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">
2990 * @extends Roo.Element
2991 * An extended {@link Roo.Element} object that supports a shadow and shim, constrain to viewport and
2992 * automatic maintaining of shadow/shim positions.
2993 * @cfg {Boolean} shim False to disable the iframe shim in browsers which need one (defaults to true)
2994 * @cfg {String/Boolean} shadow True to create a shadow element with default class "x-layer-shadow", or
2995 * you can pass a string with a CSS class name. False turns off the shadow.
2996 * @cfg {Object} dh DomHelper object config to create element with (defaults to {tag: "div", cls: "x-layer"}).
2997 * @cfg {Boolean} constrain False to disable constrain to viewport (defaults to true)
2998 * @cfg {String} cls CSS class to add to the element
2999 * @cfg {Number} zindex Starting z-index (defaults to 11000)
3000 * @cfg {Number} shadowOffset Number of pixels to offset the shadow (defaults to 3)
3002 * @param {Object} config An object with config options.
3003 * @param {String/HTMLElement} existingEl (optional) Uses an existing DOM element. If the element is not found it creates it.
3006 Roo.Layer = function(config, existingEl){
3007 config = config || {};
3008 var dh = Roo.DomHelper;
3009 var cp = config.parentEl, pel = cp ? Roo.getDom(cp) : document.body;
3011 this.dom = Roo.getDom(existingEl);
3014 var o = config.dh || {tag: "div", cls: "x-layer"};
3015 this.dom = dh.append(pel, o);
3018 this.addClass(config.cls);
3020 this.constrain = config.constrain !== false;
3021 this.visibilityMode = Roo.Element.VISIBILITY;
3023 this.id = this.dom.id = config.id;
3025 this.id = Roo.id(this.dom);
3027 this.zindex = config.zindex || this.getZIndex();
3028 this.position("absolute", this.zindex);
3030 this.shadowOffset = config.shadowOffset || 4;
3031 this.shadow = new Roo.Shadow({
3032 offset : this.shadowOffset,
3033 mode : config.shadow
3036 this.shadowOffset = 0;
3038 this.useShim = config.shim !== false && Roo.useShims;
3039 this.useDisplay = config.useDisplay;
3043 var supr = Roo.Element.prototype;
3045 // shims are shared among layer to keep from having 100 iframes
3048 Roo.extend(Roo.Layer, Roo.Element, {
3050 getZIndex : function(){
3051 return this.zindex || parseInt(this.getStyle("z-index"), 10) || 11000;
3054 getShim : function(){
3061 var shim = shims.shift();
3063 shim = this.createShim();
3064 shim.enableDisplayMode('block');
3065 shim.dom.style.display = 'none';
3066 shim.dom.style.visibility = 'visible';
3068 var pn = this.dom.parentNode;
3069 if(shim.dom.parentNode != pn){
3070 pn.insertBefore(shim.dom, this.dom);
3072 shim.setStyle('z-index', this.getZIndex()-2);
3077 hideShim : function(){
3079 this.shim.setDisplayed(false);
3080 shims.push(this.shim);
3085 disableShadow : function(){
3087 this.shadowDisabled = true;
3089 this.lastShadowOffset = this.shadowOffset;
3090 this.shadowOffset = 0;
3094 enableShadow : function(show){
3096 this.shadowDisabled = false;
3097 this.shadowOffset = this.lastShadowOffset;
3098 delete this.lastShadowOffset;
3106 // this code can execute repeatedly in milliseconds (i.e. during a drag) so
3107 // code size was sacrificed for effeciency (e.g. no getBox/setBox, no XY calls)
3108 sync : function(doShow){
3109 var sw = this.shadow;
3110 if(!this.updating && this.isVisible() && (sw || this.useShim)){
3111 var sh = this.getShim();
3113 var w = this.getWidth(),
3114 h = this.getHeight();
3116 var l = this.getLeft(true),
3117 t = this.getTop(true);
3119 if(sw && !this.shadowDisabled){
3120 if(doShow && !sw.isVisible()){
3123 sw.realign(l, t, w, h);
3129 // fit the shim behind the shadow, so it is shimmed too
3130 var a = sw.adjusts, s = sh.dom.style;
3131 s.left = (Math.min(l, l+a.l))+"px";
3132 s.top = (Math.min(t, t+a.t))+"px";
3133 s.width = (w+a.w)+"px";
3134 s.height = (h+a.h)+"px";
3141 sh.setLeftTop(l, t);
3148 destroy : function(){
3153 this.removeAllListeners();
3154 var pn = this.dom.parentNode;
3156 pn.removeChild(this.dom);
3158 Roo.Element.uncache(this.id);
3161 remove : function(){
3166 beginUpdate : function(){
3167 this.updating = true;
3171 endUpdate : function(){
3172 this.updating = false;
3177 hideUnders : function(negOffset){
3185 constrainXY : function(){
3187 var vw = Roo.lib.Dom.getViewWidth(),
3188 vh = Roo.lib.Dom.getViewHeight();
3189 var s = Roo.get(document).getScroll();
3191 var xy = this.getXY();
3192 var x = xy[0], y = xy[1];
3193 var w = this.dom.offsetWidth+this.shadowOffset, h = this.dom.offsetHeight+this.shadowOffset;
3194 // only move it if it needs it
3196 // first validate right/bottom
3197 if((x + w) > vw+s.left){
3198 x = vw - w - this.shadowOffset;
3201 if((y + h) > vh+s.top){
3202 y = vh - h - this.shadowOffset;
3205 // then make sure top/left isn't negative
3216 var ay = this.avoidY;
3217 if(y <= ay && (y+h) >= ay){
3223 supr.setXY.call(this, xy);
3229 isVisible : function(){
3230 return this.visible;
3234 showAction : function(){
3235 this.visible = true; // track visibility to prevent getStyle calls
3236 if(this.useDisplay === true){
3237 this.setDisplayed("");
3238 }else if(this.lastXY){
3239 supr.setXY.call(this, this.lastXY);
3240 }else if(this.lastLT){
3241 supr.setLeftTop.call(this, this.lastLT[0], this.lastLT[1]);
3246 hideAction : function(){
3247 this.visible = false;
3248 if(this.useDisplay === true){
3249 this.setDisplayed(false);
3251 this.setLeftTop(-10000,-10000);
3255 // overridden Element method
3256 setVisible : function(v, a, d, c, e){
3261 var cb = function(){
3266 }.createDelegate(this);
3267 supr.setVisible.call(this, true, true, d, cb, e);
3270 this.hideUnders(true);
3279 }.createDelegate(this);
3281 supr.setVisible.call(this, v, a, d, cb, e);
3290 storeXY : function(xy){
3295 storeLeftTop : function(left, top){
3297 this.lastLT = [left, top];
3301 beforeFx : function(){
3302 this.beforeAction();
3303 return Roo.Layer.superclass.beforeFx.apply(this, arguments);
3307 afterFx : function(){
3308 Roo.Layer.superclass.afterFx.apply(this, arguments);
3309 this.sync(this.isVisible());
3313 beforeAction : function(){
3314 if(!this.updating && this.shadow){
3319 // overridden Element method
3320 setLeft : function(left){
3321 this.storeLeftTop(left, this.getTop(true));
3322 supr.setLeft.apply(this, arguments);
3326 setTop : function(top){
3327 this.storeLeftTop(this.getLeft(true), top);
3328 supr.setTop.apply(this, arguments);
3332 setLeftTop : function(left, top){
3333 this.storeLeftTop(left, top);
3334 supr.setLeftTop.apply(this, arguments);
3338 setXY : function(xy, a, d, c, e){
3340 this.beforeAction();
3342 var cb = this.createCB(c);
3343 supr.setXY.call(this, xy, a, d, cb, e);
3350 createCB : function(c){
3361 // overridden Element method
3362 setX : function(x, a, d, c, e){
3363 this.setXY([x, this.getY()], a, d, c, e);
3366 // overridden Element method
3367 setY : function(y, a, d, c, e){
3368 this.setXY([this.getX(), y], a, d, c, e);
3371 // overridden Element method
3372 setSize : function(w, h, a, d, c, e){
3373 this.beforeAction();
3374 var cb = this.createCB(c);
3375 supr.setSize.call(this, w, h, a, d, cb, e);
3381 // overridden Element method
3382 setWidth : function(w, a, d, c, e){
3383 this.beforeAction();
3384 var cb = this.createCB(c);
3385 supr.setWidth.call(this, w, a, d, cb, e);
3391 // overridden Element method
3392 setHeight : function(h, a, d, c, e){
3393 this.beforeAction();
3394 var cb = this.createCB(c);
3395 supr.setHeight.call(this, h, a, d, cb, e);
3401 // overridden Element method
3402 setBounds : function(x, y, w, h, a, d, c, e){
3403 this.beforeAction();
3404 var cb = this.createCB(c);
3406 this.storeXY([x, y]);
3407 supr.setXY.call(this, [x, y]);
3408 supr.setSize.call(this, w, h, a, d, cb, e);
3411 supr.setBounds.call(this, x, y, w, h, a, d, cb, e);
3417 * Sets the z-index of this layer and adjusts any shadow and shim z-indexes. The layer z-index is automatically
3418 * incremented by two more than the value passed in so that it always shows above any shadow or shim (the shadow
3419 * element, if any, will be assigned z-index + 1, and the shim element, if any, will be assigned the unmodified z-index).
3420 * @param {Number} zindex The new z-index to set
3421 * @return {this} The Layer
3423 setZIndex : function(zindex){
3424 this.zindex = zindex;
3425 this.setStyle("z-index", zindex + 2);
3427 this.shadow.setZIndex(zindex + 1);
3430 this.shim.setStyle("z-index", zindex);
3436 * Ext JS Library 1.1.1
3437 * Copyright(c) 2006-2007, Ext JS, LLC.
3439 * Originally Released Under LGPL - original licence link has changed is not relivant.
3442 * <script type="text/javascript">
3448 * Simple class that can provide a shadow effect for any element. Note that the element MUST be absolutely positioned,
3449 * and the shadow does not provide any shimming. This should be used only in simple cases -- for more advanced
3450 * functionality that can also provide the same shadow effect, see the {@link Roo.Layer} class.
3452 * Create a new Shadow
3453 * @param {Object} config The config object
3455 Roo.Shadow = function(config){
3456 Roo.apply(this, config);
3457 if(typeof this.mode != "string"){
3458 this.mode = this.defaultMode;
3460 var o = this.offset, a = {h: 0};
3461 var rad = Math.floor(this.offset/2);
3462 switch(this.mode.toLowerCase()){ // all this hideous nonsense calculates the various offsets for shadows
3468 a.l -= this.offset + rad;
3469 a.t -= this.offset + rad;
3480 a.l -= (this.offset - rad);
3481 a.t -= this.offset + rad;
3483 a.w -= (this.offset - rad)*2;
3494 a.l -= (this.offset - rad);
3495 a.t -= (this.offset - rad);
3497 a.w -= (this.offset + rad + 1);
3498 a.h -= (this.offset + rad);
3507 Roo.Shadow.prototype = {
3509 * @cfg {String} mode
3510 * The shadow display mode. Supports the following options:<br />
3511 * sides: Shadow displays on both sides and bottom only<br />
3512 * frame: Shadow displays equally on all four sides<br />
3513 * drop: Traditional bottom-right drop shadow (default)
3516 * @cfg {String} offset
3517 * The number of pixels to offset the shadow from the element (defaults to 4)
3522 defaultMode: "drop",
3525 * Displays the shadow under the target element
3526 * @param {String/HTMLElement/Element} targetEl The id or element under which the shadow should display
3528 show : function(target){
3529 target = Roo.get(target);
3531 this.el = Roo.Shadow.Pool.pull();
3532 if(this.el.dom.nextSibling != target.dom){
3533 this.el.insertBefore(target);
3536 this.el.setStyle("z-index", this.zIndex || parseInt(target.getStyle("z-index"), 10)-1);
3538 this.el.dom.style.filter="progid:DXImageTransform.Microsoft.alpha(opacity=50) progid:DXImageTransform.Microsoft.Blur(pixelradius="+(this.offset)+")";
3541 target.getLeft(true),
3542 target.getTop(true),
3546 this.el.dom.style.display = "block";
3550 * Returns true if the shadow is visible, else false
3552 isVisible : function(){
3553 return this.el ? true : false;
3557 * Direct alignment when values are already available. Show must be called at least once before
3558 * calling this method to ensure it is initialized.
3559 * @param {Number} left The target element left position
3560 * @param {Number} top The target element top position
3561 * @param {Number} width The target element width
3562 * @param {Number} height The target element height
3564 realign : function(l, t, w, h){
3568 var a = this.adjusts, d = this.el.dom, s = d.style;
3570 s.left = (l+a.l)+"px";
3571 s.top = (t+a.t)+"px";
3572 var sw = (w+a.w), sh = (h+a.h), sws = sw +"px", shs = sh + "px";
3574 if(s.width != sws || s.height != shs){
3578 var cn = d.childNodes;
3579 var sww = Math.max(0, (sw-12))+"px";
3580 cn[0].childNodes[1].style.width = sww;
3581 cn[1].childNodes[1].style.width = sww;
3582 cn[2].childNodes[1].style.width = sww;
3583 cn[1].style.height = Math.max(0, (sh-12))+"px";
3593 this.el.dom.style.display = "none";
3594 Roo.Shadow.Pool.push(this.el);
3600 * Adjust the z-index of this shadow
3601 * @param {Number} zindex The new z-index
3603 setZIndex : function(z){
3606 this.el.setStyle("z-index", z);
3611 // Private utility class that manages the internal Shadow cache
3612 Roo.Shadow.Pool = function(){
3614 var markup = Roo.isIE ?
3615 '<div class="x-ie-shadow"></div>' :
3616 '<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>';
3621 sh = Roo.get(Roo.DomHelper.insertHtml("beforeBegin", document.body.firstChild, markup));
3622 sh.autoBoxAdjust = false;
3627 push : function(sh){
3633 * Ext JS Library 1.1.1
3634 * Copyright(c) 2006-2007, Ext JS, LLC.
3636 * Originally Released Under LGPL - original licence link has changed is not relivant.
3639 * <script type="text/javascript">
3644 * @class Roo.SplitBar
3645 * @extends Roo.util.Observable
3646 * Creates draggable splitter bar functionality from two elements (element to be dragged and element to be resized).
3650 var split = new Roo.SplitBar("elementToDrag", "elementToSize",
3651 Roo.SplitBar.HORIZONTAL, Roo.SplitBar.LEFT);
3652 split.setAdapter(new Roo.SplitBar.AbsoluteLayoutAdapter("container"));
3653 split.minSize = 100;
3654 split.maxSize = 600;
3655 split.animate = true;
3656 split.on('moved', splitterMoved);
3659 * Create a new SplitBar
3660 * @param {String/HTMLElement/Roo.Element} dragElement The element to be dragged and act as the SplitBar.
3661 * @param {String/HTMLElement/Roo.Element} resizingElement The element to be resized based on where the SplitBar element is dragged
3662 * @param {Number} orientation (optional) Either Roo.SplitBar.HORIZONTAL or Roo.SplitBar.VERTICAL. (Defaults to HORIZONTAL)
3663 * @param {Number} placement (optional) Either Roo.SplitBar.LEFT or Roo.SplitBar.RIGHT for horizontal or
3664 Roo.SplitBar.TOP or Roo.SplitBar.BOTTOM for vertical. (By default, this is determined automatically by the initial
3665 position of the SplitBar).
3667 Roo.SplitBar = function(dragElement, resizingElement, orientation, placement, existingProxy){
3670 this.el = Roo.get(dragElement, true);
3671 this.el.dom.unselectable = "on";
3673 this.resizingEl = Roo.get(resizingElement, true);
3677 * The orientation of the split. Either Roo.SplitBar.HORIZONTAL or Roo.SplitBar.VERTICAL. (Defaults to HORIZONTAL)
3678 * Note: If this is changed after creating the SplitBar, the placement property must be manually updated
3681 this.orientation = orientation || Roo.SplitBar.HORIZONTAL;
3684 * The minimum size of the resizing element. (Defaults to 0)
3690 * The maximum size of the resizing element. (Defaults to 2000)
3693 this.maxSize = 2000;
3696 * Whether to animate the transition to the new size
3699 this.animate = false;
3702 * Whether to create a transparent shim that overlays the page when dragging, enables dragging across iframes.
3705 this.useShim = false;
3712 this.proxy = Roo.SplitBar.createProxy(this.orientation);
3714 this.proxy = Roo.get(existingProxy).dom;
3717 this.dd = new Roo.dd.DDProxy(this.el.dom.id, "XSplitBars", {dragElId : this.proxy.id});
3720 this.dd.b4StartDrag = this.onStartProxyDrag.createDelegate(this);
3723 this.dd.endDrag = this.onEndProxyDrag.createDelegate(this);
3726 this.dragSpecs = {};
3729 * @private The adapter to use to positon and resize elements
3731 this.adapter = new Roo.SplitBar.BasicLayoutAdapter();
3732 this.adapter.init(this);
3734 if(this.orientation == Roo.SplitBar.HORIZONTAL){
3736 this.placement = placement || (this.el.getX() > this.resizingEl.getX() ? Roo.SplitBar.LEFT : Roo.SplitBar.RIGHT);
3737 this.el.addClass("x-splitbar-h");
3740 this.placement = placement || (this.el.getY() > this.resizingEl.getY() ? Roo.SplitBar.TOP : Roo.SplitBar.BOTTOM);
3741 this.el.addClass("x-splitbar-v");
3747 * Fires when the splitter is moved (alias for {@link #event-moved})
3748 * @param {Roo.SplitBar} this
3749 * @param {Number} newSize the new width or height
3754 * Fires when the splitter is moved
3755 * @param {Roo.SplitBar} this
3756 * @param {Number} newSize the new width or height
3760 * @event beforeresize
3761 * Fires before the splitter is dragged
3762 * @param {Roo.SplitBar} this
3764 "beforeresize" : true,
3766 "beforeapply" : true
3769 Roo.util.Observable.call(this);
3772 Roo.extend(Roo.SplitBar, Roo.util.Observable, {
3773 onStartProxyDrag : function(x, y){
3774 this.fireEvent("beforeresize", this);
3776 var o = Roo.DomHelper.insertFirst(document.body, {cls: "x-drag-overlay", html: " "}, true);
3778 o.enableDisplayMode("block");
3779 // all splitbars share the same overlay
3780 Roo.SplitBar.prototype.overlay = o;
3782 this.overlay.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
3783 this.overlay.show();
3784 Roo.get(this.proxy).setDisplayed("block");
3785 var size = this.adapter.getElementSize(this);
3786 this.activeMinSize = this.getMinimumSize();;
3787 this.activeMaxSize = this.getMaximumSize();;
3788 var c1 = size - this.activeMinSize;
3789 var c2 = Math.max(this.activeMaxSize - size, 0);
3790 if(this.orientation == Roo.SplitBar.HORIZONTAL){
3791 this.dd.resetConstraints();
3792 this.dd.setXConstraint(
3793 this.placement == Roo.SplitBar.LEFT ? c1 : c2,
3794 this.placement == Roo.SplitBar.LEFT ? c2 : c1
3796 this.dd.setYConstraint(0, 0);
3798 this.dd.resetConstraints();
3799 this.dd.setXConstraint(0, 0);
3800 this.dd.setYConstraint(
3801 this.placement == Roo.SplitBar.TOP ? c1 : c2,
3802 this.placement == Roo.SplitBar.TOP ? c2 : c1
3805 this.dragSpecs.startSize = size;
3806 this.dragSpecs.startPoint = [x, y];
3807 Roo.dd.DDProxy.prototype.b4StartDrag.call(this.dd, x, y);
3811 * @private Called after the drag operation by the DDProxy
3813 onEndProxyDrag : function(e){
3814 Roo.get(this.proxy).setDisplayed(false);
3815 var endPoint = Roo.lib.Event.getXY(e);
3817 this.overlay.hide();
3820 if(this.orientation == Roo.SplitBar.HORIZONTAL){
3821 newSize = this.dragSpecs.startSize +
3822 (this.placement == Roo.SplitBar.LEFT ?
3823 endPoint[0] - this.dragSpecs.startPoint[0] :
3824 this.dragSpecs.startPoint[0] - endPoint[0]
3827 newSize = this.dragSpecs.startSize +
3828 (this.placement == Roo.SplitBar.TOP ?
3829 endPoint[1] - this.dragSpecs.startPoint[1] :
3830 this.dragSpecs.startPoint[1] - endPoint[1]
3833 newSize = Math.min(Math.max(newSize, this.activeMinSize), this.activeMaxSize);
3834 if(newSize != this.dragSpecs.startSize){
3835 if(this.fireEvent('beforeapply', this, newSize) !== false){
3836 this.adapter.setElementSize(this, newSize);
3837 this.fireEvent("moved", this, newSize);
3838 this.fireEvent("resize", this, newSize);
3844 * Get the adapter this SplitBar uses
3845 * @return The adapter object
3847 getAdapter : function(){
3848 return this.adapter;
3852 * Set the adapter this SplitBar uses
3853 * @param {Object} adapter A SplitBar adapter object
3855 setAdapter : function(adapter){
3856 this.adapter = adapter;
3857 this.adapter.init(this);
3861 * Gets the minimum size for the resizing element
3862 * @return {Number} The minimum size
3864 getMinimumSize : function(){
3865 return this.minSize;
3869 * Sets the minimum size for the resizing element
3870 * @param {Number} minSize The minimum size
3872 setMinimumSize : function(minSize){
3873 this.minSize = minSize;
3877 * Gets the maximum size for the resizing element
3878 * @return {Number} The maximum size
3880 getMaximumSize : function(){
3881 return this.maxSize;
3885 * Sets the maximum size for the resizing element
3886 * @param {Number} maxSize The maximum size
3888 setMaximumSize : function(maxSize){
3889 this.maxSize = maxSize;
3893 * Sets the initialize size for the resizing element
3894 * @param {Number} size The initial size
3896 setCurrentSize : function(size){
3897 var oldAnimate = this.animate;
3898 this.animate = false;
3899 this.adapter.setElementSize(this, size);
3900 this.animate = oldAnimate;
3904 * Destroy this splitbar.
3905 * @param {Boolean} removeEl True to remove the element
3907 destroy : function(removeEl){
3912 this.proxy.parentNode.removeChild(this.proxy);
3920 * @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.
3922 Roo.SplitBar.createProxy = function(dir){
3923 var proxy = new Roo.Element(document.createElement("div"));
3924 proxy.unselectable();
3925 var cls = 'x-splitbar-proxy';
3926 proxy.addClass(cls + ' ' + (dir == Roo.SplitBar.HORIZONTAL ? cls +'-h' : cls + '-v'));
3927 document.body.appendChild(proxy.dom);
3932 * @class Roo.SplitBar.BasicLayoutAdapter
3933 * Default Adapter. It assumes the splitter and resizing element are not positioned
3934 * elements and only gets/sets the width of the element. Generally used for table based layouts.
3936 Roo.SplitBar.BasicLayoutAdapter = function(){
3939 Roo.SplitBar.BasicLayoutAdapter.prototype = {
3940 // do nothing for now
3945 * Called before drag operations to get the current size of the resizing element.
3946 * @param {Roo.SplitBar} s The SplitBar using this adapter
3948 getElementSize : function(s){
3949 if(s.orientation == Roo.SplitBar.HORIZONTAL){
3950 return s.resizingEl.getWidth();
3952 return s.resizingEl.getHeight();
3957 * Called after drag operations to set the size of the resizing element.
3958 * @param {Roo.SplitBar} s The SplitBar using this adapter
3959 * @param {Number} newSize The new size to set
3960 * @param {Function} onComplete A function to be invoked when resizing is complete
3962 setElementSize : function(s, newSize, onComplete){
3963 if(s.orientation == Roo.SplitBar.HORIZONTAL){
3965 s.resizingEl.setWidth(newSize);
3967 onComplete(s, newSize);
3970 s.resizingEl.setWidth(newSize, true, .1, onComplete, 'easeOut');
3975 s.resizingEl.setHeight(newSize);
3977 onComplete(s, newSize);
3980 s.resizingEl.setHeight(newSize, true, .1, onComplete, 'easeOut');
3987 *@class Roo.SplitBar.AbsoluteLayoutAdapter
3988 * @extends Roo.SplitBar.BasicLayoutAdapter
3989 * Adapter that moves the splitter element to align with the resized sizing element.
3990 * Used with an absolute positioned SplitBar.
3991 * @param {String/HTMLElement/Roo.Element} container The container that wraps around the absolute positioned content. If it's
3992 * document.body, make sure you assign an id to the body element.
3994 Roo.SplitBar.AbsoluteLayoutAdapter = function(container){
3995 this.basic = new Roo.SplitBar.BasicLayoutAdapter();
3996 this.container = Roo.get(container);
3999 Roo.SplitBar.AbsoluteLayoutAdapter.prototype = {
4004 getElementSize : function(s){
4005 return this.basic.getElementSize(s);
4008 setElementSize : function(s, newSize, onComplete){
4009 this.basic.setElementSize(s, newSize, this.moveSplitter.createDelegate(this, [s]));
4012 moveSplitter : function(s){
4013 var yes = Roo.SplitBar;
4014 switch(s.placement){
4016 s.el.setX(s.resizingEl.getRight());
4019 s.el.setStyle("right", (this.container.getWidth() - s.resizingEl.getLeft()) + "px");
4022 s.el.setY(s.resizingEl.getBottom());
4025 s.el.setY(s.resizingEl.getTop() - s.el.getHeight());
4032 * Orientation constant - Create a vertical SplitBar
4036 Roo.SplitBar.VERTICAL = 1;
4039 * Orientation constant - Create a horizontal SplitBar
4043 Roo.SplitBar.HORIZONTAL = 2;
4046 * Placement constant - The resizing element is to the left of the splitter element
4050 Roo.SplitBar.LEFT = 1;
4053 * Placement constant - The resizing element is to the right of the splitter element
4057 Roo.SplitBar.RIGHT = 2;
4060 * Placement constant - The resizing element is positioned above the splitter element
4064 Roo.SplitBar.TOP = 3;
4067 * Placement constant - The resizing element is positioned under splitter element
4071 Roo.SplitBar.BOTTOM = 4;
4074 * Ext JS Library 1.1.1
4075 * Copyright(c) 2006-2007, Ext JS, LLC.
4077 * Originally Released Under LGPL - original licence link has changed is not relivant.
4080 * <script type="text/javascript">
4085 * @extends Roo.util.Observable
4086 * Create a "View" for an element based on a data model or UpdateManager and the supplied DomHelper template.
4087 * This class also supports single and multi selection modes. <br>
4088 * Create a data model bound view:
4090 var store = new Roo.data.Store(...);
4092 var view = new Roo.View({
4094 tpl : '<div id="{0}">{2} - {1}</div>', // auto create template
4097 selectedClass: "ydataview-selected",
4101 // listen for node click?
4102 view.on("click", function(vw, index, node, e){
4103 alert('Node "' + node.id + '" at index: ' + index + " was clicked.");
4107 dataModel.load("foobar.xml");
4109 For an example of creating a JSON/UpdateManager view, see {@link Roo.JsonView}.
4111 * <b>Note: The root of your template must be a single node. Table/row implementations may work but are not supported due to
4112 * IE"s limited insertion support with tables and Opera"s faulty event bubbling.</b>
4114 * Note: old style constructor is still suported (container, template, config)
4118 * @param {Object} config The config object
4121 Roo.View = function(config, depreciated_tpl, depreciated_config){
4123 this.parent = false;
4125 if (typeof(depreciated_tpl) == 'undefined') {
4126 // new way.. - universal constructor.
4127 Roo.apply(this, config);
4128 this.el = Roo.get(this.el);
4131 this.el = Roo.get(config);
4132 this.tpl = depreciated_tpl;
4133 Roo.apply(this, depreciated_config);
4135 this.wrapEl = this.el.wrap().wrap();
4136 ///this.el = this.wrapEla.appendChild(document.createElement("div"));
4139 if(typeof(this.tpl) == "string"){
4140 this.tpl = new Roo.Template(this.tpl);
4142 // support xtype ctors..
4143 this.tpl = new Roo.factory(this.tpl, Roo);
4152 * @event beforeclick
4153 * Fires before a click is processed. Returns false to cancel the default action.
4154 * @param {Roo.View} this
4155 * @param {Number} index The index of the target node
4156 * @param {HTMLElement} node The target node
4157 * @param {Roo.EventObject} e The raw event object
4159 "beforeclick" : true,
4162 * Fires when a template node is clicked.
4163 * @param {Roo.View} this
4164 * @param {Number} index The index of the target node
4165 * @param {HTMLElement} node The target node
4166 * @param {Roo.EventObject} e The raw event object
4171 * Fires when a template node is double clicked.
4172 * @param {Roo.View} this
4173 * @param {Number} index The index of the target node
4174 * @param {HTMLElement} node The target node
4175 * @param {Roo.EventObject} e The raw event object
4179 * @event contextmenu
4180 * Fires when a template node is right clicked.
4181 * @param {Roo.View} this
4182 * @param {Number} index The index of the target node
4183 * @param {HTMLElement} node The target node
4184 * @param {Roo.EventObject} e The raw event object
4186 "contextmenu" : true,
4188 * @event selectionchange
4189 * Fires when the selected nodes change.
4190 * @param {Roo.View} this
4191 * @param {Array} selections Array of the selected nodes
4193 "selectionchange" : true,
4196 * @event beforeselect
4197 * Fires before a selection is made. If any handlers return false, the selection is cancelled.
4198 * @param {Roo.View} this
4199 * @param {HTMLElement} node The node to be selected
4200 * @param {Array} selections Array of currently selected nodes
4202 "beforeselect" : true,
4204 * @event preparedata
4205 * Fires on every row to render, to allow you to change the data.
4206 * @param {Roo.View} this
4207 * @param {Object} data to be rendered (change this)
4209 "preparedata" : true
4217 "click": this.onClick,
4218 "dblclick": this.onDblClick,
4219 "contextmenu": this.onContextMenu,
4223 this.selections = [];
4225 this.cmp = new Roo.CompositeElementLite([]);
4227 this.store = Roo.factory(this.store, Roo.data);
4228 this.setStore(this.store, true);
4231 if ( this.footer && this.footer.xtype) {
4233 var fctr = this.wrapEl.appendChild(document.createElement("div"));
4235 this.footer.dataSource = this.store;
4236 this.footer.container = fctr;
4237 this.footer = Roo.factory(this.footer, Roo);
4238 fctr.insertFirst(this.el);
4240 // this is a bit insane - as the paging toolbar seems to detach the el..
4241 // dom.parentNode.parentNode.parentNode
4242 // they get detached?
4246 Roo.View.superclass.constructor.call(this);
4251 Roo.extend(Roo.View, Roo.util.Observable, {
4254 * @cfg {Roo.data.Store} store Data store to load data from.
4259 * @cfg {String|Roo.Element} el The container element.
4264 * @cfg {String|Roo.Template} tpl The template used by this View
4268 * @cfg {String} dataName the named area of the template to use as the data area
4269 * Works with domtemplates roo-name="name"
4273 * @cfg {String} selectedClass The css class to add to selected nodes
4275 selectedClass : "x-view-selected",
4277 * @cfg {String} emptyText The empty text to show when nothing is loaded.
4282 * @cfg {String} text to display on mask (default Loading)
4286 * @cfg {Boolean} multiSelect Allow multiple selection
4288 multiSelect : false,
4290 * @cfg {Boolean} singleSelect Allow single selection
4292 singleSelect: false,
4295 * @cfg {Boolean} toggleSelect - selecting
4297 toggleSelect : false,
4300 * @cfg {Boolean} tickable - selecting
4305 * Returns the element this view is bound to.
4306 * @return {Roo.Element}
4315 * Refreshes the view. - called by datachanged on the store. - do not call directly.
4317 refresh : function(){
4318 //Roo.log('refresh');
4321 // if we are using something like 'domtemplate', then
4322 // the what gets used is:
4323 // t.applySubtemplate(NAME, data, wrapping data..)
4324 // the outer template then get' applied with
4325 // the store 'extra data'
4326 // and the body get's added to the
4327 // roo-name="data" node?
4328 // <span class='roo-tpl-{name}'></span> ?????
4332 this.clearSelections();
4335 var records = this.store.getRange();
4336 if(records.length < 1) {
4338 // is this valid?? = should it render a template??
4340 this.el.update(this.emptyText);
4344 if (this.dataName) {
4345 this.el.update(t.apply(this.store.meta)); //????
4346 el = this.el.child('.roo-tpl-' + this.dataName);
4349 for(var i = 0, len = records.length; i < len; i++){
4350 var data = this.prepareData(records[i].data, i, records[i]);
4351 this.fireEvent("preparedata", this, data, i, records[i]);
4353 var d = Roo.apply({}, data);
4356 Roo.apply(d, {'roo-id' : Roo.id()});
4360 Roo.each(this.parent.item, function(item){
4361 if(item[_this.parent.valueField] != data[_this.parent.valueField]){
4364 Roo.apply(d, {'roo-data-checked' : 'checked'});
4368 html[html.length] = Roo.util.Format.trim(
4370 t.applySubtemplate(this.dataName, d, this.store.meta) :
4377 el.update(html.join(""));
4378 this.nodes = el.dom.childNodes;
4379 this.updateIndexes(0);
4384 * Function to override to reformat the data that is sent to
4385 * the template for each node.
4386 * DEPRICATED - use the preparedata event handler.
4387 * @param {Array/Object} data The raw data (array of colData for a data model bound view or
4388 * a JSON object for an UpdateManager bound view).
4390 prepareData : function(data, index, record)
4392 this.fireEvent("preparedata", this, data, index, record);
4396 onUpdate : function(ds, record){
4397 // Roo.log('on update');
4398 this.clearSelections();
4399 var index = this.store.indexOf(record);
4400 var n = this.nodes[index];
4401 this.tpl.insertBefore(n, this.prepareData(record.data, index, record));
4402 n.parentNode.removeChild(n);
4403 this.updateIndexes(index, index);
4409 onAdd : function(ds, records, index)
4411 //Roo.log(['on Add', ds, records, index] );
4412 this.clearSelections();
4413 if(this.nodes.length == 0){
4417 var n = this.nodes[index];
4418 for(var i = 0, len = records.length; i < len; i++){
4419 var d = this.prepareData(records[i].data, i, records[i]);
4421 this.tpl.insertBefore(n, d);
4424 this.tpl.append(this.el, d);
4427 this.updateIndexes(index);
4430 onRemove : function(ds, record, index){
4431 // Roo.log('onRemove');
4432 this.clearSelections();
4433 var el = this.dataName ?
4434 this.el.child('.roo-tpl-' + this.dataName) :
4437 el.dom.removeChild(this.nodes[index]);
4438 this.updateIndexes(index);
4442 * Refresh an individual node.
4443 * @param {Number} index
4445 refreshNode : function(index){
4446 this.onUpdate(this.store, this.store.getAt(index));
4449 updateIndexes : function(startIndex, endIndex){
4450 var ns = this.nodes;
4451 startIndex = startIndex || 0;
4452 endIndex = endIndex || ns.length - 1;
4453 for(var i = startIndex; i <= endIndex; i++){
4454 ns[i].nodeIndex = i;
4459 * Changes the data store this view uses and refresh the view.
4460 * @param {Store} store
4462 setStore : function(store, initial){
4463 if(!initial && this.store){
4464 this.store.un("datachanged", this.refresh);
4465 this.store.un("add", this.onAdd);
4466 this.store.un("remove", this.onRemove);
4467 this.store.un("update", this.onUpdate);
4468 this.store.un("clear", this.refresh);
4469 this.store.un("beforeload", this.onBeforeLoad);
4470 this.store.un("load", this.onLoad);
4471 this.store.un("loadexception", this.onLoad);
4475 store.on("datachanged", this.refresh, this);
4476 store.on("add", this.onAdd, this);
4477 store.on("remove", this.onRemove, this);
4478 store.on("update", this.onUpdate, this);
4479 store.on("clear", this.refresh, this);
4480 store.on("beforeload", this.onBeforeLoad, this);
4481 store.on("load", this.onLoad, this);
4482 store.on("loadexception", this.onLoad, this);
4490 * onbeforeLoad - masks the loading area.
4493 onBeforeLoad : function(store,opts)
4495 //Roo.log('onBeforeLoad');
4499 this.el.mask(this.mask ? this.mask : "Loading" );
4501 onLoad : function ()
4508 * Returns the template node the passed child belongs to or null if it doesn't belong to one.
4509 * @param {HTMLElement} node
4510 * @return {HTMLElement} The template node
4512 findItemFromChild : function(node){
4513 var el = this.dataName ?
4514 this.el.child('.roo-tpl-' + this.dataName,true) :
4517 if(!node || node.parentNode == el){
4520 var p = node.parentNode;
4521 while(p && p != el){
4522 if(p.parentNode == el){
4531 onClick : function(e){
4532 var item = this.findItemFromChild(e.getTarget());
4534 var index = this.indexOf(item);
4535 if(this.onItemClick(item, index, e) !== false){
4536 this.fireEvent("click", this, index, item, e);
4539 this.clearSelections();
4544 onContextMenu : function(e){
4545 var item = this.findItemFromChild(e.getTarget());
4547 this.fireEvent("contextmenu", this, this.indexOf(item), item, e);
4552 onDblClick : function(e){
4553 var item = this.findItemFromChild(e.getTarget());
4555 this.fireEvent("dblclick", this, this.indexOf(item), item, e);
4559 onItemClick : function(item, index, e)
4561 if(this.fireEvent("beforeclick", this, index, item, e) === false){
4564 if (this.toggleSelect) {
4565 var m = this.isSelected(item) ? 'unselect' : 'select';
4568 _t[m](item, true, false);
4571 if(this.multiSelect || this.singleSelect){
4572 if(this.multiSelect && e.shiftKey && this.lastSelection){
4573 this.select(this.getNodes(this.indexOf(this.lastSelection), index), false);
4575 this.select(item, this.multiSelect && e.ctrlKey);
4576 this.lastSelection = item;
4588 * Get the number of selected nodes.
4591 getSelectionCount : function(){
4592 return this.selections.length;
4596 * Get the currently selected nodes.
4597 * @return {Array} An array of HTMLElements
4599 getSelectedNodes : function(){
4600 return this.selections;
4604 * Get the indexes of the selected nodes.
4607 getSelectedIndexes : function(){
4608 var indexes = [], s = this.selections;
4609 for(var i = 0, len = s.length; i < len; i++){
4610 indexes.push(s[i].nodeIndex);
4616 * Clear all selections
4617 * @param {Boolean} suppressEvent (optional) true to skip firing of the selectionchange event
4619 clearSelections : function(suppressEvent){
4620 if(this.nodes && (this.multiSelect || this.singleSelect) && this.selections.length > 0){
4621 this.cmp.elements = this.selections;
4622 this.cmp.removeClass(this.selectedClass);
4623 this.selections = [];
4625 this.fireEvent("selectionchange", this, this.selections);
4631 * Returns true if the passed node is selected
4632 * @param {HTMLElement/Number} node The node or node index
4635 isSelected : function(node){
4636 var s = this.selections;
4640 node = this.getNode(node);
4641 return s.indexOf(node) !== -1;
4646 * @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
4647 * @param {Boolean} keepExisting (optional) true to keep existing selections
4648 * @param {Boolean} suppressEvent (optional) true to skip firing of the selectionchange vent
4650 select : function(nodeInfo, keepExisting, suppressEvent){
4651 if(nodeInfo instanceof Array){
4653 this.clearSelections(true);
4655 for(var i = 0, len = nodeInfo.length; i < len; i++){
4656 this.select(nodeInfo[i], true, true);
4660 var node = this.getNode(nodeInfo);
4661 if(!node || this.isSelected(node)){
4662 return; // already selected.
4665 this.clearSelections(true);
4668 if(this.fireEvent("beforeselect", this, node, this.selections) !== false){
4669 Roo.fly(node).addClass(this.selectedClass);
4670 this.selections.push(node);
4672 this.fireEvent("selectionchange", this, this.selections);
4680 * @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
4681 * @param {Boolean} keepExisting (optional) true IGNORED (for campatibility with select)
4682 * @param {Boolean} suppressEvent (optional) true to skip firing of the selectionchange vent
4684 unselect : function(nodeInfo, keepExisting, suppressEvent)
4686 if(nodeInfo instanceof Array){
4687 Roo.each(this.selections, function(s) {
4688 this.unselect(s, nodeInfo);
4692 var node = this.getNode(nodeInfo);
4693 if(!node || !this.isSelected(node)){
4694 //Roo.log("not selected");
4695 return; // not selected.
4699 Roo.each(this.selections, function(s) {
4701 Roo.fly(node).removeClass(this.selectedClass);
4708 this.selections= ns;
4709 this.fireEvent("selectionchange", this, this.selections);
4713 * Gets a template node.
4714 * @param {HTMLElement/String/Number} nodeInfo An HTMLElement template node, index of a template node or the id of a template node
4715 * @return {HTMLElement} The node or null if it wasn't found
4717 getNode : function(nodeInfo){
4718 if(typeof nodeInfo == "string"){
4719 return document.getElementById(nodeInfo);
4720 }else if(typeof nodeInfo == "number"){
4721 return this.nodes[nodeInfo];
4727 * Gets a range template nodes.
4728 * @param {Number} startIndex
4729 * @param {Number} endIndex
4730 * @return {Array} An array of nodes
4732 getNodes : function(start, end){
4733 var ns = this.nodes;
4735 end = typeof end == "undefined" ? ns.length - 1 : end;
4738 for(var i = start; i <= end; i++){
4742 for(var i = start; i >= end; i--){
4750 * Finds the index of the passed node
4751 * @param {HTMLElement/String/Number} nodeInfo An HTMLElement template node, index of a template node or the id of a template node
4752 * @return {Number} The index of the node or -1
4754 indexOf : function(node){
4755 node = this.getNode(node);
4756 if(typeof node.nodeIndex == "number"){
4757 return node.nodeIndex;
4759 var ns = this.nodes;
4760 for(var i = 0, len = ns.length; i < len; i++){
4770 * Ext JS Library 1.1.1
4771 * Copyright(c) 2006-2007, Ext JS, LLC.
4773 * Originally Released Under LGPL - original licence link has changed is not relivant.
4776 * <script type="text/javascript">
4780 * @class Roo.JsonView
4782 * Shortcut class to create a JSON + {@link Roo.UpdateManager} template view. Usage:
4784 var view = new Roo.JsonView({
4785 container: "my-element",
4786 tpl: '<div id="{id}">{foo} - {bar}</div>', // auto create template
4791 // listen for node click?
4792 view.on("click", function(vw, index, node, e){
4793 alert('Node "' + node.id + '" at index: ' + index + " was clicked.");
4796 // direct load of JSON data
4797 view.load("foobar.php");
4799 // Example from my blog list
4800 var tpl = new Roo.Template(
4801 '<div class="entry">' +
4802 '<a class="entry-title" href="{link}">{title}</a>' +
4803 "<h4>{date} by {author} | {comments} Comments</h4>{description}" +
4804 "</div><hr />"
4807 var moreView = new Roo.JsonView({
4808 container : "entry-list",
4812 moreView.on("beforerender", this.sortEntries, this);
4814 url: "/blog/get-posts.php",
4815 params: "allposts=true",
4816 text: "Loading Blog Entries..."
4820 * Note: old code is supported with arguments : (container, template, config)
4824 * Create a new JsonView
4826 * @param {Object} config The config object
4829 Roo.JsonView = function(config, depreciated_tpl, depreciated_config){
4832 Roo.JsonView.superclass.constructor.call(this, config, depreciated_tpl, depreciated_config);
4834 var um = this.el.getUpdateManager();
4835 um.setRenderer(this);
4836 um.on("update", this.onLoad, this);
4837 um.on("failure", this.onLoadException, this);
4840 * @event beforerender
4841 * Fires before rendering of the downloaded JSON data.
4842 * @param {Roo.JsonView} this
4843 * @param {Object} data The JSON data loaded
4847 * Fires when data is loaded.
4848 * @param {Roo.JsonView} this
4849 * @param {Object} data The JSON data loaded
4850 * @param {Object} response The raw Connect response object
4853 * @event loadexception
4854 * Fires when loading fails.
4855 * @param {Roo.JsonView} this
4856 * @param {Object} response The raw Connect response object
4859 'beforerender' : true,
4861 'loadexception' : true
4864 Roo.extend(Roo.JsonView, Roo.View, {
4866 * @type {String} The root property in the loaded JSON object that contains the data
4871 * Refreshes the view.
4873 refresh : function(){
4874 this.clearSelections();
4877 var o = this.jsonData;
4878 if(o && o.length > 0){
4879 for(var i = 0, len = o.length; i < len; i++){
4880 var data = this.prepareData(o[i], i, o);
4881 html[html.length] = this.tpl.apply(data);
4884 html.push(this.emptyText);
4886 this.el.update(html.join(""));
4887 this.nodes = this.el.dom.childNodes;
4888 this.updateIndexes(0);
4892 * 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.
4893 * @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:
4896 url: "your-url.php",
4897 params: {param1: "foo", param2: "bar"}, // or a URL encoded string
4898 callback: yourFunction,
4899 scope: yourObject, //(optional scope)
4907 * The only required property is <i>url</i>. The optional properties <i>nocache</i>, <i>text</i> and <i>scripts</i>
4908 * 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.
4909 * @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}
4910 * @param {Function} callback (optional) Callback when transaction is complete - called with signature (oElement, bSuccess)
4911 * @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.
4914 var um = this.el.getUpdateManager();
4915 um.update.apply(um, arguments);
4918 // note - render is a standard framework call...
4919 // using it for the response is really flaky... - it's called by UpdateManager normally, except when called by the XComponent/addXtype.
4920 render : function(el, response){
4922 this.clearSelections();
4926 if (response != '') {
4927 o = Roo.util.JSON.decode(response.responseText);
4930 o = o[this.jsonRoot];
4936 * The current JSON data or null
4939 this.beforeRender();
4944 * Get the number of records in the current JSON dataset
4947 getCount : function(){
4948 return this.jsonData ? this.jsonData.length : 0;
4952 * Returns the JSON object for the specified node(s)
4953 * @param {HTMLElement/Array} node The node or an array of nodes
4954 * @return {Object/Array} If you pass in an array, you get an array back, otherwise
4955 * you get the JSON object for the node
4957 getNodeData : function(node){
4958 if(node instanceof Array){
4960 for(var i = 0, len = node.length; i < len; i++){
4961 data.push(this.getNodeData(node[i]));
4965 return this.jsonData[this.indexOf(node)] || null;
4968 beforeRender : function(){
4969 this.snapshot = this.jsonData;
4971 this.sort.apply(this, this.sortInfo);
4973 this.fireEvent("beforerender", this, this.jsonData);
4976 onLoad : function(el, o){
4977 this.fireEvent("load", this, this.jsonData, o);
4980 onLoadException : function(el, o){
4981 this.fireEvent("loadexception", this, o);
4985 * Filter the data by a specific property.
4986 * @param {String} property A property on your JSON objects
4987 * @param {String/RegExp} value Either string that the property values
4988 * should start with, or a RegExp to test against the property
4990 filter : function(property, value){
4993 var ss = this.snapshot;
4994 if(typeof value == "string"){
4995 var vlen = value.length;
5000 value = value.toLowerCase();
5001 for(var i = 0, len = ss.length; i < len; i++){
5003 if(o[property].substr(0, vlen).toLowerCase() == value){
5007 } else if(value.exec){ // regex?
5008 for(var i = 0, len = ss.length; i < len; i++){
5010 if(value.test(o[property])){
5017 this.jsonData = data;
5023 * Filter by a function. The passed function will be called with each
5024 * object in the current dataset. If the function returns true the value is kept,
5025 * otherwise it is filtered.
5026 * @param {Function} fn
5027 * @param {Object} scope (optional) The scope of the function (defaults to this JsonView)
5029 filterBy : function(fn, scope){
5032 var ss = this.snapshot;
5033 for(var i = 0, len = ss.length; i < len; i++){
5035 if(fn.call(scope || this, o)){
5039 this.jsonData = data;
5045 * Clears the current filter.
5047 clearFilter : function(){
5048 if(this.snapshot && this.jsonData != this.snapshot){
5049 this.jsonData = this.snapshot;
5056 * Sorts the data for this view and refreshes it.
5057 * @param {String} property A property on your JSON objects to sort on
5058 * @param {String} direction (optional) "desc" or "asc" (defaults to "asc")
5059 * @param {Function} sortType (optional) A function to call to convert the data to a sortable value.
5061 sort : function(property, dir, sortType){
5062 this.sortInfo = Array.prototype.slice.call(arguments, 0);
5065 var dsc = dir && dir.toLowerCase() == "desc";
5066 var f = function(o1, o2){
5067 var v1 = sortType ? sortType(o1[p]) : o1[p];
5068 var v2 = sortType ? sortType(o2[p]) : o2[p];
5071 return dsc ? +1 : -1;
5073 return dsc ? -1 : +1;
5078 this.jsonData.sort(f);
5080 if(this.jsonData != this.snapshot){
5081 this.snapshot.sort(f);
5087 * Ext JS Library 1.1.1
5088 * Copyright(c) 2006-2007, Ext JS, LLC.
5090 * Originally Released Under LGPL - original licence link has changed is not relivant.
5093 * <script type="text/javascript">
5098 * @class Roo.ColorPalette
5099 * @extends Roo.Component
5100 * Simple color palette class for choosing colors. The palette can be rendered to any container.<br />
5101 * Here's an example of typical usage:
5103 var cp = new Roo.ColorPalette({value:'993300'}); // initial selected color
5104 cp.render('my-div');
5106 cp.on('select', function(palette, selColor){
5107 // do something with selColor
5111 * Create a new ColorPalette
5112 * @param {Object} config The config object
5114 Roo.ColorPalette = function(config){
5115 Roo.ColorPalette.superclass.constructor.call(this, config);
5119 * Fires when a color is selected
5120 * @param {ColorPalette} this
5121 * @param {String} color The 6-digit color hex code (without the # symbol)
5127 this.on("select", this.handler, this.scope, true);
5130 Roo.extend(Roo.ColorPalette, Roo.Component, {
5132 * @cfg {String} itemCls
5133 * The CSS class to apply to the containing element (defaults to "x-color-palette")
5135 itemCls : "x-color-palette",
5137 * @cfg {String} value
5138 * The initial color to highlight (should be a valid 6-digit color hex code without the # symbol). Note that
5139 * the hex codes are case-sensitive.
5144 ctype: "Roo.ColorPalette",
5147 * @cfg {Boolean} allowReselect If set to true then reselecting a color that is already selected fires the selection event
5149 allowReselect : false,
5152 * <p>An array of 6-digit color hex code strings (without the # symbol). This array can contain any number
5153 * of colors, and each hex code should be unique. The width of the palette is controlled via CSS by adjusting
5154 * the width property of the 'x-color-palette' class (or assigning a custom class), so you can balance the number
5155 * of colors with the width setting until the box is symmetrical.</p>
5156 * <p>You can override individual colors if needed:</p>
5158 var cp = new Roo.ColorPalette();
5159 cp.colors[0] = "FF0000"; // change the first box to red
5162 Or you can provide a custom array of your own for complete control:
5164 var cp = new Roo.ColorPalette();
5165 cp.colors = ["000000", "993300", "333300"];
5170 "000000", "993300", "333300", "003300", "003366", "000080", "333399", "333333",
5171 "800000", "FF6600", "808000", "008000", "008080", "0000FF", "666699", "808080",
5172 "FF0000", "FF9900", "99CC00", "339966", "33CCCC", "3366FF", "800080", "969696",
5173 "FF00FF", "FFCC00", "FFFF00", "00FF00", "00FFFF", "00CCFF", "993366", "C0C0C0",
5174 "FF99CC", "FFCC99", "FFFF99", "CCFFCC", "CCFFFF", "99CCFF", "CC99FF", "FFFFFF"
5178 onRender : function(container, position){
5179 var t = new Roo.MasterTemplate(
5180 '<tpl><a href="#" class="color-{0}" hidefocus="on"><em><span style="background:#{0}" unselectable="on"> </span></em></a></tpl>'
5182 var c = this.colors;
5183 for(var i = 0, len = c.length; i < len; i++){
5186 var el = document.createElement("div");
5187 el.className = this.itemCls;
5189 container.dom.insertBefore(el, position);
5190 this.el = Roo.get(el);
5191 this.el.on(this.clickEvent, this.handleClick, this, {delegate: "a"});
5192 if(this.clickEvent != 'click'){
5193 this.el.on('click', Roo.emptyFn, this, {delegate: "a", preventDefault:true});
5198 afterRender : function(){
5199 Roo.ColorPalette.superclass.afterRender.call(this);
5208 handleClick : function(e, t){
5211 var c = t.className.match(/(?:^|\s)color-(.{6})(?:\s|$)/)[1];
5212 this.select(c.toUpperCase());
5217 * Selects the specified color in the palette (fires the select event)
5218 * @param {String} color A valid 6-digit color hex code (# will be stripped if included)
5220 select : function(color){
5221 color = color.replace("#", "");
5222 if(color != this.value || this.allowReselect){
5225 el.child("a.color-"+this.value).removeClass("x-color-palette-sel");
5227 el.child("a.color-"+color).addClass("x-color-palette-sel");
5229 this.fireEvent("select", this, color);
5234 * Ext JS Library 1.1.1
5235 * Copyright(c) 2006-2007, Ext JS, LLC.
5237 * Originally Released Under LGPL - original licence link has changed is not relivant.
5240 * <script type="text/javascript">
5244 * @class Roo.DatePicker
5245 * @extends Roo.Component
5246 * Simple date picker class.
5248 * Create a new DatePicker
5249 * @param {Object} config The config object
5251 Roo.DatePicker = function(config){
5252 Roo.DatePicker.superclass.constructor.call(this, config);
5254 this.value = config && config.value ?
5255 config.value.clearTime() : new Date().clearTime();
5260 * Fires when a date is selected
5261 * @param {DatePicker} this
5262 * @param {Date} date The selected date
5266 * @event monthchange
5267 * Fires when the displayed month changes
5268 * @param {DatePicker} this
5269 * @param {Date} date The selected month
5275 this.on("select", this.handler, this.scope || this);
5277 // build the disabledDatesRE
5278 if(!this.disabledDatesRE && this.disabledDates){
5279 var dd = this.disabledDates;
5281 for(var i = 0; i < dd.length; i++){
5283 if(i != dd.length-1) {
5287 this.disabledDatesRE = new RegExp(re + ")");
5291 Roo.extend(Roo.DatePicker, Roo.Component, {
5293 * @cfg {String} todayText
5294 * The text to display on the button that selects the current date (defaults to "Today")
5296 todayText : "Today",
5298 * @cfg {String} okText
5299 * The text to display on the ok button
5301 okText : " OK ", //   to give the user extra clicking room
5303 * @cfg {String} cancelText
5304 * The text to display on the cancel button
5306 cancelText : "Cancel",
5308 * @cfg {String} todayTip
5309 * The tooltip to display for the button that selects the current date (defaults to "{current date} (Spacebar)")
5311 todayTip : "{0} (Spacebar)",
5313 * @cfg {Date} minDate
5314 * Minimum allowable date (JavaScript date object, defaults to null)
5318 * @cfg {Date} maxDate
5319 * Maximum allowable date (JavaScript date object, defaults to null)
5323 * @cfg {String} minText
5324 * The error text to display if the minDate validation fails (defaults to "This date is before the minimum date")
5326 minText : "This date is before the minimum date",
5328 * @cfg {String} maxText
5329 * The error text to display if the maxDate validation fails (defaults to "This date is after the maximum date")
5331 maxText : "This date is after the maximum date",
5333 * @cfg {String} format
5334 * The default date format string which can be overriden for localization support. The format must be
5335 * valid according to {@link Date#parseDate} (defaults to 'm/d/y').
5339 * @cfg {Array} disabledDays
5340 * An array of days to disable, 0-based. For example, [0, 6] disables Sunday and Saturday (defaults to null).
5342 disabledDays : null,
5344 * @cfg {String} disabledDaysText
5345 * The tooltip to display when the date falls on a disabled day (defaults to "")
5347 disabledDaysText : "",
5349 * @cfg {RegExp} disabledDatesRE
5350 * JavaScript regular expression used to disable a pattern of dates (defaults to null)
5352 disabledDatesRE : null,
5354 * @cfg {String} disabledDatesText
5355 * The tooltip text to display when the date falls on a disabled date (defaults to "")
5357 disabledDatesText : "",
5359 * @cfg {Boolean} constrainToViewport
5360 * True to constrain the date picker to the viewport (defaults to true)
5362 constrainToViewport : true,
5364 * @cfg {Array} monthNames
5365 * An array of textual month names which can be overriden for localization support (defaults to Date.monthNames)
5367 monthNames : Date.monthNames,
5369 * @cfg {Array} dayNames
5370 * An array of textual day names which can be overriden for localization support (defaults to Date.dayNames)
5372 dayNames : Date.dayNames,
5374 * @cfg {String} nextText
5375 * The next month navigation button tooltip (defaults to 'Next Month (Control+Right)')
5377 nextText: 'Next Month (Control+Right)',
5379 * @cfg {String} prevText
5380 * The previous month navigation button tooltip (defaults to 'Previous Month (Control+Left)')
5382 prevText: 'Previous Month (Control+Left)',
5384 * @cfg {String} monthYearText
5385 * The header month selector tooltip (defaults to 'Choose a month (Control+Up/Down to move years)')
5387 monthYearText: 'Choose a month (Control+Up/Down to move years)',
5389 * @cfg {Number} startDay
5390 * Day index at which the week should begin, 0-based (defaults to 0, which is Sunday)
5394 * @cfg {Bool} showClear
5395 * Show a clear button (usefull for date form elements that can be blank.)
5401 * Sets the value of the date field
5402 * @param {Date} value The date to set
5404 setValue : function(value){
5405 var old = this.value;
5407 if (typeof(value) == 'string') {
5409 value = Date.parseDate(value, this.format);
5415 this.value = value.clearTime(true);
5417 this.update(this.value);
5422 * Gets the current selected value of the date field
5423 * @return {Date} The selected date
5425 getValue : function(){
5432 this.update(this.activeDate);
5437 onRender : function(container, position){
5440 '<table cellspacing="0">',
5441 '<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>',
5442 '<tr><td colspan="3"><table class="x-date-inner" cellspacing="0"><thead><tr>'];
5443 var dn = this.dayNames;
5444 for(var i = 0; i < 7; i++){
5445 var d = this.startDay+i;
5449 m.push("<th><span>", dn[d].substr(0,1), "</span></th>");
5451 m[m.length] = "</tr></thead><tbody><tr>";
5452 for(var i = 0; i < 42; i++) {
5453 if(i % 7 == 0 && i != 0){
5454 m[m.length] = "</tr><tr>";
5456 m[m.length] = '<td><a href="#" hidefocus="on" class="x-date-date" tabIndex="1"><em><span></span></em></a></td>';
5458 m[m.length] = '</tr></tbody></table></td></tr><tr>'+
5459 '<td colspan="3" class="x-date-bottom" align="center"></td></tr></table><div class="x-date-mp"></div>';
5461 var el = document.createElement("div");
5462 el.className = "x-date-picker";
5463 el.innerHTML = m.join("");
5465 container.dom.insertBefore(el, position);
5467 this.el = Roo.get(el);
5468 this.eventEl = Roo.get(el.firstChild);
5470 new Roo.util.ClickRepeater(this.el.child("td.x-date-left a"), {
5471 handler: this.showPrevMonth,
5473 preventDefault:true,
5477 new Roo.util.ClickRepeater(this.el.child("td.x-date-right a"), {
5478 handler: this.showNextMonth,
5480 preventDefault:true,
5484 this.eventEl.on("mousewheel", this.handleMouseWheel, this);
5486 this.monthPicker = this.el.down('div.x-date-mp');
5487 this.monthPicker.enableDisplayMode('block');
5489 var kn = new Roo.KeyNav(this.eventEl, {
5490 "left" : function(e){
5492 this.showPrevMonth() :
5493 this.update(this.activeDate.add("d", -1));
5496 "right" : function(e){
5498 this.showNextMonth() :
5499 this.update(this.activeDate.add("d", 1));
5504 this.showNextYear() :
5505 this.update(this.activeDate.add("d", -7));
5508 "down" : function(e){
5510 this.showPrevYear() :
5511 this.update(this.activeDate.add("d", 7));
5514 "pageUp" : function(e){
5515 this.showNextMonth();
5518 "pageDown" : function(e){
5519 this.showPrevMonth();
5522 "enter" : function(e){
5523 e.stopPropagation();
5530 this.eventEl.on("click", this.handleDateClick, this, {delegate: "a.x-date-date"});
5532 this.eventEl.addKeyListener(Roo.EventObject.SPACE, this.selectToday, this);
5534 this.el.unselectable();
5536 this.cells = this.el.select("table.x-date-inner tbody td");
5537 this.textNodes = this.el.query("table.x-date-inner tbody span");
5539 this.mbtn = new Roo.Button(this.el.child("td.x-date-middle", true), {
5541 tooltip: this.monthYearText
5544 this.mbtn.on('click', this.showMonthPicker, this);
5545 this.mbtn.el.child(this.mbtn.menuClassTarget).addClass("x-btn-with-menu");
5548 var today = (new Date()).dateFormat(this.format);
5550 var baseTb = new Roo.Toolbar(this.el.child("td.x-date-bottom", true));
5551 if (this.showClear) {
5552 baseTb.add( new Roo.Toolbar.Fill());
5555 text: String.format(this.todayText, today),
5556 tooltip: String.format(this.todayTip, today),
5557 handler: this.selectToday,
5561 //var todayBtn = new Roo.Button(this.el.child("td.x-date-bottom", true), {
5564 if (this.showClear) {
5566 baseTb.add( new Roo.Toolbar.Fill());
5569 cls: 'x-btn-icon x-btn-clear',
5570 handler: function() {
5572 this.fireEvent("select", this, '');
5582 this.update(this.value);
5585 createMonthPicker : function(){
5586 if(!this.monthPicker.dom.firstChild){
5587 var buf = ['<table border="0" cellspacing="0">'];
5588 for(var i = 0; i < 6; i++){
5590 '<tr><td class="x-date-mp-month"><a href="#">', this.monthNames[i].substr(0, 3), '</a></td>',
5591 '<td class="x-date-mp-month x-date-mp-sep"><a href="#">', this.monthNames[i+6].substr(0, 3), '</a></td>',
5593 '<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>' :
5594 '<td class="x-date-mp-year"><a href="#"></a></td><td class="x-date-mp-year"><a href="#"></a></td></tr>'
5598 '<tr class="x-date-mp-btns"><td colspan="4"><button type="button" class="x-date-mp-ok">',
5600 '</button><button type="button" class="x-date-mp-cancel">',
5602 '</button></td></tr>',
5605 this.monthPicker.update(buf.join(''));
5606 this.monthPicker.on('click', this.onMonthClick, this);
5607 this.monthPicker.on('dblclick', this.onMonthDblClick, this);
5609 this.mpMonths = this.monthPicker.select('td.x-date-mp-month');
5610 this.mpYears = this.monthPicker.select('td.x-date-mp-year');
5612 this.mpMonths.each(function(m, a, i){
5615 m.dom.xmonth = 5 + Math.round(i * .5);
5617 m.dom.xmonth = Math.round((i-1) * .5);
5623 showMonthPicker : function(){
5624 this.createMonthPicker();
5625 var size = this.el.getSize();
5626 this.monthPicker.setSize(size);
5627 this.monthPicker.child('table').setSize(size);
5629 this.mpSelMonth = (this.activeDate || this.value).getMonth();
5630 this.updateMPMonth(this.mpSelMonth);
5631 this.mpSelYear = (this.activeDate || this.value).getFullYear();
5632 this.updateMPYear(this.mpSelYear);
5634 this.monthPicker.slideIn('t', {duration:.2});
5637 updateMPYear : function(y){
5639 var ys = this.mpYears.elements;
5640 for(var i = 1; i <= 10; i++){
5641 var td = ys[i-1], y2;
5643 y2 = y + Math.round(i * .5);
5644 td.firstChild.innerHTML = y2;
5647 y2 = y - (5-Math.round(i * .5));
5648 td.firstChild.innerHTML = y2;
5651 this.mpYears.item(i-1)[y2 == this.mpSelYear ? 'addClass' : 'removeClass']('x-date-mp-sel');
5655 updateMPMonth : function(sm){
5656 this.mpMonths.each(function(m, a, i){
5657 m[m.dom.xmonth == sm ? 'addClass' : 'removeClass']('x-date-mp-sel');
5661 selectMPMonth: function(m){
5665 onMonthClick : function(e, t){
5667 var el = new Roo.Element(t), pn;
5668 if(el.is('button.x-date-mp-cancel')){
5669 this.hideMonthPicker();
5671 else if(el.is('button.x-date-mp-ok')){
5672 this.update(new Date(this.mpSelYear, this.mpSelMonth, (this.activeDate || this.value).getDate()));
5673 this.hideMonthPicker();
5675 else if(pn = el.up('td.x-date-mp-month', 2)){
5676 this.mpMonths.removeClass('x-date-mp-sel');
5677 pn.addClass('x-date-mp-sel');
5678 this.mpSelMonth = pn.dom.xmonth;
5680 else if(pn = el.up('td.x-date-mp-year', 2)){
5681 this.mpYears.removeClass('x-date-mp-sel');
5682 pn.addClass('x-date-mp-sel');
5683 this.mpSelYear = pn.dom.xyear;
5685 else if(el.is('a.x-date-mp-prev')){
5686 this.updateMPYear(this.mpyear-10);
5688 else if(el.is('a.x-date-mp-next')){
5689 this.updateMPYear(this.mpyear+10);
5693 onMonthDblClick : function(e, t){
5695 var el = new Roo.Element(t), pn;
5696 if(pn = el.up('td.x-date-mp-month', 2)){
5697 this.update(new Date(this.mpSelYear, pn.dom.xmonth, (this.activeDate || this.value).getDate()));
5698 this.hideMonthPicker();
5700 else if(pn = el.up('td.x-date-mp-year', 2)){
5701 this.update(new Date(pn.dom.xyear, this.mpSelMonth, (this.activeDate || this.value).getDate()));
5702 this.hideMonthPicker();
5706 hideMonthPicker : function(disableAnim){
5707 if(this.monthPicker){
5708 if(disableAnim === true){
5709 this.monthPicker.hide();
5711 this.monthPicker.slideOut('t', {duration:.2});
5717 showPrevMonth : function(e){
5718 this.update(this.activeDate.add("mo", -1));
5722 showNextMonth : function(e){
5723 this.update(this.activeDate.add("mo", 1));
5727 showPrevYear : function(){
5728 this.update(this.activeDate.add("y", -1));
5732 showNextYear : function(){
5733 this.update(this.activeDate.add("y", 1));
5737 handleMouseWheel : function(e){
5738 var delta = e.getWheelDelta();
5740 this.showPrevMonth();
5742 } else if(delta < 0){
5743 this.showNextMonth();
5749 handleDateClick : function(e, t){
5751 if(t.dateValue && !Roo.fly(t.parentNode).hasClass("x-date-disabled")){
5752 this.setValue(new Date(t.dateValue));
5753 this.fireEvent("select", this, this.value);
5758 selectToday : function(){
5759 this.setValue(new Date().clearTime());
5760 this.fireEvent("select", this, this.value);
5764 update : function(date)
5766 var vd = this.activeDate;
5767 this.activeDate = date;
5769 var t = date.getTime();
5770 if(vd.getMonth() == date.getMonth() && vd.getFullYear() == date.getFullYear()){
5771 this.cells.removeClass("x-date-selected");
5772 this.cells.each(function(c){
5773 if(c.dom.firstChild.dateValue == t){
5774 c.addClass("x-date-selected");
5775 setTimeout(function(){
5776 try{c.dom.firstChild.focus();}catch(e){}
5785 var days = date.getDaysInMonth();
5786 var firstOfMonth = date.getFirstDateOfMonth();
5787 var startingPos = firstOfMonth.getDay()-this.startDay;
5789 if(startingPos <= this.startDay){
5793 var pm = date.add("mo", -1);
5794 var prevStart = pm.getDaysInMonth()-startingPos;
5796 var cells = this.cells.elements;
5797 var textEls = this.textNodes;
5798 days += startingPos;
5800 // convert everything to numbers so it's fast
5802 var d = (new Date(pm.getFullYear(), pm.getMonth(), prevStart)).clearTime();
5803 var today = new Date().clearTime().getTime();
5804 var sel = date.clearTime().getTime();
5805 var min = this.minDate ? this.minDate.clearTime() : Number.NEGATIVE_INFINITY;
5806 var max = this.maxDate ? this.maxDate.clearTime() : Number.POSITIVE_INFINITY;
5807 var ddMatch = this.disabledDatesRE;
5808 var ddText = this.disabledDatesText;
5809 var ddays = this.disabledDays ? this.disabledDays.join("") : false;
5810 var ddaysText = this.disabledDaysText;
5811 var format = this.format;
5813 var setCellClass = function(cal, cell){
5815 var t = d.getTime();
5816 cell.firstChild.dateValue = t;
5818 cell.className += " x-date-today";
5819 cell.title = cal.todayText;
5822 cell.className += " x-date-selected";
5823 setTimeout(function(){
5824 try{cell.firstChild.focus();}catch(e){}
5829 cell.className = " x-date-disabled";
5830 cell.title = cal.minText;
5834 cell.className = " x-date-disabled";
5835 cell.title = cal.maxText;
5839 if(ddays.indexOf(d.getDay()) != -1){
5840 cell.title = ddaysText;
5841 cell.className = " x-date-disabled";
5844 if(ddMatch && format){
5845 var fvalue = d.dateFormat(format);
5846 if(ddMatch.test(fvalue)){
5847 cell.title = ddText.replace("%0", fvalue);
5848 cell.className = " x-date-disabled";
5854 for(; i < startingPos; i++) {
5855 textEls[i].innerHTML = (++prevStart);
5856 d.setDate(d.getDate()+1);
5857 cells[i].className = "x-date-prevday";
5858 setCellClass(this, cells[i]);
5860 for(; i < days; i++){
5861 intDay = i - startingPos + 1;
5862 textEls[i].innerHTML = (intDay);
5863 d.setDate(d.getDate()+1);
5864 cells[i].className = "x-date-active";
5865 setCellClass(this, cells[i]);
5868 for(; i < 42; i++) {
5869 textEls[i].innerHTML = (++extraDays);
5870 d.setDate(d.getDate()+1);
5871 cells[i].className = "x-date-nextday";
5872 setCellClass(this, cells[i]);
5875 this.mbtn.setText(this.monthNames[date.getMonth()] + " " + date.getFullYear());
5876 this.fireEvent('monthchange', this, date);
5878 if(!this.internalRender){
5879 var main = this.el.dom.firstChild;
5880 var w = main.offsetWidth;
5881 this.el.setWidth(w + this.el.getBorderWidth("lr"));
5882 Roo.fly(main).setWidth(w);
5883 this.internalRender = true;
5884 // opera does not respect the auto grow header center column
5885 // then, after it gets a width opera refuses to recalculate
5886 // without a second pass
5887 if(Roo.isOpera && !this.secondPass){
5888 main.rows[0].cells[1].style.width = (w - (main.rows[0].cells[0].offsetWidth+main.rows[0].cells[2].offsetWidth)) + "px";
5889 this.secondPass = true;
5890 this.update.defer(10, this, [date]);
5898 * Ext JS Library 1.1.1
5899 * Copyright(c) 2006-2007, Ext JS, LLC.
5901 * Originally Released Under LGPL - original licence link has changed is not relivant.
5904 * <script type="text/javascript">
5907 * @class Roo.TabPanel
5908 * @extends Roo.util.Observable
5909 * A lightweight tab container.
5913 // basic tabs 1, built from existing content
5914 var tabs = new Roo.TabPanel("tabs1");
5915 tabs.addTab("script", "View Script");
5916 tabs.addTab("markup", "View Markup");
5917 tabs.activate("script");
5919 // more advanced tabs, built from javascript
5920 var jtabs = new Roo.TabPanel("jtabs");
5921 jtabs.addTab("jtabs-1", "Normal Tab", "My content was added during construction.");
5923 // set up the UpdateManager
5924 var tab2 = jtabs.addTab("jtabs-2", "Ajax Tab 1");
5925 var updater = tab2.getUpdateManager();
5926 updater.setDefaultUrl("ajax1.htm");
5927 tab2.on('activate', updater.refresh, updater, true);
5929 // Use setUrl for Ajax loading
5930 var tab3 = jtabs.addTab("jtabs-3", "Ajax Tab 2");
5931 tab3.setUrl("ajax2.htm", null, true);
5934 var tab4 = jtabs.addTab("tabs1-5", "Disabled Tab", "Can't see me cause I'm disabled");
5937 jtabs.activate("jtabs-1");
5940 * Create a new TabPanel.
5941 * @param {String/HTMLElement/Roo.Element} container The id, DOM element or Roo.Element container where this TabPanel is to be rendered.
5942 * @param {Object/Boolean} config Config object to set any properties for this TabPanel, or true to render the tabs on the bottom.
5944 Roo.TabPanel = function(container, config){
5946 * The container element for this TabPanel.
5949 this.el = Roo.get(container, true);
5951 if(typeof config == "boolean"){
5952 this.tabPosition = config ? "bottom" : "top";
5954 Roo.apply(this, config);
5957 if(this.tabPosition == "bottom"){
5958 this.bodyEl = Roo.get(this.createBody(this.el.dom));
5959 this.el.addClass("x-tabs-bottom");
5961 this.stripWrap = Roo.get(this.createStrip(this.el.dom), true);
5962 this.stripEl = Roo.get(this.createStripList(this.stripWrap.dom), true);
5963 this.stripBody = Roo.get(this.stripWrap.dom.firstChild.firstChild, true);
5965 Roo.fly(this.stripWrap.dom.firstChild).setStyle("overflow-x", "hidden");
5967 if(this.tabPosition != "bottom"){
5968 /** The body element that contains {@link Roo.TabPanelItem} bodies. +
5971 this.bodyEl = Roo.get(this.createBody(this.el.dom));
5972 this.el.addClass("x-tabs-top");
5976 this.bodyEl.setStyle("position", "relative");
5979 this.activateDelegate = this.activate.createDelegate(this);
5984 * Fires when the active tab changes
5985 * @param {Roo.TabPanel} this
5986 * @param {Roo.TabPanelItem} activePanel The new active tab
5990 * @event beforetabchange
5991 * Fires before the active tab changes, set cancel to true on the "e" parameter to cancel the change
5992 * @param {Roo.TabPanel} this
5993 * @param {Object} e Set cancel to true on this object to cancel the tab change
5994 * @param {Roo.TabPanelItem} tab The tab being changed to
5996 "beforetabchange" : true
5999 Roo.EventManager.onWindowResize(this.onResize, this);
6000 this.cpad = this.el.getPadding("lr");
6001 this.hiddenCount = 0;
6004 // toolbar on the tabbar support...
6006 var tcfg = this.toolbar;
6007 tcfg.container = this.stripEl.child('td.x-tab-strip-toolbar');
6008 this.toolbar = new Roo.Toolbar(tcfg);
6010 var tbl = tcfg.container.child('table', true);
6011 tbl.setAttribute('width', '100%');
6018 Roo.TabPanel.superclass.constructor.call(this);
6021 Roo.extend(Roo.TabPanel, Roo.util.Observable, {
6023 *@cfg {String} tabPosition "top" or "bottom" (defaults to "top")
6025 tabPosition : "top",
6027 *@cfg {Number} currentTabWidth The width of the current tab (defaults to 0)
6029 currentTabWidth : 0,
6031 *@cfg {Number} minTabWidth The minimum width of a tab (defaults to 40) (ignored if {@link #resizeTabs} is not true)
6035 *@cfg {Number} maxTabWidth The maximum width of a tab (defaults to 250) (ignored if {@link #resizeTabs} is not true)
6039 *@cfg {Number} preferredTabWidth The preferred (default) width of a tab (defaults to 175) (ignored if {@link #resizeTabs} is not true)
6041 preferredTabWidth : 175,
6043 *@cfg {Boolean} resizeTabs True to enable dynamic tab resizing (defaults to false)
6047 *@cfg {Boolean} monitorResize Set this to true to turn on window resize monitoring (ignored if {@link #resizeTabs} is not true) (defaults to true)
6049 monitorResize : true,
6051 *@cfg {Object} toolbar xtype description of toolbar to show at the right of the tab bar.
6056 * Creates a new {@link Roo.TabPanelItem} by looking for an existing element with the provided id -- if it's not found it creates one.
6057 * @param {String} id The id of the div to use <b>or create</b>
6058 * @param {String} text The text for the tab
6059 * @param {String} content (optional) Content to put in the TabPanelItem body
6060 * @param {Boolean} closable (optional) True to create a close icon on the tab
6061 * @return {Roo.TabPanelItem} The created TabPanelItem
6063 addTab : function(id, text, content, closable){
6064 var item = new Roo.TabPanelItem(this, id, text, closable);
6065 this.addTabItem(item);
6067 item.setContent(content);
6073 * Returns the {@link Roo.TabPanelItem} with the specified id/index
6074 * @param {String/Number} id The id or index of the TabPanelItem to fetch.
6075 * @return {Roo.TabPanelItem}
6077 getTab : function(id){
6078 return this.items[id];
6082 * Hides the {@link Roo.TabPanelItem} with the specified id/index
6083 * @param {String/Number} id The id or index of the TabPanelItem to hide.
6085 hideTab : function(id){
6086 var t = this.items[id];
6090 this.autoSizeTabs();
6095 * "Unhides" the {@link Roo.TabPanelItem} with the specified id/index.
6096 * @param {String/Number} id The id or index of the TabPanelItem to unhide.
6098 unhideTab : function(id){
6099 var t = this.items[id];
6103 this.autoSizeTabs();
6108 * Adds an existing {@link Roo.TabPanelItem}.
6109 * @param {Roo.TabPanelItem} item The TabPanelItem to add
6111 addTabItem : function(item){
6112 this.items[item.id] = item;
6113 this.items.push(item);
6114 if(this.resizeTabs){
6115 item.setWidth(this.currentTabWidth || this.preferredTabWidth);
6116 this.autoSizeTabs();
6123 * Removes a {@link Roo.TabPanelItem}.
6124 * @param {String/Number} id The id or index of the TabPanelItem to remove.
6126 removeTab : function(id){
6127 var items = this.items;
6128 var tab = items[id];
6129 if(!tab) { return; }
6130 var index = items.indexOf(tab);
6131 if(this.active == tab && items.length > 1){
6132 var newTab = this.getNextAvailable(index);
6137 this.stripEl.dom.removeChild(tab.pnode.dom);
6138 if(tab.bodyEl.dom.parentNode == this.bodyEl.dom){ // if it was moved already prevent error
6139 this.bodyEl.dom.removeChild(tab.bodyEl.dom);
6141 items.splice(index, 1);
6142 delete this.items[tab.id];
6143 tab.fireEvent("close", tab);
6144 tab.purgeListeners();
6145 this.autoSizeTabs();
6148 getNextAvailable : function(start){
6149 var items = this.items;
6151 // look for a next tab that will slide over to
6152 // replace the one being removed
6153 while(index < items.length){
6154 var item = items[++index];
6155 if(item && !item.isHidden()){
6159 // if one isn't found select the previous tab (on the left)
6162 var item = items[--index];
6163 if(item && !item.isHidden()){
6171 * Disables a {@link Roo.TabPanelItem}. It cannot be the active tab, if it is this call is ignored.
6172 * @param {String/Number} id The id or index of the TabPanelItem to disable.
6174 disableTab : function(id){
6175 var tab = this.items[id];
6176 if(tab && this.active != tab){
6182 * Enables a {@link Roo.TabPanelItem} that is disabled.
6183 * @param {String/Number} id The id or index of the TabPanelItem to enable.
6185 enableTab : function(id){
6186 var tab = this.items[id];
6191 * Activates a {@link Roo.TabPanelItem}. The currently active one will be deactivated.
6192 * @param {String/Number} id The id or index of the TabPanelItem to activate.
6193 * @return {Roo.TabPanelItem} The TabPanelItem.
6195 activate : function(id){
6196 var tab = this.items[id];
6200 if(tab == this.active || tab.disabled){
6204 this.fireEvent("beforetabchange", this, e, tab);
6205 if(e.cancel !== true && !tab.disabled){
6209 this.active = this.items[id];
6211 this.fireEvent("tabchange", this, this.active);
6217 * Gets the active {@link Roo.TabPanelItem}.
6218 * @return {Roo.TabPanelItem} The active TabPanelItem or null if none are active.
6220 getActiveTab : function(){
6225 * Updates the tab body element to fit the height of the container element
6226 * for overflow scrolling
6227 * @param {Number} targetHeight (optional) Override the starting height from the elements height
6229 syncHeight : function(targetHeight){
6230 var height = (targetHeight || this.el.getHeight())-this.el.getBorderWidth("tb")-this.el.getPadding("tb");
6231 var bm = this.bodyEl.getMargins();
6232 var newHeight = height-(this.stripWrap.getHeight()||0)-(bm.top+bm.bottom);
6233 this.bodyEl.setHeight(newHeight);
6237 onResize : function(){
6238 if(this.monitorResize){
6239 this.autoSizeTabs();
6244 * Disables tab resizing while tabs are being added (if {@link #resizeTabs} is false this does nothing)
6246 beginUpdate : function(){
6247 this.updating = true;
6251 * Stops an update and resizes the tabs (if {@link #resizeTabs} is false this does nothing)
6253 endUpdate : function(){
6254 this.updating = false;
6255 this.autoSizeTabs();
6259 * Manual call to resize the tabs (if {@link #resizeTabs} is false this does nothing)
6261 autoSizeTabs : function(){
6262 var count = this.items.length;
6263 var vcount = count - this.hiddenCount;
6264 if(!this.resizeTabs || count < 1 || vcount < 1 || this.updating) {
6267 var w = Math.max(this.el.getWidth() - this.cpad, 10);
6268 var availWidth = Math.floor(w / vcount);
6269 var b = this.stripBody;
6270 if(b.getWidth() > w){
6271 var tabs = this.items;
6272 this.setTabWidth(Math.max(availWidth, this.minTabWidth)-2);
6273 if(availWidth < this.minTabWidth){
6274 /*if(!this.sleft){ // incomplete scrolling code
6275 this.createScrollButtons();
6278 this.stripClip.setWidth(w - (this.sleft.getWidth()+this.sright.getWidth()));*/
6281 if(this.currentTabWidth < this.preferredTabWidth){
6282 this.setTabWidth(Math.min(availWidth, this.preferredTabWidth)-2);
6288 * Returns the number of tabs in this TabPanel.
6291 getCount : function(){
6292 return this.items.length;
6296 * Resizes all the tabs to the passed width
6297 * @param {Number} The new width
6299 setTabWidth : function(width){
6300 this.currentTabWidth = width;
6301 for(var i = 0, len = this.items.length; i < len; i++) {
6302 if(!this.items[i].isHidden()) {
6303 this.items[i].setWidth(width);
6309 * Destroys this TabPanel
6310 * @param {Boolean} removeEl (optional) True to remove the element from the DOM as well (defaults to undefined)
6312 destroy : function(removeEl){
6313 Roo.EventManager.removeResizeListener(this.onResize, this);
6314 for(var i = 0, len = this.items.length; i < len; i++){
6315 this.items[i].purgeListeners();
6317 if(removeEl === true){
6325 * @class Roo.TabPanelItem
6326 * @extends Roo.util.Observable
6327 * Represents an individual item (tab plus body) in a TabPanel.
6328 * @param {Roo.TabPanel} tabPanel The {@link Roo.TabPanel} this TabPanelItem belongs to
6329 * @param {String} id The id of this TabPanelItem
6330 * @param {String} text The text for the tab of this TabPanelItem
6331 * @param {Boolean} closable True to allow this TabPanelItem to be closable (defaults to false)
6333 Roo.TabPanelItem = function(tabPanel, id, text, closable){
6335 * The {@link Roo.TabPanel} this TabPanelItem belongs to
6336 * @type Roo.TabPanel
6338 this.tabPanel = tabPanel;
6340 * The id for this TabPanelItem
6345 this.disabled = false;
6349 this.loaded = false;
6350 this.closable = closable;
6353 * The body element for this TabPanelItem.
6356 this.bodyEl = Roo.get(tabPanel.createItemBody(tabPanel.bodyEl.dom, id));
6357 this.bodyEl.setVisibilityMode(Roo.Element.VISIBILITY);
6358 this.bodyEl.setStyle("display", "block");
6359 this.bodyEl.setStyle("zoom", "1");
6362 var els = tabPanel.createStripElements(tabPanel.stripEl.dom, text, closable);
6364 this.el = Roo.get(els.el, true);
6365 this.inner = Roo.get(els.inner, true);
6366 this.textEl = Roo.get(this.el.dom.firstChild.firstChild.firstChild, true);
6367 this.pnode = Roo.get(els.el.parentNode, true);
6368 this.el.on("mousedown", this.onTabMouseDown, this);
6369 this.el.on("click", this.onTabClick, this);
6372 var c = Roo.get(els.close, true);
6373 c.dom.title = this.closeText;
6374 c.addClassOnOver("close-over");
6375 c.on("click", this.closeClick, this);
6381 * Fires when this tab becomes the active tab.
6382 * @param {Roo.TabPanel} tabPanel The parent TabPanel
6383 * @param {Roo.TabPanelItem} this
6387 * @event beforeclose
6388 * Fires before this tab is closed. To cancel the close, set cancel to true on e (e.cancel = true).
6389 * @param {Roo.TabPanelItem} this
6390 * @param {Object} e Set cancel to true on this object to cancel the close.
6392 "beforeclose": true,
6395 * Fires when this tab is closed.
6396 * @param {Roo.TabPanelItem} this
6401 * Fires when this tab is no longer the active tab.
6402 * @param {Roo.TabPanel} tabPanel The parent TabPanel
6403 * @param {Roo.TabPanelItem} this
6407 this.hidden = false;
6409 Roo.TabPanelItem.superclass.constructor.call(this);
6412 Roo.extend(Roo.TabPanelItem, Roo.util.Observable, {
6413 purgeListeners : function(){
6414 Roo.util.Observable.prototype.purgeListeners.call(this);
6415 this.el.removeAllListeners();
6418 * Shows this TabPanelItem -- this <b>does not</b> deactivate the currently active TabPanelItem.
6421 this.pnode.addClass("on");
6424 this.tabPanel.stripWrap.repaint();
6426 this.fireEvent("activate", this.tabPanel, this);
6430 * Returns true if this tab is the active tab.
6433 isActive : function(){
6434 return this.tabPanel.getActiveTab() == this;
6438 * Hides this TabPanelItem -- if you don't activate another TabPanelItem this could look odd.
6441 this.pnode.removeClass("on");
6443 this.fireEvent("deactivate", this.tabPanel, this);
6446 hideAction : function(){
6448 this.bodyEl.setStyle("position", "absolute");
6449 this.bodyEl.setLeft("-20000px");
6450 this.bodyEl.setTop("-20000px");
6453 showAction : function(){
6454 this.bodyEl.setStyle("position", "relative");
6455 this.bodyEl.setTop("");
6456 this.bodyEl.setLeft("");
6461 * Set the tooltip for the tab.
6462 * @param {String} tooltip The tab's tooltip
6464 setTooltip : function(text){
6465 if(Roo.QuickTips && Roo.QuickTips.isEnabled()){
6466 this.textEl.dom.qtip = text;
6467 this.textEl.dom.removeAttribute('title');
6469 this.textEl.dom.title = text;
6473 onTabClick : function(e){
6475 this.tabPanel.activate(this.id);
6478 onTabMouseDown : function(e){
6480 this.tabPanel.activate(this.id);
6483 getWidth : function(){
6484 return this.inner.getWidth();
6487 setWidth : function(width){
6488 var iwidth = width - this.pnode.getPadding("lr");
6489 this.inner.setWidth(iwidth);
6490 this.textEl.setWidth(iwidth-this.inner.getPadding("lr"));
6491 this.pnode.setWidth(width);
6495 * Show or hide the tab
6496 * @param {Boolean} hidden True to hide or false to show.
6498 setHidden : function(hidden){
6499 this.hidden = hidden;
6500 this.pnode.setStyle("display", hidden ? "none" : "");
6504 * Returns true if this tab is "hidden"
6507 isHidden : function(){
6512 * Returns the text for this tab
6515 getText : function(){
6519 autoSize : function(){
6520 //this.el.beginMeasure();
6521 this.textEl.setWidth(1);
6523 * #2804 [new] Tabs in Roojs
6524 * increase the width by 2-4 pixels to prevent the ellipssis showing in chrome
6526 this.setWidth(this.textEl.dom.scrollWidth+this.pnode.getPadding("lr")+this.inner.getPadding("lr") + 2);
6527 //this.el.endMeasure();
6531 * Sets the text for the tab (Note: this also sets the tooltip text)
6532 * @param {String} text The tab's text and tooltip
6534 setText : function(text){
6536 this.textEl.update(text);
6537 this.setTooltip(text);
6538 if(!this.tabPanel.resizeTabs){
6543 * Activates this TabPanelItem -- this <b>does</b> deactivate the currently active TabPanelItem.
6545 activate : function(){
6546 this.tabPanel.activate(this.id);
6550 * Disables this TabPanelItem -- this does nothing if this is the active TabPanelItem.
6552 disable : function(){
6553 if(this.tabPanel.active != this){
6554 this.disabled = true;
6555 this.pnode.addClass("disabled");
6560 * Enables this TabPanelItem if it was previously disabled.
6562 enable : function(){
6563 this.disabled = false;
6564 this.pnode.removeClass("disabled");
6568 * Sets the content for this TabPanelItem.
6569 * @param {String} content The content
6570 * @param {Boolean} loadScripts true to look for and load scripts
6572 setContent : function(content, loadScripts){
6573 this.bodyEl.update(content, loadScripts);
6577 * Gets the {@link Roo.UpdateManager} for the body of this TabPanelItem. Enables you to perform Ajax updates.
6578 * @return {Roo.UpdateManager} The UpdateManager
6580 getUpdateManager : function(){
6581 return this.bodyEl.getUpdateManager();
6585 * Set a URL to be used to load the content for this TabPanelItem.
6586 * @param {String/Function} url The URL to load the content from, or a function to call to get the URL
6587 * @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)
6588 * @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)
6589 * @return {Roo.UpdateManager} The UpdateManager
6591 setUrl : function(url, params, loadOnce){
6592 if(this.refreshDelegate){
6593 this.un('activate', this.refreshDelegate);
6595 this.refreshDelegate = this._handleRefresh.createDelegate(this, [url, params, loadOnce]);
6596 this.on("activate", this.refreshDelegate);
6597 return this.bodyEl.getUpdateManager();
6601 _handleRefresh : function(url, params, loadOnce){
6602 if(!loadOnce || !this.loaded){
6603 var updater = this.bodyEl.getUpdateManager();
6604 updater.update(url, params, this._setLoaded.createDelegate(this));
6609 * Forces a content refresh from the URL specified in the {@link #setUrl} method.
6610 * Will fail silently if the setUrl method has not been called.
6611 * This does not activate the panel, just updates its content.
6613 refresh : function(){
6614 if(this.refreshDelegate){
6615 this.loaded = false;
6616 this.refreshDelegate();
6621 _setLoaded : function(){
6626 closeClick : function(e){
6629 this.fireEvent("beforeclose", this, o);
6630 if(o.cancel !== true){
6631 this.tabPanel.removeTab(this.id);
6635 * The text displayed in the tooltip for the close icon.
6638 closeText : "Close this tab"
6642 Roo.TabPanel.prototype.createStrip = function(container){
6643 var strip = document.createElement("div");
6644 strip.className = "x-tabs-wrap";
6645 container.appendChild(strip);
6649 Roo.TabPanel.prototype.createStripList = function(strip){
6650 // div wrapper for retard IE
6651 // returns the "tr" element.
6652 strip.innerHTML = '<div class="x-tabs-strip-wrap">'+
6653 '<table class="x-tabs-strip" cellspacing="0" cellpadding="0" border="0"><tbody><tr>'+
6654 '<td class="x-tab-strip-toolbar"></td></tr></tbody></table></div>';
6655 return strip.firstChild.firstChild.firstChild.firstChild;
6658 Roo.TabPanel.prototype.createBody = function(container){
6659 var body = document.createElement("div");
6660 Roo.id(body, "tab-body");
6661 Roo.fly(body).addClass("x-tabs-body");
6662 container.appendChild(body);
6666 Roo.TabPanel.prototype.createItemBody = function(bodyEl, id){
6667 var body = Roo.getDom(id);
6669 body = document.createElement("div");
6672 Roo.fly(body).addClass("x-tabs-item-body");
6673 bodyEl.insertBefore(body, bodyEl.firstChild);
6677 Roo.TabPanel.prototype.createStripElements = function(stripEl, text, closable){
6678 var td = document.createElement("td");
6679 stripEl.insertBefore(td, stripEl.childNodes[stripEl.childNodes.length-1]);
6680 //stripEl.appendChild(td);
6682 td.className = "x-tabs-closable";
6684 this.closeTpl = new Roo.Template(
6685 '<a href="#" class="x-tabs-right"><span class="x-tabs-left"><em class="x-tabs-inner">' +
6686 '<span unselectable="on"' + (this.disableTooltips ? '' : ' title="{text}"') +' class="x-tabs-text">{text}</span>' +
6687 '<div unselectable="on" class="close-icon"> </div></em></span></a>'
6690 var el = this.closeTpl.overwrite(td, {"text": text});
6691 var close = el.getElementsByTagName("div")[0];
6692 var inner = el.getElementsByTagName("em")[0];
6693 return {"el": el, "close": close, "inner": inner};
6696 this.tabTpl = new Roo.Template(
6697 '<a href="#" class="x-tabs-right"><span class="x-tabs-left"><em class="x-tabs-inner">' +
6698 '<span unselectable="on"' + (this.disableTooltips ? '' : ' title="{text}"') +' class="x-tabs-text">{text}</span></em></span></a>'
6701 var el = this.tabTpl.overwrite(td, {"text": text});
6702 var inner = el.getElementsByTagName("em")[0];
6703 return {"el": el, "inner": inner};
6707 * Ext JS Library 1.1.1
6708 * Copyright(c) 2006-2007, Ext JS, LLC.
6710 * Originally Released Under LGPL - original licence link has changed is not relivant.
6713 * <script type="text/javascript">
6718 * @extends Roo.util.Observable
6719 * Simple Button class
6720 * @cfg {String} text The button text
6721 * @cfg {String} icon The path to an image to display in the button (the image will be set as the background-image
6722 * CSS property of the button by default, so if you want a mixed icon/text button, set cls:"x-btn-text-icon")
6723 * @cfg {Function} handler A function called when the button is clicked (can be used instead of click event)
6724 * @cfg {Object} scope The scope of the handler
6725 * @cfg {Number} minWidth The minimum width for this button (used to give a set of buttons a common width)
6726 * @cfg {String/Object} tooltip The tooltip for the button - can be a string or QuickTips config object
6727 * @cfg {Boolean} hidden True to start hidden (defaults to false)
6728 * @cfg {Boolean} disabled True to start disabled (defaults to false)
6729 * @cfg {Boolean} pressed True to start pressed (only if enableToggle = true)
6730 * @cfg {String} toggleGroup The group this toggle button is a member of (only 1 per group can be pressed, only
6731 applies if enableToggle = true)
6732 * @cfg {String/HTMLElement/Element} renderTo The element to append the button to
6733 * @cfg {Boolean/Object} repeat True to repeat fire the click event while the mouse is down. This can also be
6734 an {@link Roo.util.ClickRepeater} config object (defaults to false).
6736 * Create a new button
6737 * @param {Object} config The config object
6739 Roo.Button = function(renderTo, config)
6743 renderTo = config.renderTo || false;
6746 Roo.apply(this, config);
6750 * Fires when this button is clicked
6751 * @param {Button} this
6752 * @param {EventObject} e The click event
6757 * Fires when the "pressed" state of this button changes (only if enableToggle = true)
6758 * @param {Button} this
6759 * @param {Boolean} pressed
6764 * Fires when the mouse hovers over the button
6765 * @param {Button} this
6766 * @param {Event} e The event object
6771 * Fires when the mouse exits the button
6772 * @param {Button} this
6773 * @param {Event} e The event object
6778 * Fires when the button is rendered
6779 * @param {Button} this
6784 this.menu = Roo.menu.MenuMgr.get(this.menu);
6786 // register listeners first!! - so render can be captured..
6787 Roo.util.Observable.call(this);
6789 this.render(renderTo);
6795 Roo.extend(Roo.Button, Roo.util.Observable, {
6801 * Read-only. True if this button is hidden
6806 * Read-only. True if this button is disabled
6811 * Read-only. True if this button is pressed (only if enableToggle = true)
6817 * @cfg {Number} tabIndex
6818 * The DOM tabIndex for this button (defaults to undefined)
6820 tabIndex : undefined,
6823 * @cfg {Boolean} enableToggle
6824 * True to enable pressed/not pressed toggling (defaults to false)
6826 enableToggle: false,
6829 * Standard menu attribute consisting of a reference to a menu object, a menu id or a menu config blob (defaults to undefined).
6833 * @cfg {String} menuAlign
6834 * The position to align the menu to (see {@link Roo.Element#alignTo} for more details, defaults to 'tl-bl?').
6836 menuAlign : "tl-bl?",
6839 * @cfg {String} iconCls
6840 * A css class which sets a background image to be used as the icon for this button (defaults to undefined).
6842 iconCls : undefined,
6844 * @cfg {String} type
6845 * The button's type, corresponding to the DOM input element type attribute. Either "submit," "reset" or "button" (default).
6850 menuClassTarget: 'tr',
6853 * @cfg {String} clickEvent
6854 * The type of event to map to the button's event handler (defaults to 'click')
6856 clickEvent : 'click',
6859 * @cfg {Boolean} handleMouseEvents
6860 * False to disable visual cues on mouseover, mouseout and mousedown (defaults to true)
6862 handleMouseEvents : true,
6865 * @cfg {String} tooltipType
6866 * The type of tooltip to use. Either "qtip" (default) for QuickTips or "title" for title attribute.
6868 tooltipType : 'qtip',
6872 * A CSS class to apply to the button's main element.
6876 * @cfg {Roo.Template} template (Optional)
6877 * An {@link Roo.Template} with which to create the Button's main element. This Template must
6878 * contain numeric substitution parameter 0 if it is to display the tRoo property. Changing the template could
6879 * require code modifications if required elements (e.g. a button) aren't present.
6883 render : function(renderTo){
6885 if(this.hideParent){
6886 this.parentEl = Roo.get(renderTo);
6890 if(!Roo.Button.buttonTemplate){
6891 // hideous table template
6892 Roo.Button.buttonTemplate = new Roo.Template(
6893 '<table border="0" cellpadding="0" cellspacing="0" class="x-btn-wrap"><tbody><tr>',
6894 '<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>',
6895 "</tr></tbody></table>");
6897 this.template = Roo.Button.buttonTemplate;
6899 btn = this.template.append(renderTo, [this.text || ' ', this.type], true);
6900 var btnEl = btn.child("button:first");
6901 btnEl.on('focus', this.onFocus, this);
6902 btnEl.on('blur', this.onBlur, this);
6904 btn.addClass(this.cls);
6907 btnEl.setStyle('background-image', 'url(' +this.icon +')');
6910 btnEl.addClass(this.iconCls);
6912 btn.addClass(this.text ? 'x-btn-text-icon' : 'x-btn-icon');
6915 if(this.tabIndex !== undefined){
6916 btnEl.dom.tabIndex = this.tabIndex;
6919 if(typeof this.tooltip == 'object'){
6920 Roo.QuickTips.tips(Roo.apply({
6924 btnEl.dom[this.tooltipType] = this.tooltip;
6928 btn = Roo.DomHelper.append(Roo.get(renderTo).dom, this.dhconfig, true);
6932 this.el.dom.id = this.el.id = this.id;
6935 this.el.child(this.menuClassTarget).addClass("x-btn-with-menu");
6936 this.menu.on("show", this.onMenuShow, this);
6937 this.menu.on("hide", this.onMenuHide, this);
6939 btn.addClass("x-btn");
6940 if(Roo.isIE && !Roo.isIE7){
6941 this.autoWidth.defer(1, this);
6945 if(this.handleMouseEvents){
6946 btn.on("mouseover", this.onMouseOver, this);
6947 btn.on("mouseout", this.onMouseOut, this);
6948 btn.on("mousedown", this.onMouseDown, this);
6950 btn.on(this.clickEvent, this.onClick, this);
6951 //btn.on("mouseup", this.onMouseUp, this);
6958 Roo.ButtonToggleMgr.register(this);
6960 this.el.addClass("x-btn-pressed");
6963 var repeater = new Roo.util.ClickRepeater(btn,
6964 typeof this.repeat == "object" ? this.repeat : {}
6966 repeater.on("click", this.onClick, this);
6969 this.fireEvent('render', this);
6973 * Returns the button's underlying element
6974 * @return {Roo.Element} The element
6981 * Destroys this Button and removes any listeners.
6983 destroy : function(){
6984 Roo.ButtonToggleMgr.unregister(this);
6985 this.el.removeAllListeners();
6986 this.purgeListeners();
6991 autoWidth : function(){
6993 this.el.setWidth("auto");
6994 if(Roo.isIE7 && Roo.isStrict){
6995 var ib = this.el.child('button');
6996 if(ib && ib.getWidth() > 20){
6998 ib.setWidth(Roo.util.TextMetrics.measure(ib, this.text).width+ib.getFrameWidth('lr'));
7003 this.el.beginMeasure();
7005 if(this.el.getWidth() < this.minWidth){
7006 this.el.setWidth(this.minWidth);
7009 this.el.endMeasure();
7016 * Assigns this button's click handler
7017 * @param {Function} handler The function to call when the button is clicked
7018 * @param {Object} scope (optional) Scope for the function passed in
7020 setHandler : function(handler, scope){
7021 this.handler = handler;
7026 * Sets this button's text
7027 * @param {String} text The button text
7029 setText : function(text){
7032 this.el.child("td.x-btn-center button.x-btn-text").update(text);
7038 * Gets the text for this button
7039 * @return {String} The button text
7041 getText : function(){
7049 this.hidden = false;
7051 this[this.hideParent? 'parentEl' : 'el'].setStyle("display", "");
7061 this[this.hideParent? 'parentEl' : 'el'].setStyle("display", "none");
7066 * Convenience function for boolean show/hide
7067 * @param {Boolean} visible True to show, false to hide
7069 setVisible: function(visible){
7078 * If a state it passed, it becomes the pressed state otherwise the current state is toggled.
7079 * @param {Boolean} state (optional) Force a particular state
7081 toggle : function(state){
7082 state = state === undefined ? !this.pressed : state;
7083 if(state != this.pressed){
7085 this.el.addClass("x-btn-pressed");
7086 this.pressed = true;
7087 this.fireEvent("toggle", this, true);
7089 this.el.removeClass("x-btn-pressed");
7090 this.pressed = false;
7091 this.fireEvent("toggle", this, false);
7093 if(this.toggleHandler){
7094 this.toggleHandler.call(this.scope || this, this, state);
7103 this.el.child('button:first').focus();
7107 * Disable this button
7109 disable : function(){
7111 this.el.addClass("x-btn-disabled");
7113 this.disabled = true;
7117 * Enable this button
7119 enable : function(){
7121 this.el.removeClass("x-btn-disabled");
7123 this.disabled = false;
7127 * Convenience function for boolean enable/disable
7128 * @param {Boolean} enabled True to enable, false to disable
7130 setDisabled : function(v){
7131 this[v !== true ? "enable" : "disable"]();
7135 onClick : function(e)
7144 if(this.enableToggle){
7147 if(this.menu && !this.menu.isVisible()){
7148 this.menu.show(this.el, this.menuAlign);
7150 this.fireEvent("click", this, e);
7152 this.el.removeClass("x-btn-over");
7153 this.handler.call(this.scope || this, this, e);
7158 onMouseOver : function(e){
7160 this.el.addClass("x-btn-over");
7161 this.fireEvent('mouseover', this, e);
7165 onMouseOut : function(e){
7166 if(!e.within(this.el, true)){
7167 this.el.removeClass("x-btn-over");
7168 this.fireEvent('mouseout', this, e);
7172 onFocus : function(e){
7174 this.el.addClass("x-btn-focus");
7178 onBlur : function(e){
7179 this.el.removeClass("x-btn-focus");
7182 onMouseDown : function(e){
7183 if(!this.disabled && e.button == 0){
7184 this.el.addClass("x-btn-click");
7185 Roo.get(document).on('mouseup', this.onMouseUp, this);
7189 onMouseUp : function(e){
7191 this.el.removeClass("x-btn-click");
7192 Roo.get(document).un('mouseup', this.onMouseUp, this);
7196 onMenuShow : function(e){
7197 this.el.addClass("x-btn-menu-active");
7200 onMenuHide : function(e){
7201 this.el.removeClass("x-btn-menu-active");
7205 // Private utility class used by Button
7206 Roo.ButtonToggleMgr = function(){
7209 function toggleGroup(btn, state){
7211 var g = groups[btn.toggleGroup];
7212 for(var i = 0, l = g.length; i < l; i++){
7221 register : function(btn){
7222 if(!btn.toggleGroup){
7225 var g = groups[btn.toggleGroup];
7227 g = groups[btn.toggleGroup] = [];
7230 btn.on("toggle", toggleGroup);
7233 unregister : function(btn){
7234 if(!btn.toggleGroup){
7237 var g = groups[btn.toggleGroup];
7240 btn.un("toggle", toggleGroup);
7246 * Ext JS Library 1.1.1
7247 * Copyright(c) 2006-2007, Ext JS, LLC.
7249 * Originally Released Under LGPL - original licence link has changed is not relivant.
7252 * <script type="text/javascript">
7256 * @class Roo.SplitButton
7257 * @extends Roo.Button
7258 * A split button that provides a built-in dropdown arrow that can fire an event separately from the default
7259 * click event of the button. Typically this would be used to display a dropdown menu that provides additional
7260 * options to the primary button action, but any custom handler can provide the arrowclick implementation.
7261 * @cfg {Function} arrowHandler A function called when the arrow button is clicked (can be used instead of click event)
7262 * @cfg {String} arrowTooltip The title attribute of the arrow
7264 * Create a new menu button
7265 * @param {String/HTMLElement/Element} renderTo The element to append the button to
7266 * @param {Object} config The config object
7268 Roo.SplitButton = function(renderTo, config){
7269 Roo.SplitButton.superclass.constructor.call(this, renderTo, config);
7272 * Fires when this button's arrow is clicked
7273 * @param {SplitButton} this
7274 * @param {EventObject} e The click event
7276 this.addEvents({"arrowclick":true});
7279 Roo.extend(Roo.SplitButton, Roo.Button, {
7280 render : function(renderTo){
7281 // this is one sweet looking template!
7282 var tpl = new Roo.Template(
7283 '<table cellspacing="0" class="x-btn-menu-wrap x-btn"><tr><td>',
7284 '<table cellspacing="0" class="x-btn-wrap x-btn-menu-text-wrap"><tbody>',
7285 '<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>',
7286 "</tbody></table></td><td>",
7287 '<table cellspacing="0" class="x-btn-wrap x-btn-menu-arrow-wrap"><tbody>',
7288 '<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>',
7289 "</tbody></table></td></tr></table>"
7291 var btn = tpl.append(renderTo, [this.text, this.type], true);
7292 var btnEl = btn.child("button");
7294 btn.addClass(this.cls);
7297 btnEl.setStyle('background-image', 'url(' +this.icon +')');
7300 btnEl.addClass(this.iconCls);
7302 btn.addClass(this.text ? 'x-btn-text-icon' : 'x-btn-icon');
7306 if(this.handleMouseEvents){
7307 btn.on("mouseover", this.onMouseOver, this);
7308 btn.on("mouseout", this.onMouseOut, this);
7309 btn.on("mousedown", this.onMouseDown, this);
7310 btn.on("mouseup", this.onMouseUp, this);
7312 btn.on(this.clickEvent, this.onClick, this);
7314 if(typeof this.tooltip == 'object'){
7315 Roo.QuickTips.tips(Roo.apply({
7319 btnEl.dom[this.tooltipType] = this.tooltip;
7322 if(this.arrowTooltip){
7323 btn.child("button:nth(2)").dom[this.tooltipType] = this.arrowTooltip;
7332 this.el.addClass("x-btn-pressed");
7334 if(Roo.isIE && !Roo.isIE7){
7335 this.autoWidth.defer(1, this);
7340 this.menu.on("show", this.onMenuShow, this);
7341 this.menu.on("hide", this.onMenuHide, this);
7343 this.fireEvent('render', this);
7347 autoWidth : function(){
7349 var tbl = this.el.child("table:first");
7350 var tbl2 = this.el.child("table:last");
7351 this.el.setWidth("auto");
7352 tbl.setWidth("auto");
7353 if(Roo.isIE7 && Roo.isStrict){
7354 var ib = this.el.child('button:first');
7355 if(ib && ib.getWidth() > 20){
7357 ib.setWidth(Roo.util.TextMetrics.measure(ib, this.text).width+ib.getFrameWidth('lr'));
7362 this.el.beginMeasure();
7364 if((tbl.getWidth()+tbl2.getWidth()) < this.minWidth){
7365 tbl.setWidth(this.minWidth-tbl2.getWidth());
7368 this.el.endMeasure();
7371 this.el.setWidth(tbl.getWidth()+tbl2.getWidth());
7375 * Sets this button's click handler
7376 * @param {Function} handler The function to call when the button is clicked
7377 * @param {Object} scope (optional) Scope for the function passed above
7379 setHandler : function(handler, scope){
7380 this.handler = handler;
7385 * Sets this button's arrow click handler
7386 * @param {Function} handler The function to call when the arrow is clicked
7387 * @param {Object} scope (optional) Scope for the function passed above
7389 setArrowHandler : function(handler, scope){
7390 this.arrowHandler = handler;
7399 this.el.child("button:first").focus();
7404 onClick : function(e){
7407 if(e.getTarget(".x-btn-menu-arrow-wrap")){
7408 if(this.menu && !this.menu.isVisible()){
7409 this.menu.show(this.el, this.menuAlign);
7411 this.fireEvent("arrowclick", this, e);
7412 if(this.arrowHandler){
7413 this.arrowHandler.call(this.scope || this, this, e);
7416 this.fireEvent("click", this, e);
7418 this.handler.call(this.scope || this, this, e);
7424 onMouseDown : function(e){
7426 Roo.fly(e.getTarget("table")).addClass("x-btn-click");
7430 onMouseUp : function(e){
7431 Roo.fly(e.getTarget("table")).removeClass("x-btn-click");
7437 Roo.MenuButton = Roo.SplitButton;/*
7439 * Ext JS Library 1.1.1
7440 * Copyright(c) 2006-2007, Ext JS, LLC.
7442 * Originally Released Under LGPL - original licence link has changed is not relivant.
7445 * <script type="text/javascript">
7449 * @class Roo.Toolbar
7450 * Basic Toolbar class.
7452 * Creates a new Toolbar
7453 * @param {Object} container The config object
7455 Roo.Toolbar = function(container, buttons, config)
7457 /// old consturctor format still supported..
7458 if(container instanceof Array){ // omit the container for later rendering
7459 buttons = container;
7463 if (typeof(container) == 'object' && container.xtype) {
7465 container = config.container;
7466 buttons = config.buttons || []; // not really - use items!!
7469 if (config && config.items) {
7470 xitems = config.items;
7471 delete config.items;
7473 Roo.apply(this, config);
7474 this.buttons = buttons;
7477 this.render(container);
7479 this.xitems = xitems;
7480 Roo.each(xitems, function(b) {
7486 Roo.Toolbar.prototype = {
7488 * @cfg {Array} items
7489 * array of button configs or elements to add (will be converted to a MixedCollection)
7493 * @cfg {String/HTMLElement/Element} container
7494 * The id or element that will contain the toolbar
7497 render : function(ct){
7498 this.el = Roo.get(ct);
7500 this.el.addClass(this.cls);
7502 // using a table allows for vertical alignment
7503 // 100% width is needed by Safari...
7504 this.el.update('<div class="x-toolbar x-small-editor"><table cellspacing="0"><tr></tr></table></div>');
7505 this.tr = this.el.child("tr", true);
7507 this.items = new Roo.util.MixedCollection(false, function(o){
7508 return o.id || ("item" + (++autoId));
7511 this.add.apply(this, this.buttons);
7512 delete this.buttons;
7517 * Adds element(s) to the toolbar -- this function takes a variable number of
7518 * arguments of mixed type and adds them to the toolbar.
7519 * @param {Mixed} arg1 The following types of arguments are all valid:<br />
7521 * <li>{@link Roo.Toolbar.Button} config: A valid button config object (equivalent to {@link #addButton})</li>
7522 * <li>HtmlElement: Any standard HTML element (equivalent to {@link #addElement})</li>
7523 * <li>Field: Any form field (equivalent to {@link #addField})</li>
7524 * <li>Item: Any subclass of {@link Roo.Toolbar.Item} (equivalent to {@link #addItem})</li>
7525 * <li>String: Any generic string (gets wrapped in a {@link Roo.Toolbar.TextItem}, equivalent to {@link #addText}).
7526 * Note that there are a few special strings that are treated differently as explained nRoo.</li>
7527 * <li>'separator' or '-': Creates a separator element (equivalent to {@link #addSeparator})</li>
7528 * <li>' ': Creates a spacer element (equivalent to {@link #addSpacer})</li>
7529 * <li>'->': Creates a fill element (equivalent to {@link #addFill})</li>
7531 * @param {Mixed} arg2
7532 * @param {Mixed} etc.
7535 var a = arguments, l = a.length;
7536 for(var i = 0; i < l; i++){
7541 _add : function(el) {
7544 el = Roo.factory(el, typeof(Roo.Toolbar[el.xtype]) == 'undefined' ? Roo.form : Roo.Toolbar);
7547 if (el.applyTo){ // some kind of form field
7548 return this.addField(el);
7550 if (el.render){ // some kind of Toolbar.Item
7551 return this.addItem(el);
7553 if (typeof el == "string"){ // string
7554 if(el == "separator" || el == "-"){
7555 return this.addSeparator();
7558 return this.addSpacer();
7561 return this.addFill();
7563 return this.addText(el);
7566 if(el.tagName){ // element
7567 return this.addElement(el);
7569 if(typeof el == "object"){ // must be button config?
7570 return this.addButton(el);
7578 * Add an Xtype element
7579 * @param {Object} xtype Xtype Object
7580 * @return {Object} created Object
7582 addxtype : function(e){
7587 * Returns the Element for this toolbar.
7588 * @return {Roo.Element}
7596 * @return {Roo.Toolbar.Item} The separator item
7598 addSeparator : function(){
7599 return this.addItem(new Roo.Toolbar.Separator());
7603 * Adds a spacer element
7604 * @return {Roo.Toolbar.Spacer} The spacer item
7606 addSpacer : function(){
7607 return this.addItem(new Roo.Toolbar.Spacer());
7611 * Adds a fill element that forces subsequent additions to the right side of the toolbar
7612 * @return {Roo.Toolbar.Fill} The fill item
7614 addFill : function(){
7615 return this.addItem(new Roo.Toolbar.Fill());
7619 * Adds any standard HTML element to the toolbar
7620 * @param {String/HTMLElement/Element} el The element or id of the element to add
7621 * @return {Roo.Toolbar.Item} The element's item
7623 addElement : function(el){
7624 return this.addItem(new Roo.Toolbar.Item(el));
7627 * Collection of items on the toolbar.. (only Toolbar Items, so use fields to retrieve fields)
7628 * @type Roo.util.MixedCollection
7633 * Adds any Toolbar.Item or subclass
7634 * @param {Roo.Toolbar.Item} item
7635 * @return {Roo.Toolbar.Item} The item
7637 addItem : function(item){
7638 var td = this.nextBlock();
7640 this.items.add(item);
7645 * Adds a button (or buttons). See {@link Roo.Toolbar.Button} for more info on the config.
7646 * @param {Object/Array} config A button config or array of configs
7647 * @return {Roo.Toolbar.Button/Array}
7649 addButton : function(config){
7650 if(config instanceof Array){
7652 for(var i = 0, len = config.length; i < len; i++) {
7653 buttons.push(this.addButton(config[i]));
7658 if(!(config instanceof Roo.Toolbar.Button)){
7660 new Roo.Toolbar.SplitButton(config) :
7661 new Roo.Toolbar.Button(config);
7663 var td = this.nextBlock();
7670 * Adds text to the toolbar
7671 * @param {String} text The text to add
7672 * @return {Roo.Toolbar.Item} The element's item
7674 addText : function(text){
7675 return this.addItem(new Roo.Toolbar.TextItem(text));
7679 * Inserts any {@link Roo.Toolbar.Item}/{@link Roo.Toolbar.Button} at the specified index.
7680 * @param {Number} index The index where the item is to be inserted
7681 * @param {Object/Roo.Toolbar.Item/Roo.Toolbar.Button (may be Array)} item The button, or button config object to be inserted.
7682 * @return {Roo.Toolbar.Button/Item}
7684 insertButton : function(index, item){
7685 if(item instanceof Array){
7687 for(var i = 0, len = item.length; i < len; i++) {
7688 buttons.push(this.insertButton(index + i, item[i]));
7692 if (!(item instanceof Roo.Toolbar.Button)){
7693 item = new Roo.Toolbar.Button(item);
7695 var td = document.createElement("td");
7696 this.tr.insertBefore(td, this.tr.childNodes[index]);
7698 this.items.insert(index, item);
7703 * Adds a new element to the toolbar from the passed {@link Roo.DomHelper} config.
7704 * @param {Object} config
7705 * @return {Roo.Toolbar.Item} The element's item
7707 addDom : function(config, returnEl){
7708 var td = this.nextBlock();
7709 Roo.DomHelper.overwrite(td, config);
7710 var ti = new Roo.Toolbar.Item(td.firstChild);
7717 * Collection of fields on the toolbar.. usefull for quering (value is false if there are no fields)
7718 * @type Roo.util.MixedCollection
7723 * Adds a dynamically rendered Roo.form field (TextField, ComboBox, etc).
7724 * Note: the field should not have been rendered yet. For a field that has already been
7725 * rendered, use {@link #addElement}.
7726 * @param {Roo.form.Field} field
7727 * @return {Roo.ToolbarItem}
7731 addField : function(field) {
7734 this.fields = new Roo.util.MixedCollection(false, function(o){
7735 return o.id || ("item" + (++autoId));
7740 var td = this.nextBlock();
7742 var ti = new Roo.Toolbar.Item(td.firstChild);
7745 this.fields.add(field);
7756 this.el.child('div').setVisibilityMode(Roo.Element.DISPLAY);
7757 this.el.child('div').hide();
7765 this.el.child('div').show();
7769 nextBlock : function(){
7770 var td = document.createElement("td");
7771 this.tr.appendChild(td);
7776 destroy : function(){
7777 if(this.items){ // rendered?
7778 Roo.destroy.apply(Roo, this.items.items);
7780 if(this.fields){ // rendered?
7781 Roo.destroy.apply(Roo, this.fields.items);
7783 Roo.Element.uncache(this.el, this.tr);
7788 * @class Roo.Toolbar.Item
7789 * The base class that other classes should extend in order to get some basic common toolbar item functionality.
7791 * Creates a new Item
7792 * @param {HTMLElement} el
7794 Roo.Toolbar.Item = function(el){
7796 if (typeof (el.xtype) != 'undefined') {
7801 this.el = Roo.getDom(el);
7802 this.id = Roo.id(this.el);
7803 this.hidden = false;
7808 * Fires when the button is rendered
7809 * @param {Button} this
7813 Roo.Toolbar.Item.superclass.constructor.call(this,cfg);
7815 Roo.extend(Roo.Toolbar.Item, Roo.util.Observable, {
7816 //Roo.Toolbar.Item.prototype = {
7819 * Get this item's HTML Element
7820 * @return {HTMLElement}
7827 render : function(td){
7830 td.appendChild(this.el);
7832 this.fireEvent('render', this);
7836 * Removes and destroys this item.
7838 destroy : function(){
7839 this.td.parentNode.removeChild(this.td);
7846 this.hidden = false;
7847 this.td.style.display = "";
7855 this.td.style.display = "none";
7859 * Convenience function for boolean show/hide.
7860 * @param {Boolean} visible true to show/false to hide
7862 setVisible: function(visible){
7871 * Try to focus this item.
7874 Roo.fly(this.el).focus();
7878 * Disables this item.
7880 disable : function(){
7881 Roo.fly(this.td).addClass("x-item-disabled");
7882 this.disabled = true;
7883 this.el.disabled = true;
7887 * Enables this item.
7889 enable : function(){
7890 Roo.fly(this.td).removeClass("x-item-disabled");
7891 this.disabled = false;
7892 this.el.disabled = false;
7898 * @class Roo.Toolbar.Separator
7899 * @extends Roo.Toolbar.Item
7900 * A simple toolbar separator class
7902 * Creates a new Separator
7904 Roo.Toolbar.Separator = function(cfg){
7906 var s = document.createElement("span");
7907 s.className = "ytb-sep";
7912 Roo.Toolbar.Separator.superclass.constructor.call(this, cfg || s);
7914 Roo.extend(Roo.Toolbar.Separator, Roo.Toolbar.Item, {
7916 disable:Roo.emptyFn,
7921 * @class Roo.Toolbar.Spacer
7922 * @extends Roo.Toolbar.Item
7923 * A simple element that adds extra horizontal space to a toolbar.
7925 * Creates a new Spacer
7927 Roo.Toolbar.Spacer = function(cfg){
7928 var s = document.createElement("div");
7929 s.className = "ytb-spacer";
7933 Roo.Toolbar.Spacer.superclass.constructor.call(this, cfg || s);
7935 Roo.extend(Roo.Toolbar.Spacer, Roo.Toolbar.Item, {
7937 disable:Roo.emptyFn,
7942 * @class Roo.Toolbar.Fill
7943 * @extends Roo.Toolbar.Spacer
7944 * A simple element that adds a greedy (100% width) horizontal space to a toolbar.
7946 * Creates a new Spacer
7948 Roo.Toolbar.Fill = Roo.extend(Roo.Toolbar.Spacer, {
7950 render : function(td){
7951 td.style.width = '100%';
7952 Roo.Toolbar.Fill.superclass.render.call(this, td);
7957 * @class Roo.Toolbar.TextItem
7958 * @extends Roo.Toolbar.Item
7959 * A simple class that renders text directly into a toolbar.
7961 * Creates a new TextItem
7962 * @param {String} text
7964 Roo.Toolbar.TextItem = function(cfg){
7965 var text = cfg || "";
7966 if (typeof(cfg) == 'object') {
7967 text = cfg.text || "";
7971 var s = document.createElement("span");
7972 s.className = "ytb-text";
7978 Roo.Toolbar.TextItem.superclass.constructor.call(this, cfg || s);
7980 Roo.extend(Roo.Toolbar.TextItem, Roo.Toolbar.Item, {
7984 disable:Roo.emptyFn,
7989 * @class Roo.Toolbar.Button
7990 * @extends Roo.Button
7991 * A button that renders into a toolbar.
7993 * Creates a new Button
7994 * @param {Object} config A standard {@link Roo.Button} config object
7996 Roo.Toolbar.Button = function(config){
7997 Roo.Toolbar.Button.superclass.constructor.call(this, null, config);
7999 Roo.extend(Roo.Toolbar.Button, Roo.Button, {
8000 render : function(td){
8002 Roo.Toolbar.Button.superclass.render.call(this, td);
8006 * Removes and destroys this button
8008 destroy : function(){
8009 Roo.Toolbar.Button.superclass.destroy.call(this);
8010 this.td.parentNode.removeChild(this.td);
8017 this.hidden = false;
8018 this.td.style.display = "";
8026 this.td.style.display = "none";
8030 * Disables this item
8032 disable : function(){
8033 Roo.fly(this.td).addClass("x-item-disabled");
8034 this.disabled = true;
8040 enable : function(){
8041 Roo.fly(this.td).removeClass("x-item-disabled");
8042 this.disabled = false;
8046 Roo.ToolbarButton = Roo.Toolbar.Button;
8049 * @class Roo.Toolbar.SplitButton
8050 * @extends Roo.SplitButton
8051 * A menu button that renders into a toolbar.
8053 * Creates a new SplitButton
8054 * @param {Object} config A standard {@link Roo.SplitButton} config object
8056 Roo.Toolbar.SplitButton = function(config){
8057 Roo.Toolbar.SplitButton.superclass.constructor.call(this, null, config);
8059 Roo.extend(Roo.Toolbar.SplitButton, Roo.SplitButton, {
8060 render : function(td){
8062 Roo.Toolbar.SplitButton.superclass.render.call(this, td);
8066 * Removes and destroys this button
8068 destroy : function(){
8069 Roo.Toolbar.SplitButton.superclass.destroy.call(this);
8070 this.td.parentNode.removeChild(this.td);
8077 this.hidden = false;
8078 this.td.style.display = "";
8086 this.td.style.display = "none";
8091 Roo.Toolbar.MenuButton = Roo.Toolbar.SplitButton;/*
8093 * Ext JS Library 1.1.1
8094 * Copyright(c) 2006-2007, Ext JS, LLC.
8096 * Originally Released Under LGPL - original licence link has changed is not relivant.
8099 * <script type="text/javascript">
8103 * @class Roo.PagingToolbar
8104 * @extends Roo.Toolbar
8105 * A specialized toolbar that is bound to a {@link Roo.data.Store} and provides automatic paging controls.
8107 * Create a new PagingToolbar
8108 * @param {Object} config The config object
8110 Roo.PagingToolbar = function(el, ds, config)
8112 // old args format still supported... - xtype is prefered..
8113 if (typeof(el) == 'object' && el.xtype) {
8114 // created from xtype...
8117 el = config.container;
8121 items = config.items;
8125 Roo.PagingToolbar.superclass.constructor.call(this, el, null, config);
8128 this.renderButtons(this.el);
8131 // supprot items array.
8133 Roo.each(items, function(e) {
8134 this.add(Roo.factory(e));
8139 Roo.extend(Roo.PagingToolbar, Roo.Toolbar, {
8141 * @cfg {Roo.data.Store} dataSource
8142 * The underlying data store providing the paged data
8145 * @cfg {String/HTMLElement/Element} container
8146 * container The id or element that will contain the toolbar
8149 * @cfg {Boolean} displayInfo
8150 * True to display the displayMsg (defaults to false)
8153 * @cfg {Number} pageSize
8154 * The number of records to display per page (defaults to 20)
8158 * @cfg {String} displayMsg
8159 * The paging status message to display (defaults to "Displaying {start} - {end} of {total}")
8161 displayMsg : 'Displaying {0} - {1} of {2}',
8163 * @cfg {String} emptyMsg
8164 * The message to display when no records are found (defaults to "No data to display")
8166 emptyMsg : 'No data to display',
8168 * Customizable piece of the default paging text (defaults to "Page")
8171 beforePageText : "Page",
8173 * Customizable piece of the default paging text (defaults to "of %0")
8176 afterPageText : "of {0}",
8178 * Customizable piece of the default paging text (defaults to "First Page")
8181 firstText : "First Page",
8183 * Customizable piece of the default paging text (defaults to "Previous Page")
8186 prevText : "Previous Page",
8188 * Customizable piece of the default paging text (defaults to "Next Page")
8191 nextText : "Next Page",
8193 * Customizable piece of the default paging text (defaults to "Last Page")
8196 lastText : "Last Page",
8198 * Customizable piece of the default paging text (defaults to "Refresh")
8201 refreshText : "Refresh",
8204 renderButtons : function(el){
8205 Roo.PagingToolbar.superclass.render.call(this, el);
8206 this.first = this.addButton({
8207 tooltip: this.firstText,
8208 cls: "x-btn-icon x-grid-page-first",
8210 handler: this.onClick.createDelegate(this, ["first"])
8212 this.prev = this.addButton({
8213 tooltip: this.prevText,
8214 cls: "x-btn-icon x-grid-page-prev",
8216 handler: this.onClick.createDelegate(this, ["prev"])
8218 //this.addSeparator();
8219 this.add(this.beforePageText);
8220 this.field = Roo.get(this.addDom({
8225 cls: "x-grid-page-number"
8227 this.field.on("keydown", this.onPagingKeydown, this);
8228 this.field.on("focus", function(){this.dom.select();});
8229 this.afterTextEl = this.addText(String.format(this.afterPageText, 1));
8230 this.field.setHeight(18);
8231 //this.addSeparator();
8232 this.next = this.addButton({
8233 tooltip: this.nextText,
8234 cls: "x-btn-icon x-grid-page-next",
8236 handler: this.onClick.createDelegate(this, ["next"])
8238 this.last = this.addButton({
8239 tooltip: this.lastText,
8240 cls: "x-btn-icon x-grid-page-last",
8242 handler: this.onClick.createDelegate(this, ["last"])
8244 //this.addSeparator();
8245 this.loading = this.addButton({
8246 tooltip: this.refreshText,
8247 cls: "x-btn-icon x-grid-loading",
8248 handler: this.onClick.createDelegate(this, ["refresh"])
8251 if(this.displayInfo){
8252 this.displayEl = Roo.fly(this.el.dom.firstChild).createChild({cls:'x-paging-info'});
8257 updateInfo : function(){
8259 var count = this.ds.getCount();
8260 var msg = count == 0 ?
8264 this.cursor+1, this.cursor+count, this.ds.getTotalCount()
8266 this.displayEl.update(msg);
8271 onLoad : function(ds, r, o){
8272 this.cursor = o.params ? o.params.start : 0;
8273 var d = this.getPageData(), ap = d.activePage, ps = d.pages;
8275 this.afterTextEl.el.innerHTML = String.format(this.afterPageText, d.pages);
8276 this.field.dom.value = ap;
8277 this.first.setDisabled(ap == 1);
8278 this.prev.setDisabled(ap == 1);
8279 this.next.setDisabled(ap == ps);
8280 this.last.setDisabled(ap == ps);
8281 this.loading.enable();
8286 getPageData : function(){
8287 var total = this.ds.getTotalCount();
8290 activePage : Math.ceil((this.cursor+this.pageSize)/this.pageSize),
8291 pages : total < this.pageSize ? 1 : Math.ceil(total/this.pageSize)
8296 onLoadError : function(){
8297 this.loading.enable();
8301 onPagingKeydown : function(e){
8303 var d = this.getPageData();
8305 var v = this.field.dom.value, pageNum;
8306 if(!v || isNaN(pageNum = parseInt(v, 10))){
8307 this.field.dom.value = d.activePage;
8310 pageNum = Math.min(Math.max(1, pageNum), d.pages) - 1;
8311 this.ds.load({params:{start: pageNum * this.pageSize, limit: this.pageSize}});
8314 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))
8316 var pageNum = (k == e.HOME || (k == e.DOWN && e.ctrlKey) || (k == e.LEFT && e.ctrlKey) || (k == e.PAGEDOWN && e.ctrlKey)) ? 1 : d.pages;
8317 this.field.dom.value = pageNum;
8318 this.ds.load({params:{start: (pageNum - 1) * this.pageSize, limit: this.pageSize}});
8321 else if(k == e.UP || k == e.RIGHT || k == e.PAGEUP || k == e.DOWN || k == e.LEFT || k == e.PAGEDOWN)
8323 var v = this.field.dom.value, pageNum;
8324 var increment = (e.shiftKey) ? 10 : 1;
8325 if(k == e.DOWN || k == e.LEFT || k == e.PAGEDOWN) {
8328 if(!v || isNaN(pageNum = parseInt(v, 10))) {
8329 this.field.dom.value = d.activePage;
8332 else if(parseInt(v, 10) + increment >= 1 & parseInt(v, 10) + increment <= d.pages)
8334 this.field.dom.value = parseInt(v, 10) + increment;
8335 pageNum = Math.min(Math.max(1, pageNum + increment), d.pages) - 1;
8336 this.ds.load({params:{start: pageNum * this.pageSize, limit: this.pageSize}});
8343 beforeLoad : function(){
8345 this.loading.disable();
8350 onClick : function(which){
8354 ds.load({params:{start: 0, limit: this.pageSize}});
8357 ds.load({params:{start: Math.max(0, this.cursor-this.pageSize), limit: this.pageSize}});
8360 ds.load({params:{start: this.cursor+this.pageSize, limit: this.pageSize}});
8363 var total = ds.getTotalCount();
8364 var extra = total % this.pageSize;
8365 var lastStart = extra ? (total - extra) : total-this.pageSize;
8366 ds.load({params:{start: lastStart, limit: this.pageSize}});
8369 ds.load({params:{start: this.cursor, limit: this.pageSize}});
8375 * Unbinds the paging toolbar from the specified {@link Roo.data.Store}
8376 * @param {Roo.data.Store} store The data store to unbind
8378 unbind : function(ds){
8379 ds.un("beforeload", this.beforeLoad, this);
8380 ds.un("load", this.onLoad, this);
8381 ds.un("loadexception", this.onLoadError, this);
8382 ds.un("remove", this.updateInfo, this);
8383 ds.un("add", this.updateInfo, this);
8384 this.ds = undefined;
8388 * Binds the paging toolbar to the specified {@link Roo.data.Store}
8389 * @param {Roo.data.Store} store The data store to bind
8391 bind : function(ds){
8392 ds.on("beforeload", this.beforeLoad, this);
8393 ds.on("load", this.onLoad, this);
8394 ds.on("loadexception", this.onLoadError, this);
8395 ds.on("remove", this.updateInfo, this);
8396 ds.on("add", this.updateInfo, this);
8401 * Ext JS Library 1.1.1
8402 * Copyright(c) 2006-2007, Ext JS, LLC.
8404 * Originally Released Under LGPL - original licence link has changed is not relivant.
8407 * <script type="text/javascript">
8411 * @class Roo.Resizable
8412 * @extends Roo.util.Observable
8413 * <p>Applies drag handles to an element to make it resizable. The drag handles are inserted into the element
8414 * and positioned absolute. Some elements, such as a textarea or image, don't support this. To overcome that, you can wrap
8415 * 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
8416 * the element will be wrapped for you automatically.</p>
8417 * <p>Here is the list of valid resize handles:</p>
8420 ------ -------------------
8429 'hd' horizontal drag
8432 * <p>Here's an example showing the creation of a typical Resizable:</p>
8434 var resizer = new Roo.Resizable("element-id", {
8442 resizer.on("resize", myHandler);
8444 * <p>To hide a particular handle, set its display to none in CSS, or through script:<br>
8445 * resizer.east.setDisplayed(false);</p>
8446 * @cfg {Boolean/String/Element} resizeChild True to resize the first child, or id/element to resize (defaults to false)
8447 * @cfg {Array/String} adjustments String "auto" or an array [width, height] with values to be <b>added</b> to the
8448 * resize operation's new size (defaults to [0, 0])
8449 * @cfg {Number} minWidth The minimum width for the element (defaults to 5)
8450 * @cfg {Number} minHeight The minimum height for the element (defaults to 5)
8451 * @cfg {Number} maxWidth The maximum width for the element (defaults to 10000)
8452 * @cfg {Number} maxHeight The maximum height for the element (defaults to 10000)
8453 * @cfg {Boolean} enabled False to disable resizing (defaults to true)
8454 * @cfg {Boolean} wrap True to wrap an element with a div if needed (required for textareas and images, defaults to false)
8455 * @cfg {Number} width The width of the element in pixels (defaults to null)
8456 * @cfg {Number} height The height of the element in pixels (defaults to null)
8457 * @cfg {Boolean} animate True to animate the resize (not compatible with dynamic sizing, defaults to false)
8458 * @cfg {Number} duration Animation duration if animate = true (defaults to .35)
8459 * @cfg {Boolean} dynamic True to resize the element while dragging instead of using a proxy (defaults to false)
8460 * @cfg {String} handles String consisting of the resize handles to display (defaults to undefined)
8461 * @cfg {Boolean} multiDirectional <b>Deprecated</b>. The old style of adding multi-direction resize handles, deprecated
8462 * in favor of the handles config option (defaults to false)
8463 * @cfg {Boolean} disableTrackOver True to disable mouse tracking. This is only applied at config time. (defaults to false)
8464 * @cfg {String} easing Animation easing if animate = true (defaults to 'easingOutStrong')
8465 * @cfg {Number} widthIncrement The increment to snap the width resize in pixels (dynamic must be true, defaults to 0)
8466 * @cfg {Number} heightIncrement The increment to snap the height resize in pixels (dynamic must be true, defaults to 0)
8467 * @cfg {Boolean} pinned True to ensure that the resize handles are always visible, false to display them only when the
8468 * user mouses over the resizable borders. This is only applied at config time. (defaults to false)
8469 * @cfg {Boolean} preserveRatio True to preserve the original ratio between height and width during resize (defaults to false)
8470 * @cfg {Boolean} transparent True for transparent handles. This is only applied at config time. (defaults to false)
8471 * @cfg {Number} minX The minimum allowed page X for the element (only used for west resizing, defaults to 0)
8472 * @cfg {Number} minY The minimum allowed page Y for the element (only used for north resizing, defaults to 0)
8473 * @cfg {Boolean} draggable Convenience to initialize drag drop (defaults to false)
8475 * Create a new resizable component
8476 * @param {String/HTMLElement/Roo.Element} el The id or element to resize
8477 * @param {Object} config configuration options
8479 Roo.Resizable = function(el, config)
8481 this.el = Roo.get(el);
8483 if(config && config.wrap){
8484 config.resizeChild = this.el;
8485 this.el = this.el.wrap(typeof config.wrap == "object" ? config.wrap : {cls:"xresizable-wrap"});
8486 this.el.id = this.el.dom.id = config.resizeChild.id + "-rzwrap";
8487 this.el.setStyle("overflow", "hidden");
8488 this.el.setPositioning(config.resizeChild.getPositioning());
8489 config.resizeChild.clearPositioning();
8490 if(!config.width || !config.height){
8491 var csize = config.resizeChild.getSize();
8492 this.el.setSize(csize.width, csize.height);
8494 if(config.pinned && !config.adjustments){
8495 config.adjustments = "auto";
8499 this.proxy = this.el.createProxy({tag: "div", cls: "x-resizable-proxy", id: this.el.id + "-rzproxy"});
8500 this.proxy.unselectable();
8501 this.proxy.enableDisplayMode('block');
8503 Roo.apply(this, config);
8506 this.disableTrackOver = true;
8507 this.el.addClass("x-resizable-pinned");
8509 // if the element isn't positioned, make it relative
8510 var position = this.el.getStyle("position");
8511 if(position != "absolute" && position != "fixed"){
8512 this.el.setStyle("position", "relative");
8514 if(!this.handles){ // no handles passed, must be legacy style
8515 this.handles = 's,e,se';
8516 if(this.multiDirectional){
8517 this.handles += ',n,w';
8520 if(this.handles == "all"){
8521 this.handles = "n s e w ne nw se sw";
8523 var hs = this.handles.split(/\s*?[,;]\s*?| /);
8524 var ps = Roo.Resizable.positions;
8525 for(var i = 0, len = hs.length; i < len; i++){
8526 if(hs[i] && ps[hs[i]]){
8527 var pos = ps[hs[i]];
8528 this[pos] = new Roo.Resizable.Handle(this, pos, this.disableTrackOver, this.transparent);
8532 this.corner = this.southeast;
8534 // updateBox = the box can move..
8535 if(this.handles.indexOf("n") != -1 || this.handles.indexOf("w") != -1 || this.handles.indexOf("hd") != -1) {
8536 this.updateBox = true;
8539 this.activeHandle = null;
8541 if(this.resizeChild){
8542 if(typeof this.resizeChild == "boolean"){
8543 this.resizeChild = Roo.get(this.el.dom.firstChild, true);
8545 this.resizeChild = Roo.get(this.resizeChild, true);
8549 if(this.adjustments == "auto"){
8550 var rc = this.resizeChild;
8551 var hw = this.west, he = this.east, hn = this.north, hs = this.south;
8552 if(rc && (hw || hn)){
8553 rc.position("relative");
8554 rc.setLeft(hw ? hw.el.getWidth() : 0);
8555 rc.setTop(hn ? hn.el.getHeight() : 0);
8557 this.adjustments = [
8558 (he ? -he.el.getWidth() : 0) + (hw ? -hw.el.getWidth() : 0),
8559 (hn ? -hn.el.getHeight() : 0) + (hs ? -hs.el.getHeight() : 0) -1
8564 this.dd = this.dynamic ?
8565 this.el.initDD(null) : this.el.initDDProxy(null, {dragElId: this.proxy.id});
8566 this.dd.setHandleElId(this.resizeChild ? this.resizeChild.id : this.el.id);
8572 * @event beforeresize
8573 * Fired before resize is allowed. Set enabled to false to cancel resize.
8574 * @param {Roo.Resizable} this
8575 * @param {Roo.EventObject} e The mousedown event
8577 "beforeresize" : true,
8581 * @param {Roo.Resizable} this
8582 * @param {Number} x The new x position
8583 * @param {Number} y The new y position
8584 * @param {Number} w The new w width
8585 * @param {Number} h The new h hight
8586 * @param {Roo.EventObject} e The mouseup event
8591 * Fired after a resize.
8592 * @param {Roo.Resizable} this
8593 * @param {Number} width The new width
8594 * @param {Number} height The new height
8595 * @param {Roo.EventObject} e The mouseup event
8600 if(this.width !== null && this.height !== null){
8601 this.resizeTo(this.width, this.height);
8603 this.updateChildSize();
8606 this.el.dom.style.zoom = 1;
8608 Roo.Resizable.superclass.constructor.call(this);
8611 Roo.extend(Roo.Resizable, Roo.util.Observable, {
8612 resizeChild : false,
8613 adjustments : [0, 0],
8623 multiDirectional : false,
8624 disableTrackOver : false,
8625 easing : 'easeOutStrong',
8627 heightIncrement : 0,
8631 preserveRatio : false,
8638 * @cfg {String/HTMLElement/Element} constrainTo Constrain the resize to a particular element
8640 constrainTo: undefined,
8642 * @cfg {Roo.lib.Region} resizeRegion Constrain the resize to a particular region
8644 resizeRegion: undefined,
8648 * Perform a manual resize
8649 * @param {Number} width
8650 * @param {Number} height
8652 resizeTo : function(width, height){
8653 this.el.setSize(width, height);
8654 this.updateChildSize();
8655 this.fireEvent("resize", this, width, height, null);
8659 startSizing : function(e, handle){
8660 this.fireEvent("beforeresize", this, e);
8661 if(this.enabled){ // 2nd enabled check in case disabled before beforeresize handler
8664 this.overlay = this.el.createProxy({tag: "div", cls: "x-resizable-overlay", html: " "});
8665 this.overlay.unselectable();
8666 this.overlay.enableDisplayMode("block");
8667 this.overlay.on("mousemove", this.onMouseMove, this);
8668 this.overlay.on("mouseup", this.onMouseUp, this);
8670 this.overlay.setStyle("cursor", handle.el.getStyle("cursor"));
8672 this.resizing = true;
8673 this.startBox = this.el.getBox();
8674 this.startPoint = e.getXY();
8675 this.offsets = [(this.startBox.x + this.startBox.width) - this.startPoint[0],
8676 (this.startBox.y + this.startBox.height) - this.startPoint[1]];
8678 this.overlay.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
8679 this.overlay.show();
8681 if(this.constrainTo) {
8682 var ct = Roo.get(this.constrainTo);
8683 this.resizeRegion = ct.getRegion().adjust(
8684 ct.getFrameWidth('t'),
8685 ct.getFrameWidth('l'),
8686 -ct.getFrameWidth('b'),
8687 -ct.getFrameWidth('r')
8691 this.proxy.setStyle('visibility', 'hidden'); // workaround display none
8693 this.proxy.setBox(this.startBox);
8695 this.proxy.setStyle('visibility', 'visible');
8701 onMouseDown : function(handle, e){
8704 this.activeHandle = handle;
8705 this.startSizing(e, handle);
8710 onMouseUp : function(e){
8711 var size = this.resizeElement();
8712 this.resizing = false;
8714 this.overlay.hide();
8716 this.fireEvent("resize", this, size.width, size.height, e);
8720 updateChildSize : function(){
8722 if(this.resizeChild){
8724 var child = this.resizeChild;
8725 var adj = this.adjustments;
8726 if(el.dom.offsetWidth){
8727 var b = el.getSize(true);
8728 child.setSize(b.width+adj[0], b.height+adj[1]);
8730 // Second call here for IE
8731 // The first call enables instant resizing and
8732 // the second call corrects scroll bars if they
8735 setTimeout(function(){
8736 if(el.dom.offsetWidth){
8737 var b = el.getSize(true);
8738 child.setSize(b.width+adj[0], b.height+adj[1]);
8746 snap : function(value, inc, min){
8747 if(!inc || !value) {
8750 var newValue = value;
8751 var m = value % inc;
8754 newValue = value + (inc-m);
8756 newValue = value - m;
8759 return Math.max(min, newValue);
8763 resizeElement : function(){
8764 var box = this.proxy.getBox();
8766 this.el.setBox(box, false, this.animate, this.duration, null, this.easing);
8768 this.el.setSize(box.width, box.height, this.animate, this.duration, null, this.easing);
8770 this.updateChildSize();
8778 constrain : function(v, diff, m, mx){
8781 }else if(v - diff > mx){
8788 onMouseMove : function(e){
8791 try{// try catch so if something goes wrong the user doesn't get hung
8793 if(this.resizeRegion && !this.resizeRegion.contains(e.getPoint())) {
8797 //var curXY = this.startPoint;
8798 var curSize = this.curSize || this.startBox;
8799 var x = this.startBox.x, y = this.startBox.y;
8801 var w = curSize.width, h = curSize.height;
8803 var mw = this.minWidth, mh = this.minHeight;
8804 var mxw = this.maxWidth, mxh = this.maxHeight;
8805 var wi = this.widthIncrement;
8806 var hi = this.heightIncrement;
8808 var eventXY = e.getXY();
8809 var diffX = -(this.startPoint[0] - Math.max(this.minX, eventXY[0]));
8810 var diffY = -(this.startPoint[1] - Math.max(this.minY, eventXY[1]));
8812 var pos = this.activeHandle.position;
8817 w = Math.min(Math.max(mw, w), mxw);
8822 h = Math.min(Math.max(mh, h), mxh);
8827 w = Math.min(Math.max(mw, w), mxw);
8828 h = Math.min(Math.max(mh, h), mxh);
8831 diffY = this.constrain(h, diffY, mh, mxh);
8838 var adiffX = Math.abs(diffX);
8839 var sub = (adiffX % wi); // how much
8840 if (sub > (wi/2)) { // far enough to snap
8841 diffX = (diffX > 0) ? diffX-sub + wi : diffX+sub - wi;
8843 // remove difference..
8844 diffX = (diffX > 0) ? diffX-sub : diffX+sub;
8848 x = Math.max(this.minX, x);
8851 diffX = this.constrain(w, diffX, mw, mxw);
8857 w = Math.min(Math.max(mw, w), mxw);
8858 diffY = this.constrain(h, diffY, mh, mxh);
8863 diffX = this.constrain(w, diffX, mw, mxw);
8864 diffY = this.constrain(h, diffY, mh, mxh);
8871 diffX = this.constrain(w, diffX, mw, mxw);
8873 h = Math.min(Math.max(mh, h), mxh);
8879 var sw = this.snap(w, wi, mw);
8880 var sh = this.snap(h, hi, mh);
8881 if(sw != w || sh != h){
8904 if(this.preserveRatio){
8909 h = Math.min(Math.max(mh, h), mxh);
8914 w = Math.min(Math.max(mw, w), mxw);
8919 w = Math.min(Math.max(mw, w), mxw);
8925 w = Math.min(Math.max(mw, w), mxw);
8931 h = Math.min(Math.max(mh, h), mxh);
8939 h = Math.min(Math.max(mh, h), mxh);
8949 h = Math.min(Math.max(mh, h), mxh);
8957 if (pos == 'hdrag') {
8960 this.proxy.setBounds(x, y, w, h);
8962 this.resizeElement();
8966 this.fireEvent("resizing", this, x, y, w, h, e);
8970 handleOver : function(){
8972 this.el.addClass("x-resizable-over");
8977 handleOut : function(){
8979 this.el.removeClass("x-resizable-over");
8984 * Returns the element this component is bound to.
8985 * @return {Roo.Element}
8992 * Returns the resizeChild element (or null).
8993 * @return {Roo.Element}
8995 getResizeChild : function(){
8996 return this.resizeChild;
8998 groupHandler : function()
9003 * Destroys this resizable. If the element was wrapped and
9004 * removeEl is not true then the element remains.
9005 * @param {Boolean} removeEl (optional) true to remove the element from the DOM
9007 destroy : function(removeEl){
9008 this.proxy.remove();
9010 this.overlay.removeAllListeners();
9011 this.overlay.remove();
9013 var ps = Roo.Resizable.positions;
9015 if(typeof ps[k] != "function" && this[ps[k]]){
9016 var h = this[ps[k]];
9017 h.el.removeAllListeners();
9029 // hash to map config positions to true positions
9030 Roo.Resizable.positions = {
9031 n: "north", s: "south", e: "east", w: "west", se: "southeast", sw: "southwest", nw: "northwest", ne: "northeast",
9036 Roo.Resizable.Handle = function(rz, pos, disableTrackOver, transparent){
9038 // only initialize the template if resizable is used
9039 var tpl = Roo.DomHelper.createTemplate(
9040 {tag: "div", cls: "x-resizable-handle x-resizable-handle-{0}"}
9043 Roo.Resizable.Handle.prototype.tpl = tpl;
9045 this.position = pos;
9047 // show north drag fro topdra
9048 var handlepos = pos == 'hdrag' ? 'north' : pos;
9050 this.el = this.tpl.append(rz.el.dom, [handlepos], true);
9051 if (pos == 'hdrag') {
9052 this.el.setStyle('cursor', 'pointer');
9054 this.el.unselectable();
9056 this.el.setOpacity(0);
9058 this.el.on("mousedown", this.onMouseDown, this);
9059 if(!disableTrackOver){
9060 this.el.on("mouseover", this.onMouseOver, this);
9061 this.el.on("mouseout", this.onMouseOut, this);
9066 Roo.Resizable.Handle.prototype = {
9067 afterResize : function(rz){
9072 onMouseDown : function(e){
9073 this.rz.onMouseDown(this, e);
9076 onMouseOver : function(e){
9077 this.rz.handleOver(this, e);
9080 onMouseOut : function(e){
9081 this.rz.handleOut(this, e);
9085 * Ext JS Library 1.1.1
9086 * Copyright(c) 2006-2007, Ext JS, LLC.
9088 * Originally Released Under LGPL - original licence link has changed is not relivant.
9091 * <script type="text/javascript">
9096 * @extends Roo.Component
9097 * A base editor field that handles displaying/hiding on demand and has some built-in sizing and event handling logic.
9099 * Create a new Editor
9100 * @param {Roo.form.Field} field The Field object (or descendant)
9101 * @param {Object} config The config object
9103 Roo.Editor = function(field, config){
9104 Roo.Editor.superclass.constructor.call(this, config);
9108 * @event beforestartedit
9109 * Fires when editing is initiated, but before the value changes. Editing can be canceled by returning
9110 * false from the handler of this event.
9111 * @param {Editor} this
9112 * @param {Roo.Element} boundEl The underlying element bound to this editor
9113 * @param {Mixed} value The field value being set
9115 "beforestartedit" : true,
9118 * Fires when this editor is displayed
9119 * @param {Roo.Element} boundEl The underlying element bound to this editor
9120 * @param {Mixed} value The starting field value
9124 * @event beforecomplete
9125 * Fires after a change has been made to the field, but before the change is reflected in the underlying
9126 * field. Saving the change to the field can be canceled by returning false from the handler of this event.
9127 * Note that if the value has not changed and ignoreNoChange = true, the editing will still end but this
9128 * event will not fire since no edit actually occurred.
9129 * @param {Editor} this
9130 * @param {Mixed} value The current field value
9131 * @param {Mixed} startValue The original field value
9133 "beforecomplete" : true,
9136 * Fires after editing is complete and any changed value has been written to the underlying field.
9137 * @param {Editor} this
9138 * @param {Mixed} value The current field value
9139 * @param {Mixed} startValue The original field value
9144 * Fires when any key related to navigation (arrows, tab, enter, esc, etc.) is pressed. You can check
9145 * {@link Roo.EventObject#getKey} to determine which key was pressed.
9146 * @param {Roo.form.Field} this
9147 * @param {Roo.EventObject} e The event object
9153 Roo.extend(Roo.Editor, Roo.Component, {
9155 * @cfg {Boolean/String} autosize
9156 * True for the editor to automatically adopt the size of the underlying field, "width" to adopt the width only,
9157 * or "height" to adopt the height only (defaults to false)
9160 * @cfg {Boolean} revertInvalid
9161 * True to automatically revert the field value and cancel the edit when the user completes an edit and the field
9162 * validation fails (defaults to true)
9165 * @cfg {Boolean} ignoreNoChange
9166 * True to skip the the edit completion process (no save, no events fired) if the user completes an edit and
9167 * the value has not changed (defaults to false). Applies only to string values - edits for other data types
9168 * will never be ignored.
9171 * @cfg {Boolean} hideEl
9172 * False to keep the bound element visible while the editor is displayed (defaults to true)
9175 * @cfg {Mixed} value
9176 * The data value of the underlying field (defaults to "")
9180 * @cfg {String} alignment
9181 * The position to align to (see {@link Roo.Element#alignTo} for more details, defaults to "c-c?").
9185 * @cfg {Boolean/String} shadow "sides" for sides/bottom only, "frame" for 4-way shadow, and "drop"
9186 * for bottom-right shadow (defaults to "frame")
9190 * @cfg {Boolean} constrain True to constrain the editor to the viewport
9194 * @cfg {Boolean} completeOnEnter True to complete the edit when the enter key is pressed (defaults to false)
9196 completeOnEnter : false,
9198 * @cfg {Boolean} cancelOnEsc True to cancel the edit when the escape key is pressed (defaults to false)
9200 cancelOnEsc : false,
9202 * @cfg {Boolean} updateEl True to update the innerHTML of the bound element when the update completes (defaults to false)
9207 onRender : function(ct, position){
9208 this.el = new Roo.Layer({
9209 shadow: this.shadow,
9215 constrain: this.constrain
9217 this.el.setStyle("overflow", Roo.isGecko ? "auto" : "hidden");
9218 if(this.field.msgTarget != 'title'){
9219 this.field.msgTarget = 'qtip';
9221 this.field.render(this.el);
9223 this.field.el.dom.setAttribute('autocomplete', 'off');
9225 this.field.on("specialkey", this.onSpecialKey, this);
9226 if(this.swallowKeys){
9227 this.field.el.swallowEvent(['keydown','keypress']);
9230 this.field.on("blur", this.onBlur, this);
9231 if(this.field.grow){
9232 this.field.on("autosize", this.el.sync, this.el, {delay:1});
9236 onSpecialKey : function(field, e)
9238 //Roo.log('editor onSpecialKey');
9239 if(this.completeOnEnter && e.getKey() == e.ENTER){
9241 this.completeEdit();
9244 // do not fire special key otherwise it might hide close the editor...
9245 if(e.getKey() == e.ENTER){
9248 if(this.cancelOnEsc && e.getKey() == e.ESC){
9252 this.fireEvent('specialkey', field, e);
9257 * Starts the editing process and shows the editor.
9258 * @param {String/HTMLElement/Element} el The element to edit
9259 * @param {String} value (optional) A value to initialize the editor with. If a value is not provided, it defaults
9260 * to the innerHTML of el.
9262 startEdit : function(el, value){
9264 this.completeEdit();
9266 this.boundEl = Roo.get(el);
9267 var v = value !== undefined ? value : this.boundEl.dom.innerHTML;
9269 this.render(this.parentEl || document.body);
9271 if(this.fireEvent("beforestartedit", this, this.boundEl, v) === false){
9274 this.startValue = v;
9275 this.field.setValue(v);
9277 var sz = this.boundEl.getSize();
9278 switch(this.autoSize){
9280 this.setSize(sz.width, "");
9283 this.setSize("", sz.height);
9286 this.setSize(sz.width, sz.height);
9289 this.el.alignTo(this.boundEl, this.alignment);
9290 this.editing = true;
9292 Roo.QuickTips.disable();
9298 * Sets the height and width of this editor.
9299 * @param {Number} width The new width
9300 * @param {Number} height The new height
9302 setSize : function(w, h){
9303 this.field.setSize(w, h);
9310 * Realigns the editor to the bound field based on the current alignment config value.
9312 realign : function(){
9313 this.el.alignTo(this.boundEl, this.alignment);
9317 * Ends the editing process, persists the changed value to the underlying field, and hides the editor.
9318 * @param {Boolean} remainVisible Override the default behavior and keep the editor visible after edit (defaults to false)
9320 completeEdit : function(remainVisible){
9324 var v = this.getValue();
9325 if(this.revertInvalid !== false && !this.field.isValid()){
9326 v = this.startValue;
9327 this.cancelEdit(true);
9329 if(String(v) === String(this.startValue) && this.ignoreNoChange){
9330 this.editing = false;
9334 if(this.fireEvent("beforecomplete", this, v, this.startValue) !== false){
9335 this.editing = false;
9336 if(this.updateEl && this.boundEl){
9337 this.boundEl.update(v);
9339 if(remainVisible !== true){
9342 this.fireEvent("complete", this, v, this.startValue);
9347 onShow : function(){
9349 if(this.hideEl !== false){
9350 this.boundEl.hide();
9353 if(Roo.isIE && !this.fixIEFocus){ // IE has problems with focusing the first time
9354 this.fixIEFocus = true;
9355 this.deferredFocus.defer(50, this);
9359 this.fireEvent("startedit", this.boundEl, this.startValue);
9362 deferredFocus : function(){
9369 * Cancels the editing process and hides the editor without persisting any changes. The field value will be
9370 * reverted to the original starting value.
9371 * @param {Boolean} remainVisible Override the default behavior and keep the editor visible after
9372 * cancel (defaults to false)
9374 cancelEdit : function(remainVisible){
9376 this.setValue(this.startValue);
9377 if(remainVisible !== true){
9384 onBlur : function(){
9385 if(this.allowBlur !== true && this.editing){
9386 this.completeEdit();
9391 onHide : function(){
9393 this.completeEdit();
9397 if(this.field.collapse){
9398 this.field.collapse();
9401 if(this.hideEl !== false){
9402 this.boundEl.show();
9405 Roo.QuickTips.enable();
9410 * Sets the data value of the editor
9411 * @param {Mixed} value Any valid value supported by the underlying field
9413 setValue : function(v){
9414 this.field.setValue(v);
9418 * Gets the data value of the editor
9419 * @return {Mixed} The data value
9421 getValue : function(){
9422 return this.field.getValue();
9426 * Ext JS Library 1.1.1
9427 * Copyright(c) 2006-2007, Ext JS, LLC.
9429 * Originally Released Under LGPL - original licence link has changed is not relivant.
9432 * <script type="text/javascript">
9436 * @class Roo.BasicDialog
9437 * @extends Roo.util.Observable
9438 * Lightweight Dialog Class. The code below shows the creation of a typical dialog using existing HTML markup:
9440 var dlg = new Roo.BasicDialog("my-dlg", {
9449 dlg.addKeyListener(27, dlg.hide, dlg); // ESC can also close the dialog
9450 dlg.addButton('OK', dlg.hide, dlg); // Could call a save function instead of hiding
9451 dlg.addButton('Cancel', dlg.hide, dlg);
9454 <b>A Dialog should always be a direct child of the body element.</b>
9455 * @cfg {Boolean/DomHelper} autoCreate True to auto create from scratch, or using a DomHelper Object (defaults to false)
9456 * @cfg {String} title Default text to display in the title bar (defaults to null)
9457 * @cfg {Number} width Width of the dialog in pixels (can also be set via CSS). Determined by browser if unspecified.
9458 * @cfg {Number} height Height of the dialog in pixels (can also be set via CSS). Determined by browser if unspecified.
9459 * @cfg {Number} x The default left page coordinate of the dialog (defaults to center screen)
9460 * @cfg {Number} y The default top page coordinate of the dialog (defaults to center screen)
9461 * @cfg {String/Element} animateTarget Id or element from which the dialog should animate while opening
9462 * (defaults to null with no animation)
9463 * @cfg {Boolean} resizable False to disable manual dialog resizing (defaults to true)
9464 * @cfg {String} resizeHandles Which resize handles to display - see the {@link Roo.Resizable} handles config
9465 * property for valid values (defaults to 'all')
9466 * @cfg {Number} minHeight The minimum allowable height for a resizable dialog (defaults to 80)
9467 * @cfg {Number} minWidth The minimum allowable width for a resizable dialog (defaults to 200)
9468 * @cfg {Boolean} modal True to show the dialog modally, preventing user interaction with the rest of the page (defaults to false)
9469 * @cfg {Boolean} autoScroll True to allow the dialog body contents to overflow and display scrollbars (defaults to false)
9470 * @cfg {Boolean} closable False to remove the built-in top-right corner close button (defaults to true)
9471 * @cfg {Boolean} collapsible False to remove the built-in top-right corner collapse button (defaults to true)
9472 * @cfg {Boolean} constraintoviewport True to keep the dialog constrained within the visible viewport boundaries (defaults to true)
9473 * @cfg {Boolean} syncHeightBeforeShow True to cause the dimensions to be recalculated before the dialog is shown (defaults to false)
9474 * @cfg {Boolean} draggable False to disable dragging of the dialog within the viewport (defaults to true)
9475 * @cfg {Boolean} autoTabs If true, all elements with class 'x-dlg-tab' will get automatically converted to tabs (defaults to false)
9476 * @cfg {String} tabTag The tag name of tab elements, used when autoTabs = true (defaults to 'div')
9477 * @cfg {Boolean} proxyDrag True to drag a lightweight proxy element rather than the dialog itself, used when
9478 * draggable = true (defaults to false)
9479 * @cfg {Boolean} fixedcenter True to ensure that anytime the dialog is shown or resized it gets centered (defaults to false)
9480 * @cfg {Boolean/String} shadow True or "sides" for the default effect, "frame" for 4-way shadow, and "drop" for bottom-right
9481 * shadow (defaults to false)
9482 * @cfg {Number} shadowOffset The number of pixels to offset the shadow if displayed (defaults to 5)
9483 * @cfg {String} buttonAlign Valid values are "left," "center" and "right" (defaults to "right")
9484 * @cfg {Number} minButtonWidth Minimum width of all dialog buttons (defaults to 75)
9485 * @cfg {Array} buttons Array of buttons
9486 * @cfg {Boolean} shim True to create an iframe shim that prevents selects from showing through (defaults to false)
9488 * Create a new BasicDialog.
9489 * @param {String/HTMLElement/Roo.Element} el The container element or DOM node, or its id
9490 * @param {Object} config Configuration options
9492 Roo.BasicDialog = function(el, config){
9493 this.el = Roo.get(el);
9494 var dh = Roo.DomHelper;
9495 if(!this.el && config && config.autoCreate){
9496 if(typeof config.autoCreate == "object"){
9497 if(!config.autoCreate.id){
9498 config.autoCreate.id = el;
9500 this.el = dh.append(document.body,
9501 config.autoCreate, true);
9503 this.el = dh.append(document.body,
9504 {tag: "div", id: el, style:'visibility:hidden;'}, true);
9508 el.setDisplayed(true);
9509 el.hide = this.hideAction;
9511 el.addClass("x-dlg");
9513 Roo.apply(this, config);
9515 this.proxy = el.createProxy("x-dlg-proxy");
9516 this.proxy.hide = this.hideAction;
9517 this.proxy.setOpacity(.5);
9521 el.setWidth(config.width);
9524 el.setHeight(config.height);
9526 this.size = el.getSize();
9527 if(typeof config.x != "undefined" && typeof config.y != "undefined"){
9528 this.xy = [config.x,config.y];
9530 this.xy = el.getCenterXY(true);
9532 /** The header element @type Roo.Element */
9533 this.header = el.child("> .x-dlg-hd");
9534 /** The body element @type Roo.Element */
9535 this.body = el.child("> .x-dlg-bd");
9536 /** The footer element @type Roo.Element */
9537 this.footer = el.child("> .x-dlg-ft");
9540 this.header = el.createChild({tag: "div", cls:"x-dlg-hd", html: " "}, this.body ? this.body.dom : null);
9543 this.body = el.createChild({tag: "div", cls:"x-dlg-bd"});
9546 this.header.unselectable();
9548 this.header.update(this.title);
9550 // this element allows the dialog to be focused for keyboard event
9551 this.focusEl = el.createChild({tag: "a", href:"#", cls:"x-dlg-focus", tabIndex:"-1"});
9552 this.focusEl.swallowEvent("click", true);
9554 this.header.wrap({cls:"x-dlg-hd-right"}).wrap({cls:"x-dlg-hd-left"}, true);
9556 // wrap the body and footer for special rendering
9557 this.bwrap = this.body.wrap({tag: "div", cls:"x-dlg-dlg-body"});
9559 this.bwrap.dom.appendChild(this.footer.dom);
9562 this.bg = this.el.createChild({
9563 tag: "div", cls:"x-dlg-bg",
9564 html: '<div class="x-dlg-bg-left"><div class="x-dlg-bg-right"><div class="x-dlg-bg-center"> </div></div></div>'
9566 this.centerBg = this.bg.child("div.x-dlg-bg-center");
9569 if(this.autoScroll !== false && !this.autoTabs){
9570 this.body.setStyle("overflow", "auto");
9573 this.toolbox = this.el.createChild({cls: "x-dlg-toolbox"});
9575 if(this.closable !== false){
9576 this.el.addClass("x-dlg-closable");
9577 this.close = this.toolbox.createChild({cls:"x-dlg-close"});
9578 this.close.on("click", this.closeClick, this);
9579 this.close.addClassOnOver("x-dlg-close-over");
9581 if(this.collapsible !== false){
9582 this.collapseBtn = this.toolbox.createChild({cls:"x-dlg-collapse"});
9583 this.collapseBtn.on("click", this.collapseClick, this);
9584 this.collapseBtn.addClassOnOver("x-dlg-collapse-over");
9585 this.header.on("dblclick", this.collapseClick, this);
9587 if(this.resizable !== false){
9588 this.el.addClass("x-dlg-resizable");
9589 this.resizer = new Roo.Resizable(el, {
9590 minWidth: this.minWidth || 80,
9591 minHeight:this.minHeight || 80,
9592 handles: this.resizeHandles || "all",
9595 this.resizer.on("beforeresize", this.beforeResize, this);
9596 this.resizer.on("resize", this.onResize, this);
9598 if(this.draggable !== false){
9599 el.addClass("x-dlg-draggable");
9600 if (!this.proxyDrag) {
9601 var dd = new Roo.dd.DD(el.dom.id, "WindowDrag");
9604 var dd = new Roo.dd.DDProxy(el.dom.id, "WindowDrag", {dragElId: this.proxy.id});
9606 dd.setHandleElId(this.header.id);
9607 dd.endDrag = this.endMove.createDelegate(this);
9608 dd.startDrag = this.startMove.createDelegate(this);
9609 dd.onDrag = this.onDrag.createDelegate(this);
9614 this.mask = dh.append(document.body, {tag: "div", cls:"x-dlg-mask"}, true);
9615 this.mask.enableDisplayMode("block");
9617 this.el.addClass("x-dlg-modal");
9620 this.shadow = new Roo.Shadow({
9621 mode : typeof this.shadow == "string" ? this.shadow : "sides",
9622 offset : this.shadowOffset
9625 this.shadowOffset = 0;
9627 if(Roo.useShims && this.shim !== false){
9628 this.shim = this.el.createShim();
9629 this.shim.hide = this.hideAction;
9638 var bts= this.buttons;
9640 Roo.each(bts, function(b) {
9649 * Fires when a key is pressed
9650 * @param {Roo.BasicDialog} this
9651 * @param {Roo.EventObject} e
9656 * Fires when this dialog is moved by the user.
9657 * @param {Roo.BasicDialog} this
9658 * @param {Number} x The new page X
9659 * @param {Number} y The new page Y
9664 * Fires when this dialog is resized by the user.
9665 * @param {Roo.BasicDialog} this
9666 * @param {Number} width The new width
9667 * @param {Number} height The new height
9672 * Fires before this dialog is hidden.
9673 * @param {Roo.BasicDialog} this
9675 "beforehide" : true,
9678 * Fires when this dialog is hidden.
9679 * @param {Roo.BasicDialog} this
9684 * Fires before this dialog is shown.
9685 * @param {Roo.BasicDialog} this
9687 "beforeshow" : true,
9690 * Fires when this dialog is shown.
9691 * @param {Roo.BasicDialog} this
9695 el.on("keydown", this.onKeyDown, this);
9696 el.on("mousedown", this.toFront, this);
9697 Roo.EventManager.onWindowResize(this.adjustViewport, this, true);
9699 Roo.DialogManager.register(this);
9700 Roo.BasicDialog.superclass.constructor.call(this);
9703 Roo.extend(Roo.BasicDialog, Roo.util.Observable, {
9704 shadowOffset: Roo.isIE ? 6 : 5,
9708 defaultButton: null,
9709 buttonAlign: "right",
9714 * Sets the dialog title text
9715 * @param {String} text The title text to display
9716 * @return {Roo.BasicDialog} this
9718 setTitle : function(text){
9719 this.header.update(text);
9724 closeClick : function(){
9729 collapseClick : function(){
9730 this[this.collapsed ? "expand" : "collapse"]();
9734 * Collapses the dialog to its minimized state (only the title bar is visible).
9735 * Equivalent to the user clicking the collapse dialog button.
9737 collapse : function(){
9738 if(!this.collapsed){
9739 this.collapsed = true;
9740 this.el.addClass("x-dlg-collapsed");
9741 this.restoreHeight = this.el.getHeight();
9742 this.resizeTo(this.el.getWidth(), this.header.getHeight());
9747 * Expands a collapsed dialog back to its normal state. Equivalent to the user
9748 * clicking the expand dialog button.
9750 expand : function(){
9752 this.collapsed = false;
9753 this.el.removeClass("x-dlg-collapsed");
9754 this.resizeTo(this.el.getWidth(), this.restoreHeight);
9759 * Reinitializes the tabs component, clearing out old tabs and finding new ones.
9760 * @return {Roo.TabPanel} The tabs component
9762 initTabs : function(){
9763 var tabs = this.getTabs();
9764 while(tabs.getTab(0)){
9767 this.el.select(this.tabTag+'.x-dlg-tab').each(function(el){
9769 tabs.addTab(Roo.id(dom), dom.title);
9777 beforeResize : function(){
9778 this.resizer.minHeight = Math.max(this.minHeight, this.getHeaderFooterHeight(true)+40);
9782 onResize : function(){
9784 this.syncBodyHeight();
9785 this.adjustAssets();
9787 this.fireEvent("resize", this, this.size.width, this.size.height);
9791 onKeyDown : function(e){
9792 if(this.isVisible()){
9793 this.fireEvent("keydown", this, e);
9798 * Resizes the dialog.
9799 * @param {Number} width
9800 * @param {Number} height
9801 * @return {Roo.BasicDialog} this
9803 resizeTo : function(width, height){
9804 this.el.setSize(width, height);
9805 this.size = {width: width, height: height};
9806 this.syncBodyHeight();
9807 if(this.fixedcenter){
9810 if(this.isVisible()){
9812 this.adjustAssets();
9814 this.fireEvent("resize", this, width, height);
9820 * Resizes the dialog to fit the specified content size.
9821 * @param {Number} width
9822 * @param {Number} height
9823 * @return {Roo.BasicDialog} this
9825 setContentSize : function(w, h){
9826 h += this.getHeaderFooterHeight() + this.body.getMargins("tb");
9827 w += this.body.getMargins("lr") + this.bwrap.getMargins("lr") + this.centerBg.getPadding("lr");
9828 //if(!this.el.isBorderBox()){
9829 h += this.body.getPadding("tb") + this.bwrap.getBorderWidth("tb") + this.body.getBorderWidth("tb") + this.el.getBorderWidth("tb");
9830 w += this.body.getPadding("lr") + this.bwrap.getBorderWidth("lr") + this.body.getBorderWidth("lr") + this.bwrap.getPadding("lr") + this.el.getBorderWidth("lr");
9833 h += this.tabs.stripWrap.getHeight() + this.tabs.bodyEl.getMargins("tb") + this.tabs.bodyEl.getPadding("tb");
9834 w += this.tabs.bodyEl.getMargins("lr") + this.tabs.bodyEl.getPadding("lr");
9836 this.resizeTo(w, h);
9841 * Adds a key listener for when this dialog is displayed. This allows you to hook in a function that will be
9842 * executed in response to a particular key being pressed while the dialog is active.
9843 * @param {Number/Array/Object} key Either the numeric key code, array of key codes or an object with the following options:
9844 * {key: (number or array), shift: (true/false), ctrl: (true/false), alt: (true/false)}
9845 * @param {Function} fn The function to call
9846 * @param {Object} scope (optional) The scope of the function
9847 * @return {Roo.BasicDialog} this
9849 addKeyListener : function(key, fn, scope){
9850 var keyCode, shift, ctrl, alt;
9851 if(typeof key == "object" && !(key instanceof Array)){
9852 keyCode = key["key"];
9853 shift = key["shift"];
9859 var handler = function(dlg, e){
9860 if((!shift || e.shiftKey) && (!ctrl || e.ctrlKey) && (!alt || e.altKey)){
9862 if(keyCode instanceof Array){
9863 for(var i = 0, len = keyCode.length; i < len; i++){
9864 if(keyCode[i] == k){
9865 fn.call(scope || window, dlg, k, e);
9871 fn.call(scope || window, dlg, k, e);
9876 this.on("keydown", handler);
9881 * Returns the TabPanel component (creates it if it doesn't exist).
9882 * Note: If you wish to simply check for the existence of tabs without creating them,
9883 * check for a null 'tabs' property.
9884 * @return {Roo.TabPanel} The tabs component
9886 getTabs : function(){
9888 this.el.addClass("x-dlg-auto-tabs");
9889 this.body.addClass(this.tabPosition == "bottom" ? "x-tabs-bottom" : "x-tabs-top");
9890 this.tabs = new Roo.TabPanel(this.body.dom, this.tabPosition == "bottom");
9896 * Adds a button to the footer section of the dialog.
9897 * @param {String/Object} config A string becomes the button text, an object can either be a Button config
9898 * object or a valid Roo.DomHelper element config
9899 * @param {Function} handler The function called when the button is clicked
9900 * @param {Object} scope (optional) The scope of the handler function (accepts position as a property)
9901 * @return {Roo.Button} The new button
9903 addButton : function(config, handler, scope){
9904 var dh = Roo.DomHelper;
9906 this.footer = dh.append(this.bwrap, {tag: "div", cls:"x-dlg-ft"}, true);
9908 if(!this.btnContainer){
9909 var tb = this.footer.createChild({
9911 cls:"x-dlg-btns x-dlg-btns-"+this.buttonAlign,
9912 html:'<table cellspacing="0"><tbody><tr></tr></tbody></table><div class="x-clear"></div>'
9914 this.btnContainer = tb.firstChild.firstChild.firstChild;
9919 minWidth: this.minButtonWidth,
9922 if(typeof config == "string"){
9923 bconfig.text = config;
9926 bconfig.dhconfig = config;
9928 Roo.apply(bconfig, config);
9932 if ((typeof(bconfig.position) != 'undefined') && bconfig.position < this.btnContainer.childNodes.length-1) {
9933 bconfig.position = Math.max(0, bconfig.position);
9934 fc = this.btnContainer.childNodes[bconfig.position];
9937 var btn = new Roo.Button(
9939 this.btnContainer.insertBefore(document.createElement("td"),fc)
9940 : this.btnContainer.appendChild(document.createElement("td")),
9941 //Roo.get(this.btnContainer).createChild( { tag: 'td'}, fc ),
9944 this.syncBodyHeight();
9947 * Array of all the buttons that have been added to this dialog via addButton
9952 this.buttons.push(btn);
9957 * Sets the default button to be focused when the dialog is displayed.
9958 * @param {Roo.BasicDialog.Button} btn The button object returned by {@link #addButton}
9959 * @return {Roo.BasicDialog} this
9961 setDefaultButton : function(btn){
9962 this.defaultButton = btn;
9967 getHeaderFooterHeight : function(safe){
9970 height += this.header.getHeight();
9973 var fm = this.footer.getMargins();
9974 height += (this.footer.getHeight()+fm.top+fm.bottom);
9976 height += this.bwrap.getPadding("tb")+this.bwrap.getBorderWidth("tb");
9977 height += this.centerBg.getPadding("tb");
9982 syncBodyHeight : function()
9984 var bd = this.body, // the text
9985 cb = this.centerBg, // wrapper around bottom.. but does not seem to be used..
9987 var height = this.size.height - this.getHeaderFooterHeight(false);
9988 bd.setHeight(height-bd.getMargins("tb"));
9989 var hh = this.header.getHeight();
9990 var h = this.size.height-hh;
9993 bw.setLeftTop(cb.getPadding("l"), hh+cb.getPadding("t"));
9994 bw.setHeight(h-cb.getPadding("tb"));
9996 bw.setWidth(this.el.getWidth(true)-cb.getPadding("lr"));
9997 bd.setWidth(bw.getWidth(true));
9999 this.tabs.syncHeight();
10001 this.tabs.el.repaint();
10007 * Restores the previous state of the dialog if Roo.state is configured.
10008 * @return {Roo.BasicDialog} this
10010 restoreState : function(){
10011 var box = Roo.state.Manager.get(this.stateId || (this.el.id + "-state"));
10012 if(box && box.width){
10013 this.xy = [box.x, box.y];
10014 this.resizeTo(box.width, box.height);
10020 beforeShow : function(){
10022 if(this.fixedcenter){
10023 this.xy = this.el.getCenterXY(true);
10026 Roo.get(document.body).addClass("x-body-masked");
10027 this.mask.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
10030 this.constrainXY();
10034 animShow : function(){
10035 var b = Roo.get(this.animateTarget).getBox();
10036 this.proxy.setSize(b.width, b.height);
10037 this.proxy.setLocation(b.x, b.y);
10039 this.proxy.setBounds(this.xy[0], this.xy[1], this.size.width, this.size.height,
10040 true, .35, this.showEl.createDelegate(this));
10044 * Shows the dialog.
10045 * @param {String/HTMLElement/Roo.Element} animateTarget (optional) Reset the animation target
10046 * @return {Roo.BasicDialog} this
10048 show : function(animateTarget){
10049 if (this.fireEvent("beforeshow", this) === false){
10052 if(this.syncHeightBeforeShow){
10053 this.syncBodyHeight();
10054 }else if(this.firstShow){
10055 this.firstShow = false;
10056 this.syncBodyHeight(); // sync the height on the first show instead of in the constructor
10058 this.animateTarget = animateTarget || this.animateTarget;
10059 if(!this.el.isVisible()){
10061 if(this.animateTarget && Roo.get(this.animateTarget)){
10071 showEl : function(){
10073 this.el.setXY(this.xy);
10075 this.adjustAssets(true);
10078 // IE peekaboo bug - fix found by Dave Fenwick
10082 this.fireEvent("show", this);
10086 * Focuses the dialog. If a defaultButton is set, it will receive focus, otherwise the
10087 * dialog itself will receive focus.
10089 focus : function(){
10090 if(this.defaultButton){
10091 this.defaultButton.focus();
10093 this.focusEl.focus();
10098 constrainXY : function(){
10099 if(this.constraintoviewport !== false){
10100 if(!this.viewSize){
10101 if(this.container){
10102 var s = this.container.getSize();
10103 this.viewSize = [s.width, s.height];
10105 this.viewSize = [Roo.lib.Dom.getViewWidth(),Roo.lib.Dom.getViewHeight()];
10108 var s = Roo.get(this.container||document).getScroll();
10110 var x = this.xy[0], y = this.xy[1];
10111 var w = this.size.width, h = this.size.height;
10112 var vw = this.viewSize[0], vh = this.viewSize[1];
10113 // only move it if it needs it
10115 // first validate right/bottom
10116 if(x + w > vw+s.left){
10120 if(y + h > vh+s.top){
10124 // then make sure top/left isn't negative
10136 if(this.isVisible()){
10137 this.el.setLocation(x, y);
10138 this.adjustAssets();
10145 onDrag : function(){
10146 if(!this.proxyDrag){
10147 this.xy = this.el.getXY();
10148 this.adjustAssets();
10153 adjustAssets : function(doShow){
10154 var x = this.xy[0], y = this.xy[1];
10155 var w = this.size.width, h = this.size.height;
10156 if(doShow === true){
10158 this.shadow.show(this.el);
10164 if(this.shadow && this.shadow.isVisible()){
10165 this.shadow.show(this.el);
10167 if(this.shim && this.shim.isVisible()){
10168 this.shim.setBounds(x, y, w, h);
10173 adjustViewport : function(w, h){
10175 w = Roo.lib.Dom.getViewWidth();
10176 h = Roo.lib.Dom.getViewHeight();
10179 this.viewSize = [w, h];
10180 if(this.modal && this.mask.isVisible()){
10181 this.mask.setSize(w, h); // first make sure the mask isn't causing overflow
10182 this.mask.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
10184 if(this.isVisible()){
10185 this.constrainXY();
10190 * Destroys this dialog and all its supporting elements (including any tabs, shim,
10191 * shadow, proxy, mask, etc.) Also removes all event listeners.
10192 * @param {Boolean} removeEl (optional) true to remove the element from the DOM
10194 destroy : function(removeEl){
10195 if(this.isVisible()){
10196 this.animateTarget = null;
10199 Roo.EventManager.removeResizeListener(this.adjustViewport, this);
10201 this.tabs.destroy(removeEl);
10214 for(var i = 0, len = this.buttons.length; i < len; i++){
10215 this.buttons[i].destroy();
10218 this.el.removeAllListeners();
10219 if(removeEl === true){
10220 this.el.update("");
10223 Roo.DialogManager.unregister(this);
10227 startMove : function(){
10228 if(this.proxyDrag){
10231 if(this.constraintoviewport !== false){
10232 this.dd.constrainTo(document.body, {right: this.shadowOffset, bottom: this.shadowOffset});
10237 endMove : function(){
10238 if(!this.proxyDrag){
10239 Roo.dd.DD.prototype.endDrag.apply(this.dd, arguments);
10241 Roo.dd.DDProxy.prototype.endDrag.apply(this.dd, arguments);
10244 this.refreshSize();
10245 this.adjustAssets();
10247 this.fireEvent("move", this, this.xy[0], this.xy[1]);
10251 * Brings this dialog to the front of any other visible dialogs
10252 * @return {Roo.BasicDialog} this
10254 toFront : function(){
10255 Roo.DialogManager.bringToFront(this);
10260 * Sends this dialog to the back (under) of any other visible dialogs
10261 * @return {Roo.BasicDialog} this
10263 toBack : function(){
10264 Roo.DialogManager.sendToBack(this);
10269 * Centers this dialog in the viewport
10270 * @return {Roo.BasicDialog} this
10272 center : function(){
10273 var xy = this.el.getCenterXY(true);
10274 this.moveTo(xy[0], xy[1]);
10279 * Moves the dialog's top-left corner to the specified point
10280 * @param {Number} x
10281 * @param {Number} y
10282 * @return {Roo.BasicDialog} this
10284 moveTo : function(x, y){
10286 if(this.isVisible()){
10287 this.el.setXY(this.xy);
10288 this.adjustAssets();
10294 * Aligns the dialog to the specified element
10295 * @param {String/HTMLElement/Roo.Element} element The element to align to.
10296 * @param {String} position The position to align to (see {@link Roo.Element#alignTo} for more details).
10297 * @param {Array} offsets (optional) Offset the positioning by [x, y]
10298 * @return {Roo.BasicDialog} this
10300 alignTo : function(element, position, offsets){
10301 this.xy = this.el.getAlignToXY(element, position, offsets);
10302 if(this.isVisible()){
10303 this.el.setXY(this.xy);
10304 this.adjustAssets();
10310 * Anchors an element to another element and realigns it when the window is resized.
10311 * @param {String/HTMLElement/Roo.Element} element The element to align to.
10312 * @param {String} position The position to align to (see {@link Roo.Element#alignTo} for more details)
10313 * @param {Array} offsets (optional) Offset the positioning by [x, y]
10314 * @param {Boolean/Number} monitorScroll (optional) true to monitor body scroll and reposition. If this parameter
10315 * is a number, it is used as the buffer delay (defaults to 50ms).
10316 * @return {Roo.BasicDialog} this
10318 anchorTo : function(el, alignment, offsets, monitorScroll){
10319 var action = function(){
10320 this.alignTo(el, alignment, offsets);
10322 Roo.EventManager.onWindowResize(action, this);
10323 var tm = typeof monitorScroll;
10324 if(tm != 'undefined'){
10325 Roo.EventManager.on(window, 'scroll', action, this,
10326 {buffer: tm == 'number' ? monitorScroll : 50});
10333 * Returns true if the dialog is visible
10334 * @return {Boolean}
10336 isVisible : function(){
10337 return this.el.isVisible();
10341 animHide : function(callback){
10342 var b = Roo.get(this.animateTarget).getBox();
10344 this.proxy.setBounds(this.xy[0], this.xy[1], this.size.width, this.size.height);
10346 this.proxy.setBounds(b.x, b.y, b.width, b.height, true, .35,
10347 this.hideEl.createDelegate(this, [callback]));
10351 * Hides the dialog.
10352 * @param {Function} callback (optional) Function to call when the dialog is hidden
10353 * @return {Roo.BasicDialog} this
10355 hide : function(callback){
10356 if (this.fireEvent("beforehide", this) === false){
10360 this.shadow.hide();
10365 // sometimes animateTarget seems to get set.. causing problems...
10366 // this just double checks..
10367 if(this.animateTarget && Roo.get(this.animateTarget)) {
10368 this.animHide(callback);
10371 this.hideEl(callback);
10377 hideEl : function(callback){
10381 Roo.get(document.body).removeClass("x-body-masked");
10383 this.fireEvent("hide", this);
10384 if(typeof callback == "function"){
10390 hideAction : function(){
10391 this.setLeft("-10000px");
10392 this.setTop("-10000px");
10393 this.setStyle("visibility", "hidden");
10397 refreshSize : function(){
10398 this.size = this.el.getSize();
10399 this.xy = this.el.getXY();
10400 Roo.state.Manager.set(this.stateId || this.el.id + "-state", this.el.getBox());
10404 // z-index is managed by the DialogManager and may be overwritten at any time
10405 setZIndex : function(index){
10407 this.mask.setStyle("z-index", index);
10410 this.shim.setStyle("z-index", ++index);
10413 this.shadow.setZIndex(++index);
10415 this.el.setStyle("z-index", ++index);
10417 this.proxy.setStyle("z-index", ++index);
10420 this.resizer.proxy.setStyle("z-index", ++index);
10423 this.lastZIndex = index;
10427 * Returns the element for this dialog
10428 * @return {Roo.Element} The underlying dialog Element
10430 getEl : function(){
10436 * @class Roo.DialogManager
10437 * Provides global access to BasicDialogs that have been created and
10438 * support for z-indexing (layering) multiple open dialogs.
10440 Roo.DialogManager = function(){
10442 var accessList = [];
10446 var sortDialogs = function(d1, d2){
10447 return (!d1._lastAccess || d1._lastAccess < d2._lastAccess) ? -1 : 1;
10451 var orderDialogs = function(){
10452 accessList.sort(sortDialogs);
10453 var seed = Roo.DialogManager.zseed;
10454 for(var i = 0, len = accessList.length; i < len; i++){
10455 var dlg = accessList[i];
10457 dlg.setZIndex(seed + (i*10));
10464 * The starting z-index for BasicDialogs (defaults to 9000)
10465 * @type Number The z-index value
10470 register : function(dlg){
10471 list[dlg.id] = dlg;
10472 accessList.push(dlg);
10476 unregister : function(dlg){
10477 delete list[dlg.id];
10480 if(!accessList.indexOf){
10481 for( i = 0, len = accessList.length; i < len; i++){
10482 if(accessList[i] == dlg){
10483 accessList.splice(i, 1);
10488 i = accessList.indexOf(dlg);
10490 accessList.splice(i, 1);
10496 * Gets a registered dialog by id
10497 * @param {String/Object} id The id of the dialog or a dialog
10498 * @return {Roo.BasicDialog} this
10500 get : function(id){
10501 return typeof id == "object" ? id : list[id];
10505 * Brings the specified dialog to the front
10506 * @param {String/Object} dlg The id of the dialog or a dialog
10507 * @return {Roo.BasicDialog} this
10509 bringToFront : function(dlg){
10510 dlg = this.get(dlg);
10513 dlg._lastAccess = new Date().getTime();
10520 * Sends the specified dialog to the back
10521 * @param {String/Object} dlg The id of the dialog or a dialog
10522 * @return {Roo.BasicDialog} this
10524 sendToBack : function(dlg){
10525 dlg = this.get(dlg);
10526 dlg._lastAccess = -(new Date().getTime());
10532 * Hides all dialogs
10534 hideAll : function(){
10535 for(var id in list){
10536 if(list[id] && typeof list[id] != "function" && list[id].isVisible()){
10545 * @class Roo.LayoutDialog
10546 * @extends Roo.BasicDialog
10547 * Dialog which provides adjustments for working with a layout in a Dialog.
10548 * Add your necessary layout config options to the dialog's config.<br>
10549 * Example usage (including a nested layout):
10552 dialog = new Roo.LayoutDialog("download-dlg", {
10561 // layout config merges with the dialog config
10563 tabPosition: "top",
10564 alwaysShowTabs: true
10567 dialog.addKeyListener(27, dialog.hide, dialog);
10568 dialog.setDefaultButton(dialog.addButton("Close", dialog.hide, dialog));
10569 dialog.addButton("Build It!", this.getDownload, this);
10571 // we can even add nested layouts
10572 var innerLayout = new Roo.BorderLayout("dl-inner", {
10582 innerLayout.beginUpdate();
10583 innerLayout.add("east", new Roo.ContentPanel("dl-details"));
10584 innerLayout.add("center", new Roo.ContentPanel("selection-panel"));
10585 innerLayout.endUpdate(true);
10587 var layout = dialog.getLayout();
10588 layout.beginUpdate();
10589 layout.add("center", new Roo.ContentPanel("standard-panel",
10590 {title: "Download the Source", fitToFrame:true}));
10591 layout.add("center", new Roo.NestedLayoutPanel(innerLayout,
10592 {title: "Build your own roo.js"}));
10593 layout.getRegion("center").showPanel(sp);
10594 layout.endUpdate();
10598 * @param {String/HTMLElement/Roo.Element} el The id of or container element, or config
10599 * @param {Object} config configuration options
10601 Roo.LayoutDialog = function(el, cfg){
10604 if (typeof(cfg) == 'undefined') {
10605 config = Roo.apply({}, el);
10606 // not sure why we use documentElement here.. - it should always be body.
10607 // IE7 borks horribly if we use documentElement.
10608 // webkit also does not like documentElement - it creates a body element...
10609 el = Roo.get( document.body || document.documentElement ).createChild();
10610 //config.autoCreate = true;
10614 config.autoTabs = false;
10615 Roo.LayoutDialog.superclass.constructor.call(this, el, config);
10616 this.body.setStyle({overflow:"hidden", position:"relative"});
10617 this.layout = new Roo.BorderLayout(this.body.dom, config);
10618 this.layout.monitorWindowResize = false;
10619 this.el.addClass("x-dlg-auto-layout");
10620 // fix case when center region overwrites center function
10621 this.center = Roo.BasicDialog.prototype.center;
10622 this.on("show", this.layout.layout, this.layout, true);
10623 if (config.items) {
10624 var xitems = config.items;
10625 delete config.items;
10626 Roo.each(xitems, this.addxtype, this);
10631 Roo.extend(Roo.LayoutDialog, Roo.BasicDialog, {
10633 * Ends update of the layout <strike>and resets display to none</strike>. Use standard beginUpdate/endUpdate on the layout.
10636 endUpdate : function(){
10637 this.layout.endUpdate();
10641 * Begins an update of the layout <strike>and sets display to block and visibility to hidden</strike>. Use standard beginUpdate/endUpdate on the layout.
10644 beginUpdate : function(){
10645 this.layout.beginUpdate();
10649 * Get the BorderLayout for this dialog
10650 * @return {Roo.BorderLayout}
10652 getLayout : function(){
10653 return this.layout;
10656 showEl : function(){
10657 Roo.LayoutDialog.superclass.showEl.apply(this, arguments);
10659 this.layout.layout();
10664 // Use the syncHeightBeforeShow config option to control this automatically
10665 syncBodyHeight : function(){
10666 Roo.LayoutDialog.superclass.syncBodyHeight.call(this);
10667 if(this.layout){this.layout.layout();}
10671 * Add an xtype element (actually adds to the layout.)
10672 * @return {Object} xdata xtype object data.
10675 addxtype : function(c) {
10676 return this.layout.addxtype(c);
10680 * Ext JS Library 1.1.1
10681 * Copyright(c) 2006-2007, Ext JS, LLC.
10683 * Originally Released Under LGPL - original licence link has changed is not relivant.
10686 * <script type="text/javascript">
10690 * @class Roo.MessageBox
10691 * Utility class for generating different styles of message boxes. The alias Roo.Msg can also be used.
10695 Roo.Msg.alert('Status', 'Changes saved successfully.');
10697 // Prompt for user data:
10698 Roo.Msg.prompt('Name', 'Please enter your name:', function(btn, text){
10700 // process text value...
10704 // Show a dialog using config options:
10706 title:'Save Changes?',
10707 msg: 'Your are closing a tab that has unsaved changes. Would you like to save your changes?',
10708 buttons: Roo.Msg.YESNOCANCEL,
10715 Roo.MessageBox = function(){
10716 var dlg, opt, mask, waitTimer;
10717 var bodyEl, msgEl, textboxEl, textareaEl, progressEl, pp;
10718 var buttons, activeTextEl, bwidth;
10721 var handleButton = function(button){
10723 Roo.callback(opt.fn, opt.scope||window, [button, activeTextEl.dom.value], 1);
10727 var handleHide = function(){
10728 if(opt && opt.cls){
10729 dlg.el.removeClass(opt.cls);
10732 Roo.TaskMgr.stop(waitTimer);
10738 var updateButtons = function(b){
10741 buttons["ok"].hide();
10742 buttons["cancel"].hide();
10743 buttons["yes"].hide();
10744 buttons["no"].hide();
10745 dlg.footer.dom.style.display = 'none';
10748 dlg.footer.dom.style.display = '';
10749 for(var k in buttons){
10750 if(typeof buttons[k] != "function"){
10753 buttons[k].setText(typeof b[k] == "string" ? b[k] : Roo.MessageBox.buttonText[k]);
10754 width += buttons[k].el.getWidth()+15;
10764 var handleEsc = function(d, k, e){
10765 if(opt && opt.closable !== false){
10775 * Returns a reference to the underlying {@link Roo.BasicDialog} element
10776 * @return {Roo.BasicDialog} The BasicDialog element
10778 getDialog : function(){
10780 dlg = new Roo.BasicDialog("x-msg-box", {
10785 constraintoviewport:false,
10787 collapsible : false,
10790 width:400, height:100,
10791 buttonAlign:"center",
10792 closeClick : function(){
10793 if(opt && opt.buttons && opt.buttons.no && !opt.buttons.cancel){
10794 handleButton("no");
10796 handleButton("cancel");
10800 dlg.on("hide", handleHide);
10802 dlg.addKeyListener(27, handleEsc);
10804 var bt = this.buttonText;
10805 buttons["ok"] = dlg.addButton(bt["ok"], handleButton.createCallback("ok"));
10806 buttons["yes"] = dlg.addButton(bt["yes"], handleButton.createCallback("yes"));
10807 buttons["no"] = dlg.addButton(bt["no"], handleButton.createCallback("no"));
10808 buttons["cancel"] = dlg.addButton(bt["cancel"], handleButton.createCallback("cancel"));
10809 bodyEl = dlg.body.createChild({
10811 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>'
10813 msgEl = bodyEl.dom.firstChild;
10814 textboxEl = Roo.get(bodyEl.dom.childNodes[2]);
10815 textboxEl.enableDisplayMode();
10816 textboxEl.addKeyListener([10,13], function(){
10817 if(dlg.isVisible() && opt && opt.buttons){
10818 if(opt.buttons.ok){
10819 handleButton("ok");
10820 }else if(opt.buttons.yes){
10821 handleButton("yes");
10825 textareaEl = Roo.get(bodyEl.dom.childNodes[3]);
10826 textareaEl.enableDisplayMode();
10827 progressEl = Roo.get(bodyEl.dom.childNodes[4]);
10828 progressEl.enableDisplayMode();
10829 var pf = progressEl.dom.firstChild;
10831 pp = Roo.get(pf.firstChild);
10832 pp.setHeight(pf.offsetHeight);
10840 * Updates the message box body text
10841 * @param {String} text (optional) Replaces the message box element's innerHTML with the specified string (defaults to
10842 * the XHTML-compliant non-breaking space character '&#160;')
10843 * @return {Roo.MessageBox} This message box
10845 updateText : function(text){
10846 if(!dlg.isVisible() && !opt.width){
10847 dlg.resizeTo(this.maxWidth, 100); // resize first so content is never clipped from previous shows
10849 msgEl.innerHTML = text || ' ';
10851 var cw = Math.max(msgEl.offsetWidth, msgEl.parentNode.scrollWidth);
10852 //Roo.log("guesed size: " + JSON.stringify([cw,msgEl.offsetWidth, msgEl.parentNode.scrollWidth]));
10854 Math.min(opt.width || cw , this.maxWidth),
10855 Math.max(opt.minWidth || this.minWidth, bwidth)
10858 activeTextEl.setWidth(w);
10860 if(dlg.isVisible()){
10861 dlg.fixedcenter = false;
10863 // to big, make it scroll. = But as usual stupid IE does not support
10866 if ( bodyEl.getHeight() > (Roo.lib.Dom.getViewHeight() - 100)) {
10867 bodyEl.setHeight ( Roo.lib.Dom.getViewHeight() - 100 );
10868 bodyEl.dom.style.overflowY = 'auto' + ( Roo.isIE ? '' : ' !important');
10870 bodyEl.dom.style.height = '';
10871 bodyEl.dom.style.overflowY = '';
10874 bodyEl.dom.style.get = 'auto' + ( Roo.isIE ? '' : ' !important');
10876 bodyEl.dom.style.overflowX = '';
10879 dlg.setContentSize(w, bodyEl.getHeight());
10880 if(dlg.isVisible()){
10881 dlg.fixedcenter = true;
10887 * Updates a progress-style message box's text and progress bar. Only relevant on message boxes
10888 * initiated via {@link Roo.MessageBox#progress} or by calling {@link Roo.MessageBox#show} with progress: true.
10889 * @param {Number} value Any number between 0 and 1 (e.g., .5)
10890 * @param {String} text (optional) If defined, the message box's body text is replaced with the specified string (defaults to undefined)
10891 * @return {Roo.MessageBox} This message box
10893 updateProgress : function(value, text){
10895 this.updateText(text);
10897 if (pp) { // weird bug on my firefox - for some reason this is not defined
10898 pp.setWidth(Math.floor(value*progressEl.dom.firstChild.offsetWidth));
10904 * Returns true if the message box is currently displayed
10905 * @return {Boolean} True if the message box is visible, else false
10907 isVisible : function(){
10908 return dlg && dlg.isVisible();
10912 * Hides the message box if it is displayed
10915 if(this.isVisible()){
10921 * Displays a new message box, or reinitializes an existing message box, based on the config options
10922 * passed in. All functions (e.g. prompt, alert, etc) on MessageBox call this function internally.
10923 * The following config object properties are supported:
10925 Property Type Description
10926 ---------- --------------- ------------------------------------------------------------------------------------
10927 animEl String/Element An id or Element from which the message box should animate as it opens and
10928 closes (defaults to undefined)
10929 buttons Object/Boolean A button config object (e.g., Roo.MessageBox.OKCANCEL or {ok:'Foo',
10930 cancel:'Bar'}), or false to not show any buttons (defaults to false)
10931 closable Boolean False to hide the top-right close button (defaults to true). Note that
10932 progress and wait dialogs will ignore this property and always hide the
10933 close button as they can only be closed programmatically.
10934 cls String A custom CSS class to apply to the message box element
10935 defaultTextHeight Number The default height in pixels of the message box's multiline textarea if
10936 displayed (defaults to 75)
10937 fn Function A callback function to execute after closing the dialog. The arguments to the
10938 function will be btn (the name of the button that was clicked, if applicable,
10939 e.g. "ok"), and text (the value of the active text field, if applicable).
10940 Progress and wait dialogs will ignore this option since they do not respond to
10941 user actions and can only be closed programmatically, so any required function
10942 should be called by the same code after it closes the dialog.
10943 icon String A CSS class that provides a background image to be used as an icon for
10944 the dialog (e.g., Roo.MessageBox.WARNING or 'custom-class', defaults to '')
10945 maxWidth Number The maximum width in pixels of the message box (defaults to 600)
10946 minWidth Number The minimum width in pixels of the message box (defaults to 100)
10947 modal Boolean False to allow user interaction with the page while the message box is
10948 displayed (defaults to true)
10949 msg String A string that will replace the existing message box body text (defaults
10950 to the XHTML-compliant non-breaking space character ' ')
10951 multiline Boolean True to prompt the user to enter multi-line text (defaults to false)
10952 progress Boolean True to display a progress bar (defaults to false)
10953 progressText String The text to display inside the progress bar if progress = true (defaults to '')
10954 prompt Boolean True to prompt the user to enter single-line text (defaults to false)
10955 proxyDrag Boolean True to display a lightweight proxy while dragging (defaults to false)
10956 title String The title text
10957 value String The string value to set into the active textbox element if displayed
10958 wait Boolean True to display a progress bar (defaults to false)
10959 width Number The width of the dialog in pixels
10966 msg: 'Please enter your address:',
10968 buttons: Roo.MessageBox.OKCANCEL,
10971 animEl: 'addAddressBtn'
10974 * @param {Object} config Configuration options
10975 * @return {Roo.MessageBox} This message box
10977 show : function(options)
10980 // this causes nightmares if you show one dialog after another
10981 // especially on callbacks..
10983 if(this.isVisible()){
10986 Roo.log("[Roo.Messagebox] Show called while message displayed:" );
10987 Roo.log("Old Dialog Message:" + msgEl.innerHTML );
10988 Roo.log("New Dialog Message:" + options.msg )
10989 //this.alert("ERROR", "Multiple dialogs where displayed at the same time");
10990 //throw "Roo.MessageBox ERROR : Multiple dialogs where displayed at the same time";
10993 var d = this.getDialog();
10995 d.setTitle(opt.title || " ");
10996 d.close.setDisplayed(opt.closable !== false);
10997 activeTextEl = textboxEl;
10998 opt.prompt = opt.prompt || (opt.multiline ? true : false);
11003 textareaEl.setHeight(typeof opt.multiline == "number" ?
11004 opt.multiline : this.defaultTextHeight);
11005 activeTextEl = textareaEl;
11014 progressEl.setDisplayed(opt.progress === true);
11015 this.updateProgress(0);
11016 activeTextEl.dom.value = opt.value || "";
11018 dlg.setDefaultButton(activeTextEl);
11020 var bs = opt.buttons;
11023 db = buttons["ok"];
11024 }else if(bs && bs.yes){
11025 db = buttons["yes"];
11027 dlg.setDefaultButton(db);
11029 bwidth = updateButtons(opt.buttons);
11030 this.updateText(opt.msg);
11032 d.el.addClass(opt.cls);
11034 d.proxyDrag = opt.proxyDrag === true;
11035 d.modal = opt.modal !== false;
11036 d.mask = opt.modal !== false ? mask : false;
11037 if(!d.isVisible()){
11038 // force it to the end of the z-index stack so it gets a cursor in FF
11039 document.body.appendChild(dlg.el.dom);
11040 d.animateTarget = null;
11041 d.show(options.animEl);
11047 * Displays a message box with a progress bar. This message box has no buttons and is not closeable by
11048 * the user. You are responsible for updating the progress bar as needed via {@link Roo.MessageBox#updateProgress}
11049 * and closing the message box when the process is complete.
11050 * @param {String} title The title bar text
11051 * @param {String} msg The message box body text
11052 * @return {Roo.MessageBox} This message box
11054 progress : function(title, msg){
11061 minWidth: this.minProgressWidth,
11068 * Displays a standard read-only message box with an OK button (comparable to the basic JavaScript Window.alert).
11069 * If a callback function is passed it will be called after the user clicks the button, and the
11070 * id of the button that was clicked will be passed as the only parameter to the callback
11071 * (could also be the top-right close button).
11072 * @param {String} title The title bar text
11073 * @param {String} msg The message box body text
11074 * @param {Function} fn (optional) The callback function invoked after the message box is closed
11075 * @param {Object} scope (optional) The scope of the callback function
11076 * @return {Roo.MessageBox} This message box
11078 alert : function(title, msg, fn, scope){
11091 * Displays a message box with an infinitely auto-updating progress bar. This can be used to block user
11092 * interaction while waiting for a long-running process to complete that does not have defined intervals.
11093 * You are responsible for closing the message box when the process is complete.
11094 * @param {String} msg The message box body text
11095 * @param {String} title (optional) The title bar text
11096 * @return {Roo.MessageBox} This message box
11098 wait : function(msg, title){
11109 waitTimer = Roo.TaskMgr.start({
11111 Roo.MessageBox.updateProgress(((((i+20)%20)+1)*5)*.01);
11119 * Displays a confirmation message box with Yes and No buttons (comparable to JavaScript's Window.confirm).
11120 * If a callback function is passed it will be called after the user clicks either button, and the id of the
11121 * button that was clicked will be passed as the only parameter to the callback (could also be the top-right close button).
11122 * @param {String} title The title bar text
11123 * @param {String} msg The message box body text
11124 * @param {Function} fn (optional) The callback function invoked after the message box is closed
11125 * @param {Object} scope (optional) The scope of the callback function
11126 * @return {Roo.MessageBox} This message box
11128 confirm : function(title, msg, fn, scope){
11132 buttons: this.YESNO,
11141 * Displays a message box with OK and Cancel buttons prompting the user to enter some text (comparable to
11142 * JavaScript's Window.prompt). The prompt can be a single-line or multi-line textbox. If a callback function
11143 * is passed it will be called after the user clicks either button, and the id of the button that was clicked
11144 * (could also be the top-right close button) and the text that was entered will be passed as the two
11145 * parameters to the callback.
11146 * @param {String} title The title bar text
11147 * @param {String} msg The message box body text
11148 * @param {Function} fn (optional) The callback function invoked after the message box is closed
11149 * @param {Object} scope (optional) The scope of the callback function
11150 * @param {Boolean/Number} multiline (optional) True to create a multiline textbox using the defaultTextHeight
11151 * property, or the height in pixels to create the textbox (defaults to false / single-line)
11152 * @return {Roo.MessageBox} This message box
11154 prompt : function(title, msg, fn, scope, multiline){
11158 buttons: this.OKCANCEL,
11163 multiline: multiline,
11170 * Button config that displays a single OK button
11175 * Button config that displays Yes and No buttons
11178 YESNO : {yes:true, no:true},
11180 * Button config that displays OK and Cancel buttons
11183 OKCANCEL : {ok:true, cancel:true},
11185 * Button config that displays Yes, No and Cancel buttons
11188 YESNOCANCEL : {yes:true, no:true, cancel:true},
11191 * The default height in pixels of the message box's multiline textarea if displayed (defaults to 75)
11194 defaultTextHeight : 75,
11196 * The maximum width in pixels of the message box (defaults to 600)
11201 * The minimum width in pixels of the message box (defaults to 100)
11206 * The minimum width in pixels of the message box if it is a progress-style dialog. This is useful
11207 * for setting a different minimum width than text-only dialogs may need (defaults to 250)
11210 minProgressWidth : 250,
11212 * An object containing the default button text strings that can be overriden for localized language support.
11213 * Supported properties are: ok, cancel, yes and no.
11214 * Customize the default text like so: Roo.MessageBox.buttonText.yes = "S?";
11227 * Shorthand for {@link Roo.MessageBox}
11229 Roo.Msg = Roo.MessageBox;/*
11231 * Ext JS Library 1.1.1
11232 * Copyright(c) 2006-2007, Ext JS, LLC.
11234 * Originally Released Under LGPL - original licence link has changed is not relivant.
11237 * <script type="text/javascript">
11240 * @class Roo.QuickTips
11241 * Provides attractive and customizable tooltips for any element.
11244 Roo.QuickTips = function(){
11245 var el, tipBody, tipBodyText, tipTitle, tm, cfg, close, tagEls = {}, esc, removeCls = null, bdLeft, bdRight;
11246 var ce, bd, xy, dd;
11247 var visible = false, disabled = true, inited = false;
11248 var showProc = 1, hideProc = 1, dismissProc = 1, locks = [];
11250 var onOver = function(e){
11254 var t = e.getTarget();
11255 if(!t || t.nodeType !== 1 || t == document || t == document.body){
11258 if(ce && t == ce.el){
11259 clearTimeout(hideProc);
11262 if(t && tagEls[t.id]){
11263 tagEls[t.id].el = t;
11264 showProc = show.defer(tm.showDelay, tm, [tagEls[t.id]]);
11267 var ttp, et = Roo.fly(t);
11268 var ns = cfg.namespace;
11269 if(tm.interceptTitles && t.title){
11272 t.removeAttribute("title");
11273 e.preventDefault();
11275 ttp = t.qtip || et.getAttributeNS(ns, cfg.attribute) || et.getAttributeNS(cfg.alt_namespace, cfg.attribute) ;
11278 showProc = show.defer(tm.showDelay, tm, [{
11280 text: ttp.replace(/\\n/g,'<br/>'),
11281 width: et.getAttributeNS(ns, cfg.width),
11282 autoHide: et.getAttributeNS(ns, cfg.hide) != "user",
11283 title: et.getAttributeNS(ns, cfg.title),
11284 cls: et.getAttributeNS(ns, cfg.cls)
11289 var onOut = function(e){
11290 clearTimeout(showProc);
11291 var t = e.getTarget();
11292 if(t && ce && ce.el == t && (tm.autoHide && ce.autoHide !== false)){
11293 hideProc = setTimeout(hide, tm.hideDelay);
11297 var onMove = function(e){
11303 if(tm.trackMouse && ce){
11308 var onDown = function(e){
11309 clearTimeout(showProc);
11310 clearTimeout(hideProc);
11312 if(tm.hideOnClick){
11315 tm.enable.defer(100, tm);
11320 var getPad = function(){
11321 return 2;//bdLeft.getPadding('l')+bdRight.getPadding('r');
11324 var show = function(o){
11328 clearTimeout(dismissProc);
11330 if(removeCls){ // in case manually hidden
11331 el.removeClass(removeCls);
11335 el.addClass(ce.cls);
11336 removeCls = ce.cls;
11339 tipTitle.update(ce.title);
11342 tipTitle.update('');
11345 el.dom.style.width = tm.maxWidth+'px';
11346 //tipBody.dom.style.width = '';
11347 tipBodyText.update(o.text);
11348 var p = getPad(), w = ce.width;
11350 var td = tipBodyText.dom;
11351 var aw = Math.max(td.offsetWidth, td.clientWidth, td.scrollWidth);
11352 if(aw > tm.maxWidth){
11354 }else if(aw < tm.minWidth){
11360 //tipBody.setWidth(w);
11361 el.setWidth(parseInt(w, 10) + p);
11362 if(ce.autoHide === false){
11363 close.setDisplayed(true);
11368 close.setDisplayed(false);
11374 el.avoidY = xy[1]-18;
11379 el.setStyle("visibility", "visible");
11380 el.fadeIn({callback: afterShow});
11386 var afterShow = function(){
11390 if(tm.autoDismiss && ce.autoHide !== false){
11391 dismissProc = setTimeout(hide, tm.autoDismissDelay);
11396 var hide = function(noanim){
11397 clearTimeout(dismissProc);
11398 clearTimeout(hideProc);
11400 if(el.isVisible()){
11402 if(noanim !== true && tm.animate){
11403 el.fadeOut({callback: afterHide});
11410 var afterHide = function(){
11413 el.removeClass(removeCls);
11420 * @cfg {Number} minWidth
11421 * The minimum width of the quick tip (defaults to 40)
11425 * @cfg {Number} maxWidth
11426 * The maximum width of the quick tip (defaults to 300)
11430 * @cfg {Boolean} interceptTitles
11431 * True to automatically use the element's DOM title value if available (defaults to false)
11433 interceptTitles : false,
11435 * @cfg {Boolean} trackMouse
11436 * True to have the quick tip follow the mouse as it moves over the target element (defaults to false)
11438 trackMouse : false,
11440 * @cfg {Boolean} hideOnClick
11441 * True to hide the quick tip if the user clicks anywhere in the document (defaults to true)
11443 hideOnClick : true,
11445 * @cfg {Number} showDelay
11446 * Delay in milliseconds before the quick tip displays after the mouse enters the target element (defaults to 500)
11450 * @cfg {Number} hideDelay
11451 * Delay in milliseconds before the quick tip hides when autoHide = true (defaults to 200)
11455 * @cfg {Boolean} autoHide
11456 * True to automatically hide the quick tip after the mouse exits the target element (defaults to true).
11457 * Used in conjunction with hideDelay.
11462 * True to automatically hide the quick tip after a set period of time, regardless of the user's actions
11463 * (defaults to true). Used in conjunction with autoDismissDelay.
11465 autoDismiss : true,
11468 * Delay in milliseconds before the quick tip hides when autoDismiss = true (defaults to 5000)
11470 autoDismissDelay : 5000,
11472 * @cfg {Boolean} animate
11473 * True to turn on fade animation. Defaults to false (ClearType/scrollbar flicker issues in IE7).
11478 * @cfg {String} title
11479 * Title text to display (defaults to ''). This can be any valid HTML markup.
11483 * @cfg {String} text
11484 * Body text to display (defaults to ''). This can be any valid HTML markup.
11488 * @cfg {String} cls
11489 * A CSS class to apply to the base quick tip element (defaults to '').
11493 * @cfg {Number} width
11494 * Width in pixels of the quick tip (defaults to auto). Width will be ignored if it exceeds the bounds of
11495 * minWidth or maxWidth.
11500 * Initialize and enable QuickTips for first use. This should be called once before the first attempt to access
11501 * or display QuickTips in a page.
11504 tm = Roo.QuickTips;
11505 cfg = tm.tagConfig;
11507 if(!Roo.isReady){ // allow calling of init() before onReady
11508 Roo.onReady(Roo.QuickTips.init, Roo.QuickTips);
11511 el = new Roo.Layer({cls:"x-tip", shadow:"drop", shim: true, constrain:true, shadowOffset:4});
11512 el.fxDefaults = {stopFx: true};
11513 // maximum custom styling
11514 //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>');
11515 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>');
11516 tipTitle = el.child('h3');
11517 tipTitle.enableDisplayMode("block");
11518 tipBody = el.child('div.x-tip-bd');
11519 tipBodyText = el.child('div.x-tip-bd-inner');
11520 //bdLeft = el.child('div.x-tip-bd-left');
11521 //bdRight = el.child('div.x-tip-bd-right');
11522 close = el.child('div.x-tip-close');
11523 close.enableDisplayMode("block");
11524 close.on("click", hide);
11525 var d = Roo.get(document);
11526 d.on("mousedown", onDown);
11527 d.on("mouseover", onOver);
11528 d.on("mouseout", onOut);
11529 d.on("mousemove", onMove);
11530 esc = d.addKeyListener(27, hide);
11533 dd = el.initDD("default", null, {
11534 onDrag : function(){
11538 dd.setHandleElId(tipTitle.id);
11547 * Configures a new quick tip instance and assigns it to a target element. The following config options
11550 Property Type Description
11551 ---------- --------------------- ------------------------------------------------------------------------
11552 target Element/String/Array An Element, id or array of ids that this quick tip should be tied to
11554 * @param {Object} config The config object
11556 register : function(config){
11557 var cs = config instanceof Array ? config : arguments;
11558 for(var i = 0, len = cs.length; i < len; i++) {
11560 var target = c.target;
11562 if(target instanceof Array){
11563 for(var j = 0, jlen = target.length; j < jlen; j++){
11564 tagEls[target[j]] = c;
11567 tagEls[typeof target == 'string' ? target : Roo.id(target)] = c;
11574 * Removes this quick tip from its element and destroys it.
11575 * @param {String/HTMLElement/Element} el The element from which the quick tip is to be removed.
11577 unregister : function(el){
11578 delete tagEls[Roo.id(el)];
11582 * Enable this quick tip.
11584 enable : function(){
11585 if(inited && disabled){
11587 if(locks.length < 1){
11594 * Disable this quick tip.
11596 disable : function(){
11598 clearTimeout(showProc);
11599 clearTimeout(hideProc);
11600 clearTimeout(dismissProc);
11608 * Returns true if the quick tip is enabled, else false.
11610 isEnabled : function(){
11616 namespace : "roo", // was ext?? this may break..
11617 alt_namespace : "ext",
11618 attribute : "qtip",
11628 // backwards compat
11629 Roo.QuickTips.tips = Roo.QuickTips.register;/*
11631 * Ext JS Library 1.1.1
11632 * Copyright(c) 2006-2007, Ext JS, LLC.
11634 * Originally Released Under LGPL - original licence link has changed is not relivant.
11637 * <script type="text/javascript">
11642 * @class Roo.tree.TreePanel
11643 * @extends Roo.data.Tree
11645 * @cfg {Boolean} rootVisible false to hide the root node (defaults to true)
11646 * @cfg {Boolean} lines false to disable tree lines (defaults to true)
11647 * @cfg {Boolean} enableDD true to enable drag and drop
11648 * @cfg {Boolean} enableDrag true to enable just drag
11649 * @cfg {Boolean} enableDrop true to enable just drop
11650 * @cfg {Object} dragConfig Custom config to pass to the {@link Roo.tree.TreeDragZone} instance
11651 * @cfg {Object} dropConfig Custom config to pass to the {@link Roo.tree.TreeDropZone} instance
11652 * @cfg {String} ddGroup The DD group this TreePanel belongs to
11653 * @cfg {String} ddAppendOnly True if the tree should only allow append drops (use for trees which are sorted)
11654 * @cfg {Boolean} ddScroll true to enable YUI body scrolling
11655 * @cfg {Boolean} containerScroll true to register this container with ScrollManager
11656 * @cfg {Boolean} hlDrop false to disable node highlight on drop (defaults to the value of Roo.enableFx)
11657 * @cfg {String} hlColor The color of the node highlight (defaults to C3DAF9)
11658 * @cfg {Boolean} animate true to enable animated expand/collapse (defaults to the value of Roo.enableFx)
11659 * @cfg {Boolean} singleExpand true if only 1 node per branch may be expanded
11660 * @cfg {Boolean} selModel A tree selection model to use with this TreePanel (defaults to a {@link Roo.tree.DefaultSelectionModel})
11661 * @cfg {Boolean} loader A TreeLoader for use with this TreePanel
11662 * @cfg {Object|Roo.tree.TreeEditor} editor The TreeEditor or xtype data to display when clicked.
11663 * @cfg {String} pathSeparator The token used to separate sub-paths in path strings (defaults to '/')
11664 * @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>
11665 * @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>
11668 * @param {String/HTMLElement/Element} el The container element
11669 * @param {Object} config
11671 Roo.tree.TreePanel = function(el, config){
11673 var loader = false;
11675 root = config.root;
11676 delete config.root;
11678 if (config.loader) {
11679 loader = config.loader;
11680 delete config.loader;
11683 Roo.apply(this, config);
11684 Roo.tree.TreePanel.superclass.constructor.call(this);
11685 this.el = Roo.get(el);
11686 this.el.addClass('x-tree');
11687 //console.log(root);
11689 this.setRootNode( Roo.factory(root, Roo.tree));
11692 this.loader = Roo.factory(loader, Roo.tree);
11695 * Read-only. The id of the container element becomes this TreePanel's id.
11697 this.id = this.el.id;
11700 * @event beforeload
11701 * Fires before a node is loaded, return false to cancel
11702 * @param {Node} node The node being loaded
11704 "beforeload" : true,
11707 * Fires when a node is loaded
11708 * @param {Node} node The node that was loaded
11712 * @event textchange
11713 * Fires when the text for a node is changed
11714 * @param {Node} node The node
11715 * @param {String} text The new text
11716 * @param {String} oldText The old text
11718 "textchange" : true,
11720 * @event beforeexpand
11721 * Fires before a node is expanded, return false to cancel.
11722 * @param {Node} node The node
11723 * @param {Boolean} deep
11724 * @param {Boolean} anim
11726 "beforeexpand" : true,
11728 * @event beforecollapse
11729 * Fires before a node is collapsed, return false to cancel.
11730 * @param {Node} node The node
11731 * @param {Boolean} deep
11732 * @param {Boolean} anim
11734 "beforecollapse" : true,
11737 * Fires when a node is expanded
11738 * @param {Node} node The node
11742 * @event disabledchange
11743 * Fires when the disabled status of a node changes
11744 * @param {Node} node The node
11745 * @param {Boolean} disabled
11747 "disabledchange" : true,
11750 * Fires when a node is collapsed
11751 * @param {Node} node The node
11755 * @event beforeclick
11756 * Fires before click processing on a node. Return false to cancel the default action.
11757 * @param {Node} node The node
11758 * @param {Roo.EventObject} e The event object
11760 "beforeclick":true,
11762 * @event checkchange
11763 * Fires when a node with a checkbox's checked property changes
11764 * @param {Node} this This node
11765 * @param {Boolean} checked
11767 "checkchange":true,
11770 * Fires when a node is clicked
11771 * @param {Node} node The node
11772 * @param {Roo.EventObject} e The event object
11777 * Fires when a node is double clicked
11778 * @param {Node} node The node
11779 * @param {Roo.EventObject} e The event object
11783 * @event contextmenu
11784 * Fires when a node is right clicked
11785 * @param {Node} node The node
11786 * @param {Roo.EventObject} e The event object
11788 "contextmenu":true,
11790 * @event beforechildrenrendered
11791 * Fires right before the child nodes for a node are rendered
11792 * @param {Node} node The node
11794 "beforechildrenrendered":true,
11797 * Fires when a node starts being dragged
11798 * @param {Roo.tree.TreePanel} this
11799 * @param {Roo.tree.TreeNode} node
11800 * @param {event} e The raw browser event
11802 "startdrag" : true,
11805 * Fires when a drag operation is complete
11806 * @param {Roo.tree.TreePanel} this
11807 * @param {Roo.tree.TreeNode} node
11808 * @param {event} e The raw browser event
11813 * Fires when a dragged node is dropped on a valid DD target
11814 * @param {Roo.tree.TreePanel} this
11815 * @param {Roo.tree.TreeNode} node
11816 * @param {DD} dd The dd it was dropped on
11817 * @param {event} e The raw browser event
11821 * @event beforenodedrop
11822 * Fires when a DD object is dropped on a node in this tree for preprocessing. Return false to cancel the drop. The dropEvent
11823 * passed to handlers has the following properties:<br />
11824 * <ul style="padding:5px;padding-left:16px;">
11825 * <li>tree - The TreePanel</li>
11826 * <li>target - The node being targeted for the drop</li>
11827 * <li>data - The drag data from the drag source</li>
11828 * <li>point - The point of the drop - append, above or below</li>
11829 * <li>source - The drag source</li>
11830 * <li>rawEvent - Raw mouse event</li>
11831 * <li>dropNode - Drop node(s) provided by the source <b>OR</b> you can supply node(s)
11832 * to be inserted by setting them on this object.</li>
11833 * <li>cancel - Set this to true to cancel the drop.</li>
11835 * @param {Object} dropEvent
11837 "beforenodedrop" : true,
11840 * Fires after a DD object is dropped on a node in this tree. The dropEvent
11841 * passed to handlers has the following properties:<br />
11842 * <ul style="padding:5px;padding-left:16px;">
11843 * <li>tree - The TreePanel</li>
11844 * <li>target - The node being targeted for the drop</li>
11845 * <li>data - The drag data from the drag source</li>
11846 * <li>point - The point of the drop - append, above or below</li>
11847 * <li>source - The drag source</li>
11848 * <li>rawEvent - Raw mouse event</li>
11849 * <li>dropNode - Dropped node(s).</li>
11851 * @param {Object} dropEvent
11855 * @event nodedragover
11856 * Fires when a tree node is being targeted for a drag drop, return false to signal drop not allowed. The dragOverEvent
11857 * passed to handlers has the following properties:<br />
11858 * <ul style="padding:5px;padding-left:16px;">
11859 * <li>tree - The TreePanel</li>
11860 * <li>target - The node being targeted for the drop</li>
11861 * <li>data - The drag data from the drag source</li>
11862 * <li>point - The point of the drop - append, above or below</li>
11863 * <li>source - The drag source</li>
11864 * <li>rawEvent - Raw mouse event</li>
11865 * <li>dropNode - Drop node(s) provided by the source.</li>
11866 * <li>cancel - Set this to true to signal drop not allowed.</li>
11868 * @param {Object} dragOverEvent
11870 "nodedragover" : true,
11872 * @event appendnode
11873 * Fires when append node to the tree
11874 * @param {Roo.tree.TreePanel} this
11875 * @param {Roo.tree.TreeNode} node
11876 * @param {Number} index The index of the newly appended node
11878 "appendnode" : true
11881 if(this.singleExpand){
11882 this.on("beforeexpand", this.restrictExpand, this);
11885 this.editor.tree = this;
11886 this.editor = Roo.factory(this.editor, Roo.tree);
11889 if (this.selModel) {
11890 this.selModel = Roo.factory(this.selModel, Roo.tree);
11894 Roo.extend(Roo.tree.TreePanel, Roo.data.Tree, {
11895 rootVisible : true,
11896 animate: Roo.enableFx,
11899 hlDrop : Roo.enableFx,
11903 rendererTip: false,
11905 restrictExpand : function(node){
11906 var p = node.parentNode;
11908 if(p.expandedChild && p.expandedChild.parentNode == p){
11909 p.expandedChild.collapse();
11911 p.expandedChild = node;
11915 // private override
11916 setRootNode : function(node){
11917 Roo.tree.TreePanel.superclass.setRootNode.call(this, node);
11918 if(!this.rootVisible){
11919 node.ui = new Roo.tree.RootTreeNodeUI(node);
11925 * Returns the container element for this TreePanel
11927 getEl : function(){
11932 * Returns the default TreeLoader for this TreePanel
11934 getLoader : function(){
11935 return this.loader;
11941 expandAll : function(){
11942 this.root.expand(true);
11946 * Collapse all nodes
11948 collapseAll : function(){
11949 this.root.collapse(true);
11953 * Returns the selection model used by this TreePanel
11955 getSelectionModel : function(){
11956 if(!this.selModel){
11957 this.selModel = new Roo.tree.DefaultSelectionModel();
11959 return this.selModel;
11963 * Retrieve an array of checked nodes, or an array of a specific attribute of checked nodes (e.g. "id")
11964 * @param {String} attribute (optional) Defaults to null (return the actual nodes)
11965 * @param {TreeNode} startNode (optional) The node to start from, defaults to the root
11968 getChecked : function(a, startNode){
11969 startNode = startNode || this.root;
11971 var f = function(){
11972 if(this.attributes.checked){
11973 r.push(!a ? this : (a == 'id' ? this.id : this.attributes[a]));
11976 startNode.cascade(f);
11981 * Expands a specified path in this TreePanel. A path can be retrieved from a node with {@link Roo.data.Node#getPath}
11982 * @param {String} path
11983 * @param {String} attr (optional) The attribute used in the path (see {@link Roo.data.Node#getPath} for more info)
11984 * @param {Function} callback (optional) The callback to call when the expand is complete. The callback will be called with
11985 * (bSuccess, oLastNode) where bSuccess is if the expand was successful and oLastNode is the last node that was expanded.
11987 expandPath : function(path, attr, callback){
11988 attr = attr || "id";
11989 var keys = path.split(this.pathSeparator);
11990 var curNode = this.root;
11991 if(curNode.attributes[attr] != keys[1]){ // invalid root
11993 callback(false, null);
11998 var f = function(){
11999 if(++index == keys.length){
12001 callback(true, curNode);
12005 var c = curNode.findChild(attr, keys[index]);
12008 callback(false, curNode);
12013 c.expand(false, false, f);
12015 curNode.expand(false, false, f);
12019 * Selects the node in this tree at the specified path. A path can be retrieved from a node with {@link Roo.data.Node#getPath}
12020 * @param {String} path
12021 * @param {String} attr (optional) The attribute used in the path (see {@link Roo.data.Node#getPath} for more info)
12022 * @param {Function} callback (optional) The callback to call when the selection is complete. The callback will be called with
12023 * (bSuccess, oSelNode) where bSuccess is if the selection was successful and oSelNode is the selected node.
12025 selectPath : function(path, attr, callback){
12026 attr = attr || "id";
12027 var keys = path.split(this.pathSeparator);
12028 var v = keys.pop();
12029 if(keys.length > 0){
12030 var f = function(success, node){
12031 if(success && node){
12032 var n = node.findChild(attr, v);
12038 }else if(callback){
12039 callback(false, n);
12043 callback(false, n);
12047 this.expandPath(keys.join(this.pathSeparator), attr, f);
12049 this.root.select();
12051 callback(true, this.root);
12056 getTreeEl : function(){
12061 * Trigger rendering of this TreePanel
12063 render : function(){
12064 if (this.innerCt) {
12065 return this; // stop it rendering more than once!!
12068 this.innerCt = this.el.createChild({tag:"ul",
12069 cls:"x-tree-root-ct " +
12070 (this.lines ? "x-tree-lines" : "x-tree-no-lines")});
12072 if(this.containerScroll){
12073 Roo.dd.ScrollManager.register(this.el);
12075 if((this.enableDD || this.enableDrop) && !this.dropZone){
12077 * The dropZone used by this tree if drop is enabled
12078 * @type Roo.tree.TreeDropZone
12080 this.dropZone = new Roo.tree.TreeDropZone(this, this.dropConfig || {
12081 ddGroup: this.ddGroup || "TreeDD", appendOnly: this.ddAppendOnly === true
12084 if((this.enableDD || this.enableDrag) && !this.dragZone){
12086 * The dragZone used by this tree if drag is enabled
12087 * @type Roo.tree.TreeDragZone
12089 this.dragZone = new Roo.tree.TreeDragZone(this, this.dragConfig || {
12090 ddGroup: this.ddGroup || "TreeDD",
12091 scroll: this.ddScroll
12094 this.getSelectionModel().init(this);
12096 Roo.log("ROOT not set in tree");
12099 this.root.render();
12100 if(!this.rootVisible){
12101 this.root.renderChildren();
12107 * Ext JS Library 1.1.1
12108 * Copyright(c) 2006-2007, Ext JS, LLC.
12110 * Originally Released Under LGPL - original licence link has changed is not relivant.
12113 * <script type="text/javascript">
12118 * @class Roo.tree.DefaultSelectionModel
12119 * @extends Roo.util.Observable
12120 * The default single selection for a TreePanel.
12121 * @param {Object} cfg Configuration
12123 Roo.tree.DefaultSelectionModel = function(cfg){
12124 this.selNode = null;
12130 * @event selectionchange
12131 * Fires when the selected node changes
12132 * @param {DefaultSelectionModel} this
12133 * @param {TreeNode} node the new selection
12135 "selectionchange" : true,
12138 * @event beforeselect
12139 * Fires before the selected node changes, return false to cancel the change
12140 * @param {DefaultSelectionModel} this
12141 * @param {TreeNode} node the new selection
12142 * @param {TreeNode} node the old selection
12144 "beforeselect" : true
12147 Roo.tree.DefaultSelectionModel.superclass.constructor.call(this,cfg);
12150 Roo.extend(Roo.tree.DefaultSelectionModel, Roo.util.Observable, {
12151 init : function(tree){
12153 tree.getTreeEl().on("keydown", this.onKeyDown, this);
12154 tree.on("click", this.onNodeClick, this);
12157 onNodeClick : function(node, e){
12158 if (e.ctrlKey && this.selNode == node) {
12159 this.unselect(node);
12167 * @param {TreeNode} node The node to select
12168 * @return {TreeNode} The selected node
12170 select : function(node){
12171 var last = this.selNode;
12172 if(last != node && this.fireEvent('beforeselect', this, node, last) !== false){
12174 last.ui.onSelectedChange(false);
12176 this.selNode = node;
12177 node.ui.onSelectedChange(true);
12178 this.fireEvent("selectionchange", this, node, last);
12185 * @param {TreeNode} node The node to unselect
12187 unselect : function(node){
12188 if(this.selNode == node){
12189 this.clearSelections();
12194 * Clear all selections
12196 clearSelections : function(){
12197 var n = this.selNode;
12199 n.ui.onSelectedChange(false);
12200 this.selNode = null;
12201 this.fireEvent("selectionchange", this, null);
12207 * Get the selected node
12208 * @return {TreeNode} The selected node
12210 getSelectedNode : function(){
12211 return this.selNode;
12215 * Returns true if the node is selected
12216 * @param {TreeNode} node The node to check
12217 * @return {Boolean}
12219 isSelected : function(node){
12220 return this.selNode == node;
12224 * Selects the node above the selected node in the tree, intelligently walking the nodes
12225 * @return TreeNode The new selection
12227 selectPrevious : function(){
12228 var s = this.selNode || this.lastSelNode;
12232 var ps = s.previousSibling;
12234 if(!ps.isExpanded() || ps.childNodes.length < 1){
12235 return this.select(ps);
12237 var lc = ps.lastChild;
12238 while(lc && lc.isExpanded() && lc.childNodes.length > 0){
12241 return this.select(lc);
12243 } else if(s.parentNode && (this.tree.rootVisible || !s.parentNode.isRoot)){
12244 return this.select(s.parentNode);
12250 * Selects the node above the selected node in the tree, intelligently walking the nodes
12251 * @return TreeNode The new selection
12253 selectNext : function(){
12254 var s = this.selNode || this.lastSelNode;
12258 if(s.firstChild && s.isExpanded()){
12259 return this.select(s.firstChild);
12260 }else if(s.nextSibling){
12261 return this.select(s.nextSibling);
12262 }else if(s.parentNode){
12264 s.parentNode.bubble(function(){
12265 if(this.nextSibling){
12266 newS = this.getOwnerTree().selModel.select(this.nextSibling);
12275 onKeyDown : function(e){
12276 var s = this.selNode || this.lastSelNode;
12277 // undesirable, but required
12282 var k = e.getKey();
12290 this.selectPrevious();
12293 e.preventDefault();
12294 if(s.hasChildNodes()){
12295 if(!s.isExpanded()){
12297 }else if(s.firstChild){
12298 this.select(s.firstChild, e);
12303 e.preventDefault();
12304 if(s.hasChildNodes() && s.isExpanded()){
12306 }else if(s.parentNode && (this.tree.rootVisible || s.parentNode != this.tree.getRootNode())){
12307 this.select(s.parentNode, e);
12315 * @class Roo.tree.MultiSelectionModel
12316 * @extends Roo.util.Observable
12317 * Multi selection for a TreePanel.
12318 * @param {Object} cfg Configuration
12320 Roo.tree.MultiSelectionModel = function(){
12321 this.selNodes = [];
12325 * @event selectionchange
12326 * Fires when the selected nodes change
12327 * @param {MultiSelectionModel} this
12328 * @param {Array} nodes Array of the selected nodes
12330 "selectionchange" : true
12332 Roo.tree.MultiSelectionModel.superclass.constructor.call(this,cfg);
12336 Roo.extend(Roo.tree.MultiSelectionModel, Roo.util.Observable, {
12337 init : function(tree){
12339 tree.getTreeEl().on("keydown", this.onKeyDown, this);
12340 tree.on("click", this.onNodeClick, this);
12343 onNodeClick : function(node, e){
12344 this.select(node, e, e.ctrlKey);
12349 * @param {TreeNode} node The node to select
12350 * @param {EventObject} e (optional) An event associated with the selection
12351 * @param {Boolean} keepExisting True to retain existing selections
12352 * @return {TreeNode} The selected node
12354 select : function(node, e, keepExisting){
12355 if(keepExisting !== true){
12356 this.clearSelections(true);
12358 if(this.isSelected(node)){
12359 this.lastSelNode = node;
12362 this.selNodes.push(node);
12363 this.selMap[node.id] = node;
12364 this.lastSelNode = node;
12365 node.ui.onSelectedChange(true);
12366 this.fireEvent("selectionchange", this, this.selNodes);
12372 * @param {TreeNode} node The node to unselect
12374 unselect : function(node){
12375 if(this.selMap[node.id]){
12376 node.ui.onSelectedChange(false);
12377 var sn = this.selNodes;
12380 index = sn.indexOf(node);
12382 for(var i = 0, len = sn.length; i < len; i++){
12390 this.selNodes.splice(index, 1);
12392 delete this.selMap[node.id];
12393 this.fireEvent("selectionchange", this, this.selNodes);
12398 * Clear all selections
12400 clearSelections : function(suppressEvent){
12401 var sn = this.selNodes;
12403 for(var i = 0, len = sn.length; i < len; i++){
12404 sn[i].ui.onSelectedChange(false);
12406 this.selNodes = [];
12408 if(suppressEvent !== true){
12409 this.fireEvent("selectionchange", this, this.selNodes);
12415 * Returns true if the node is selected
12416 * @param {TreeNode} node The node to check
12417 * @return {Boolean}
12419 isSelected : function(node){
12420 return this.selMap[node.id] ? true : false;
12424 * Returns an array of the selected nodes
12427 getSelectedNodes : function(){
12428 return this.selNodes;
12431 onKeyDown : Roo.tree.DefaultSelectionModel.prototype.onKeyDown,
12433 selectNext : Roo.tree.DefaultSelectionModel.prototype.selectNext,
12435 selectPrevious : Roo.tree.DefaultSelectionModel.prototype.selectPrevious
12438 * Ext JS Library 1.1.1
12439 * Copyright(c) 2006-2007, Ext JS, LLC.
12441 * Originally Released Under LGPL - original licence link has changed is not relivant.
12444 * <script type="text/javascript">
12448 * @class Roo.tree.TreeNode
12449 * @extends Roo.data.Node
12450 * @cfg {String} text The text for this node
12451 * @cfg {Boolean} expanded true to start the node expanded
12452 * @cfg {Boolean} allowDrag false to make this node undraggable if DD is on (defaults to true)
12453 * @cfg {Boolean} allowDrop false if this node cannot be drop on
12454 * @cfg {Boolean} disabled true to start the node disabled
12455 * @cfg {String} icon The path to an icon for the node. The preferred way to do this
12456 * is to use the cls or iconCls attributes and add the icon via a CSS background image.
12457 * @cfg {String} cls A css class to be added to the node
12458 * @cfg {String} iconCls A css class to be added to the nodes icon element for applying css background images
12459 * @cfg {String} href URL of the link used for the node (defaults to #)
12460 * @cfg {String} hrefTarget target frame for the link
12461 * @cfg {String} qtip An Ext QuickTip for the node
12462 * @cfg {String} qtipCfg An Ext QuickTip config for the node (used instead of qtip)
12463 * @cfg {Boolean} singleClickExpand True for single click expand on this node
12464 * @cfg {Function} uiProvider A UI <b>class</b> to use for this node (defaults to Roo.tree.TreeNodeUI)
12465 * @cfg {Boolean} checked True to render a checked checkbox for this node, false to render an unchecked checkbox
12466 * (defaults to undefined with no checkbox rendered)
12468 * @param {Object/String} attributes The attributes/config for the node or just a string with the text for the node
12470 Roo.tree.TreeNode = function(attributes){
12471 attributes = attributes || {};
12472 if(typeof attributes == "string"){
12473 attributes = {text: attributes};
12475 this.childrenRendered = false;
12476 this.rendered = false;
12477 Roo.tree.TreeNode.superclass.constructor.call(this, attributes);
12478 this.expanded = attributes.expanded === true;
12479 this.isTarget = attributes.isTarget !== false;
12480 this.draggable = attributes.draggable !== false && attributes.allowDrag !== false;
12481 this.allowChildren = attributes.allowChildren !== false && attributes.allowDrop !== false;
12484 * Read-only. The text for this node. To change it use setText().
12487 this.text = attributes.text;
12489 * True if this node is disabled.
12492 this.disabled = attributes.disabled === true;
12496 * @event textchange
12497 * Fires when the text for this node is changed
12498 * @param {Node} this This node
12499 * @param {String} text The new text
12500 * @param {String} oldText The old text
12502 "textchange" : true,
12504 * @event beforeexpand
12505 * Fires before this node is expanded, return false to cancel.
12506 * @param {Node} this This node
12507 * @param {Boolean} deep
12508 * @param {Boolean} anim
12510 "beforeexpand" : true,
12512 * @event beforecollapse
12513 * Fires before this node is collapsed, return false to cancel.
12514 * @param {Node} this This node
12515 * @param {Boolean} deep
12516 * @param {Boolean} anim
12518 "beforecollapse" : true,
12521 * Fires when this node is expanded
12522 * @param {Node} this This node
12526 * @event disabledchange
12527 * Fires when the disabled status of this node changes
12528 * @param {Node} this This node
12529 * @param {Boolean} disabled
12531 "disabledchange" : true,
12534 * Fires when this node is collapsed
12535 * @param {Node} this This node
12539 * @event beforeclick
12540 * Fires before click processing. Return false to cancel the default action.
12541 * @param {Node} this This node
12542 * @param {Roo.EventObject} e The event object
12544 "beforeclick":true,
12546 * @event checkchange
12547 * Fires when a node with a checkbox's checked property changes
12548 * @param {Node} this This node
12549 * @param {Boolean} checked
12551 "checkchange":true,
12554 * Fires when this node is clicked
12555 * @param {Node} this This node
12556 * @param {Roo.EventObject} e The event object
12561 * Fires when this node is double clicked
12562 * @param {Node} this This node
12563 * @param {Roo.EventObject} e The event object
12567 * @event contextmenu
12568 * Fires when this node is right clicked
12569 * @param {Node} this This node
12570 * @param {Roo.EventObject} e The event object
12572 "contextmenu":true,
12574 * @event beforechildrenrendered
12575 * Fires right before the child nodes for this node are rendered
12576 * @param {Node} this This node
12578 "beforechildrenrendered":true
12581 var uiClass = this.attributes.uiProvider || Roo.tree.TreeNodeUI;
12584 * Read-only. The UI for this node
12587 this.ui = new uiClass(this);
12589 // finally support items[]
12590 if (typeof(this.attributes.items) == 'undefined' || !this.attributes.items) {
12595 Roo.each(this.attributes.items, function(c) {
12596 this.appendChild(Roo.factory(c,Roo.Tree));
12598 delete this.attributes.items;
12603 Roo.extend(Roo.tree.TreeNode, Roo.data.Node, {
12604 preventHScroll: true,
12606 * Returns true if this node is expanded
12607 * @return {Boolean}
12609 isExpanded : function(){
12610 return this.expanded;
12614 * Returns the UI object for this node
12615 * @return {TreeNodeUI}
12617 getUI : function(){
12621 // private override
12622 setFirstChild : function(node){
12623 var of = this.firstChild;
12624 Roo.tree.TreeNode.superclass.setFirstChild.call(this, node);
12625 if(this.childrenRendered && of && node != of){
12626 of.renderIndent(true, true);
12629 this.renderIndent(true, true);
12633 // private override
12634 setLastChild : function(node){
12635 var ol = this.lastChild;
12636 Roo.tree.TreeNode.superclass.setLastChild.call(this, node);
12637 if(this.childrenRendered && ol && node != ol){
12638 ol.renderIndent(true, true);
12641 this.renderIndent(true, true);
12645 // these methods are overridden to provide lazy rendering support
12646 // private override
12647 appendChild : function()
12649 var node = Roo.tree.TreeNode.superclass.appendChild.apply(this, arguments);
12650 if(node && this.childrenRendered){
12653 this.ui.updateExpandIcon();
12657 // private override
12658 removeChild : function(node){
12659 this.ownerTree.getSelectionModel().unselect(node);
12660 Roo.tree.TreeNode.superclass.removeChild.apply(this, arguments);
12661 // if it's been rendered remove dom node
12662 if(this.childrenRendered){
12665 if(this.childNodes.length < 1){
12666 this.collapse(false, false);
12668 this.ui.updateExpandIcon();
12670 if(!this.firstChild) {
12671 this.childrenRendered = false;
12676 // private override
12677 insertBefore : function(node, refNode){
12678 var newNode = Roo.tree.TreeNode.superclass.insertBefore.apply(this, arguments);
12679 if(newNode && refNode && this.childrenRendered){
12682 this.ui.updateExpandIcon();
12687 * Sets the text for this node
12688 * @param {String} text
12690 setText : function(text){
12691 var oldText = this.text;
12693 this.attributes.text = text;
12694 if(this.rendered){ // event without subscribing
12695 this.ui.onTextChange(this, text, oldText);
12697 this.fireEvent("textchange", this, text, oldText);
12701 * Triggers selection of this node
12703 select : function(){
12704 this.getOwnerTree().getSelectionModel().select(this);
12708 * Triggers deselection of this node
12710 unselect : function(){
12711 this.getOwnerTree().getSelectionModel().unselect(this);
12715 * Returns true if this node is selected
12716 * @return {Boolean}
12718 isSelected : function(){
12719 return this.getOwnerTree().getSelectionModel().isSelected(this);
12723 * Expand this node.
12724 * @param {Boolean} deep (optional) True to expand all children as well
12725 * @param {Boolean} anim (optional) false to cancel the default animation
12726 * @param {Function} callback (optional) A callback to be called when
12727 * expanding this node completes (does not wait for deep expand to complete).
12728 * Called with 1 parameter, this node.
12730 expand : function(deep, anim, callback){
12731 if(!this.expanded){
12732 if(this.fireEvent("beforeexpand", this, deep, anim) === false){
12735 if(!this.childrenRendered){
12736 this.renderChildren();
12738 this.expanded = true;
12740 if(!this.isHiddenRoot() && (this.getOwnerTree() && this.getOwnerTree().animate && anim !== false) || anim){
12741 this.ui.animExpand(function(){
12742 this.fireEvent("expand", this);
12743 if(typeof callback == "function"){
12747 this.expandChildNodes(true);
12749 }.createDelegate(this));
12753 this.fireEvent("expand", this);
12754 if(typeof callback == "function"){
12759 if(typeof callback == "function"){
12764 this.expandChildNodes(true);
12768 isHiddenRoot : function(){
12769 return this.isRoot && !this.getOwnerTree().rootVisible;
12773 * Collapse this node.
12774 * @param {Boolean} deep (optional) True to collapse all children as well
12775 * @param {Boolean} anim (optional) false to cancel the default animation
12777 collapse : function(deep, anim){
12778 if(this.expanded && !this.isHiddenRoot()){
12779 if(this.fireEvent("beforecollapse", this, deep, anim) === false){
12782 this.expanded = false;
12783 if((this.getOwnerTree().animate && anim !== false) || anim){
12784 this.ui.animCollapse(function(){
12785 this.fireEvent("collapse", this);
12787 this.collapseChildNodes(true);
12789 }.createDelegate(this));
12792 this.ui.collapse();
12793 this.fireEvent("collapse", this);
12797 var cs = this.childNodes;
12798 for(var i = 0, len = cs.length; i < len; i++) {
12799 cs[i].collapse(true, false);
12805 delayedExpand : function(delay){
12806 if(!this.expandProcId){
12807 this.expandProcId = this.expand.defer(delay, this);
12812 cancelExpand : function(){
12813 if(this.expandProcId){
12814 clearTimeout(this.expandProcId);
12816 this.expandProcId = false;
12820 * Toggles expanded/collapsed state of the node
12822 toggle : function(){
12831 * Ensures all parent nodes are expanded
12833 ensureVisible : function(callback){
12834 var tree = this.getOwnerTree();
12835 tree.expandPath(this.parentNode.getPath(), false, function(){
12836 tree.getTreeEl().scrollChildIntoView(this.ui.anchor);
12837 Roo.callback(callback);
12838 }.createDelegate(this));
12842 * Expand all child nodes
12843 * @param {Boolean} deep (optional) true if the child nodes should also expand their child nodes
12845 expandChildNodes : function(deep){
12846 var cs = this.childNodes;
12847 for(var i = 0, len = cs.length; i < len; i++) {
12848 cs[i].expand(deep);
12853 * Collapse all child nodes
12854 * @param {Boolean} deep (optional) true if the child nodes should also collapse their child nodes
12856 collapseChildNodes : function(deep){
12857 var cs = this.childNodes;
12858 for(var i = 0, len = cs.length; i < len; i++) {
12859 cs[i].collapse(deep);
12864 * Disables this node
12866 disable : function(){
12867 this.disabled = true;
12869 if(this.rendered && this.ui.onDisableChange){ // event without subscribing
12870 this.ui.onDisableChange(this, true);
12872 this.fireEvent("disabledchange", this, true);
12876 * Enables this node
12878 enable : function(){
12879 this.disabled = false;
12880 if(this.rendered && this.ui.onDisableChange){ // event without subscribing
12881 this.ui.onDisableChange(this, false);
12883 this.fireEvent("disabledchange", this, false);
12887 renderChildren : function(suppressEvent){
12888 if(suppressEvent !== false){
12889 this.fireEvent("beforechildrenrendered", this);
12891 var cs = this.childNodes;
12892 for(var i = 0, len = cs.length; i < len; i++){
12893 cs[i].render(true);
12895 this.childrenRendered = true;
12899 sort : function(fn, scope){
12900 Roo.tree.TreeNode.superclass.sort.apply(this, arguments);
12901 if(this.childrenRendered){
12902 var cs = this.childNodes;
12903 for(var i = 0, len = cs.length; i < len; i++){
12904 cs[i].render(true);
12910 render : function(bulkRender){
12911 this.ui.render(bulkRender);
12912 if(!this.rendered){
12913 this.rendered = true;
12915 this.expanded = false;
12916 this.expand(false, false);
12922 renderIndent : function(deep, refresh){
12924 this.ui.childIndent = null;
12926 this.ui.renderIndent();
12927 if(deep === true && this.childrenRendered){
12928 var cs = this.childNodes;
12929 for(var i = 0, len = cs.length; i < len; i++){
12930 cs[i].renderIndent(true, refresh);
12936 * Ext JS Library 1.1.1
12937 * Copyright(c) 2006-2007, Ext JS, LLC.
12939 * Originally Released Under LGPL - original licence link has changed is not relivant.
12942 * <script type="text/javascript">
12946 * @class Roo.tree.AsyncTreeNode
12947 * @extends Roo.tree.TreeNode
12948 * @cfg {TreeLoader} loader A TreeLoader to be used by this node (defaults to the loader defined on the tree)
12950 * @param {Object/String} attributes The attributes/config for the node or just a string with the text for the node
12952 Roo.tree.AsyncTreeNode = function(config){
12953 this.loaded = false;
12954 this.loading = false;
12955 Roo.tree.AsyncTreeNode.superclass.constructor.apply(this, arguments);
12957 * @event beforeload
12958 * Fires before this node is loaded, return false to cancel
12959 * @param {Node} this This node
12961 this.addEvents({'beforeload':true, 'load': true});
12964 * Fires when this node is loaded
12965 * @param {Node} this This node
12968 * The loader used by this node (defaults to using the tree's defined loader)
12973 Roo.extend(Roo.tree.AsyncTreeNode, Roo.tree.TreeNode, {
12974 expand : function(deep, anim, callback){
12975 if(this.loading){ // if an async load is already running, waiting til it's done
12977 var f = function(){
12978 if(!this.loading){ // done loading
12979 clearInterval(timer);
12980 this.expand(deep, anim, callback);
12982 }.createDelegate(this);
12983 timer = setInterval(f, 200);
12987 if(this.fireEvent("beforeload", this) === false){
12990 this.loading = true;
12991 this.ui.beforeLoad(this);
12992 var loader = this.loader || this.attributes.loader || this.getOwnerTree().getLoader();
12994 loader.load(this, this.loadComplete.createDelegate(this, [deep, anim, callback]));
12998 Roo.tree.AsyncTreeNode.superclass.expand.call(this, deep, anim, callback);
13002 * Returns true if this node is currently loading
13003 * @return {Boolean}
13005 isLoading : function(){
13006 return this.loading;
13009 loadComplete : function(deep, anim, callback){
13010 this.loading = false;
13011 this.loaded = true;
13012 this.ui.afterLoad(this);
13013 this.fireEvent("load", this);
13014 this.expand(deep, anim, callback);
13018 * Returns true if this node has been loaded
13019 * @return {Boolean}
13021 isLoaded : function(){
13022 return this.loaded;
13025 hasChildNodes : function(){
13026 if(!this.isLeaf() && !this.loaded){
13029 return Roo.tree.AsyncTreeNode.superclass.hasChildNodes.call(this);
13034 * Trigger a reload for this node
13035 * @param {Function} callback
13037 reload : function(callback){
13038 this.collapse(false, false);
13039 while(this.firstChild){
13040 this.removeChild(this.firstChild);
13042 this.childrenRendered = false;
13043 this.loaded = false;
13044 if(this.isHiddenRoot()){
13045 this.expanded = false;
13047 this.expand(false, false, callback);
13051 * Ext JS Library 1.1.1
13052 * Copyright(c) 2006-2007, Ext JS, LLC.
13054 * Originally Released Under LGPL - original licence link has changed is not relivant.
13057 * <script type="text/javascript">
13061 * @class Roo.tree.TreeNodeUI
13063 * @param {Object} node The node to render
13064 * The TreeNode UI implementation is separate from the
13065 * tree implementation. Unless you are customizing the tree UI,
13066 * you should never have to use this directly.
13068 Roo.tree.TreeNodeUI = function(node){
13070 this.rendered = false;
13071 this.animating = false;
13072 this.emptyIcon = Roo.BLANK_IMAGE_URL;
13075 Roo.tree.TreeNodeUI.prototype = {
13076 removeChild : function(node){
13078 this.ctNode.removeChild(node.ui.getEl());
13082 beforeLoad : function(){
13083 this.addClass("x-tree-node-loading");
13086 afterLoad : function(){
13087 this.removeClass("x-tree-node-loading");
13090 onTextChange : function(node, text, oldText){
13092 this.textNode.innerHTML = text;
13096 onDisableChange : function(node, state){
13097 this.disabled = state;
13099 this.addClass("x-tree-node-disabled");
13101 this.removeClass("x-tree-node-disabled");
13105 onSelectedChange : function(state){
13108 this.addClass("x-tree-selected");
13111 this.removeClass("x-tree-selected");
13115 onMove : function(tree, node, oldParent, newParent, index, refNode){
13116 this.childIndent = null;
13118 var targetNode = newParent.ui.getContainer();
13119 if(!targetNode){//target not rendered
13120 this.holder = document.createElement("div");
13121 this.holder.appendChild(this.wrap);
13124 var insertBefore = refNode ? refNode.ui.getEl() : null;
13126 targetNode.insertBefore(this.wrap, insertBefore);
13128 targetNode.appendChild(this.wrap);
13130 this.node.renderIndent(true);
13134 addClass : function(cls){
13136 Roo.fly(this.elNode).addClass(cls);
13140 removeClass : function(cls){
13142 Roo.fly(this.elNode).removeClass(cls);
13146 remove : function(){
13148 this.holder = document.createElement("div");
13149 this.holder.appendChild(this.wrap);
13153 fireEvent : function(){
13154 return this.node.fireEvent.apply(this.node, arguments);
13157 initEvents : function(){
13158 this.node.on("move", this.onMove, this);
13159 var E = Roo.EventManager;
13160 var a = this.anchor;
13162 var el = Roo.fly(a, '_treeui');
13164 if(Roo.isOpera){ // opera render bug ignores the CSS
13165 el.setStyle("text-decoration", "none");
13168 el.on("click", this.onClick, this);
13169 el.on("dblclick", this.onDblClick, this);
13172 Roo.EventManager.on(this.checkbox,
13173 Roo.isIE ? 'click' : 'change', this.onCheckChange, this);
13176 el.on("contextmenu", this.onContextMenu, this);
13178 var icon = Roo.fly(this.iconNode);
13179 icon.on("click", this.onClick, this);
13180 icon.on("dblclick", this.onDblClick, this);
13181 icon.on("contextmenu", this.onContextMenu, this);
13182 E.on(this.ecNode, "click", this.ecClick, this, true);
13184 if(this.node.disabled){
13185 this.addClass("x-tree-node-disabled");
13187 if(this.node.hidden){
13188 this.addClass("x-tree-node-disabled");
13190 var ot = this.node.getOwnerTree();
13191 var dd = ot ? (ot.enableDD || ot.enableDrag || ot.enableDrop) : false;
13192 if(dd && (!this.node.isRoot || ot.rootVisible)){
13193 Roo.dd.Registry.register(this.elNode, {
13195 handles: this.getDDHandles(),
13201 getDDHandles : function(){
13202 return [this.iconNode, this.textNode];
13207 this.wrap.style.display = "none";
13213 this.wrap.style.display = "";
13217 onContextMenu : function(e){
13218 if (this.node.hasListener("contextmenu") || this.node.getOwnerTree().hasListener("contextmenu")) {
13219 e.preventDefault();
13221 this.fireEvent("contextmenu", this.node, e);
13225 onClick : function(e){
13230 if(this.fireEvent("beforeclick", this.node, e) !== false){
13231 if(!this.disabled && this.node.attributes.href){
13232 this.fireEvent("click", this.node, e);
13235 e.preventDefault();
13240 if(this.node.attributes.singleClickExpand && !this.animating && this.node.hasChildNodes()){
13241 this.node.toggle();
13244 this.fireEvent("click", this.node, e);
13250 onDblClick : function(e){
13251 e.preventDefault();
13256 this.toggleCheck();
13258 if(!this.animating && this.node.hasChildNodes()){
13259 this.node.toggle();
13261 this.fireEvent("dblclick", this.node, e);
13264 onCheckChange : function(){
13265 var checked = this.checkbox.checked;
13266 this.node.attributes.checked = checked;
13267 this.fireEvent('checkchange', this.node, checked);
13270 ecClick : function(e){
13271 if(!this.animating && this.node.hasChildNodes()){
13272 this.node.toggle();
13276 startDrop : function(){
13277 this.dropping = true;
13280 // delayed drop so the click event doesn't get fired on a drop
13281 endDrop : function(){
13282 setTimeout(function(){
13283 this.dropping = false;
13284 }.createDelegate(this), 50);
13287 expand : function(){
13288 this.updateExpandIcon();
13289 this.ctNode.style.display = "";
13292 focus : function(){
13293 if(!this.node.preventHScroll){
13294 try{this.anchor.focus();
13296 }else if(!Roo.isIE){
13298 var noscroll = this.node.getOwnerTree().getTreeEl().dom;
13299 var l = noscroll.scrollLeft;
13300 this.anchor.focus();
13301 noscroll.scrollLeft = l;
13306 toggleCheck : function(value){
13307 var cb = this.checkbox;
13309 cb.checked = (value === undefined ? !cb.checked : value);
13315 this.anchor.blur();
13319 animExpand : function(callback){
13320 var ct = Roo.get(this.ctNode);
13322 if(!this.node.hasChildNodes()){
13323 this.updateExpandIcon();
13324 this.ctNode.style.display = "";
13325 Roo.callback(callback);
13328 this.animating = true;
13329 this.updateExpandIcon();
13332 callback : function(){
13333 this.animating = false;
13334 Roo.callback(callback);
13337 duration: this.node.ownerTree.duration || .25
13341 highlight : function(){
13342 var tree = this.node.getOwnerTree();
13343 Roo.fly(this.wrap).highlight(
13344 tree.hlColor || "C3DAF9",
13345 {endColor: tree.hlBaseColor}
13349 collapse : function(){
13350 this.updateExpandIcon();
13351 this.ctNode.style.display = "none";
13354 animCollapse : function(callback){
13355 var ct = Roo.get(this.ctNode);
13356 ct.enableDisplayMode('block');
13359 this.animating = true;
13360 this.updateExpandIcon();
13363 callback : function(){
13364 this.animating = false;
13365 Roo.callback(callback);
13368 duration: this.node.ownerTree.duration || .25
13372 getContainer : function(){
13373 return this.ctNode;
13376 getEl : function(){
13380 appendDDGhost : function(ghostNode){
13381 ghostNode.appendChild(this.elNode.cloneNode(true));
13384 getDDRepairXY : function(){
13385 return Roo.lib.Dom.getXY(this.iconNode);
13388 onRender : function(){
13392 render : function(bulkRender){
13393 var n = this.node, a = n.attributes;
13394 var targetNode = n.parentNode ?
13395 n.parentNode.ui.getContainer() : n.ownerTree.innerCt.dom;
13397 if(!this.rendered){
13398 this.rendered = true;
13400 this.renderElements(n, a, targetNode, bulkRender);
13403 if(this.textNode.setAttributeNS){
13404 this.textNode.setAttributeNS("ext", "qtip", a.qtip);
13406 this.textNode.setAttributeNS("ext", "qtitle", a.qtipTitle);
13409 this.textNode.setAttribute("ext:qtip", a.qtip);
13411 this.textNode.setAttribute("ext:qtitle", a.qtipTitle);
13414 }else if(a.qtipCfg){
13415 a.qtipCfg.target = Roo.id(this.textNode);
13416 Roo.QuickTips.register(a.qtipCfg);
13419 if(!this.node.expanded){
13420 this.updateExpandIcon();
13423 if(bulkRender === true) {
13424 targetNode.appendChild(this.wrap);
13429 renderElements : function(n, a, targetNode, bulkRender)
13431 // add some indent caching, this helps performance when rendering a large tree
13432 this.indentMarkup = n.parentNode ? n.parentNode.ui.getChildIndent() : '';
13433 var t = n.getOwnerTree();
13434 var txt = t && t.renderer ? t.renderer(n.attributes) : Roo.util.Format.htmlEncode(n.text);
13435 if (typeof(n.attributes.html) != 'undefined') {
13436 txt = n.attributes.html;
13438 var tip = t && t.rendererTip ? t.rendererTip(n.attributes) : txt;
13439 var cb = typeof a.checked == 'boolean';
13440 var href = a.href ? a.href : Roo.isGecko ? "" : "#";
13441 var buf = ['<li class="x-tree-node"><div class="x-tree-node-el ', a.cls,'">',
13442 '<span class="x-tree-node-indent">',this.indentMarkup,"</span>",
13443 '<img src="', this.emptyIcon, '" class="x-tree-ec-icon" />',
13444 '<img src="', a.icon || this.emptyIcon, '" class="x-tree-node-icon',(a.icon ? " x-tree-node-inline-icon" : ""),(a.iconCls ? " "+a.iconCls : ""),'" unselectable="on" />',
13445 cb ? ('<input class="x-tree-node-cb" type="checkbox" ' + (a.checked ? 'checked="checked" />' : ' />')) : '',
13446 '<a hidefocus="on" href="',href,'" tabIndex="1" ',
13447 a.hrefTarget ? ' target="'+a.hrefTarget+'"' : "",
13448 '><span unselectable="on" qtip="' , tip ,'">',txt,"</span></a></div>",
13449 '<ul class="x-tree-node-ct" style="display:none;"></ul>',
13452 if(bulkRender !== true && n.nextSibling && n.nextSibling.ui.getEl()){
13453 this.wrap = Roo.DomHelper.insertHtml("beforeBegin",
13454 n.nextSibling.ui.getEl(), buf.join(""));
13456 this.wrap = Roo.DomHelper.insertHtml("beforeEnd", targetNode, buf.join(""));
13459 this.elNode = this.wrap.childNodes[0];
13460 this.ctNode = this.wrap.childNodes[1];
13461 var cs = this.elNode.childNodes;
13462 this.indentNode = cs[0];
13463 this.ecNode = cs[1];
13464 this.iconNode = cs[2];
13467 this.checkbox = cs[3];
13470 this.anchor = cs[index];
13471 this.textNode = cs[index].firstChild;
13474 getAnchor : function(){
13475 return this.anchor;
13478 getTextEl : function(){
13479 return this.textNode;
13482 getIconEl : function(){
13483 return this.iconNode;
13486 isChecked : function(){
13487 return this.checkbox ? this.checkbox.checked : false;
13490 updateExpandIcon : function(){
13492 var n = this.node, c1, c2;
13493 var cls = n.isLast() ? "x-tree-elbow-end" : "x-tree-elbow";
13494 var hasChild = n.hasChildNodes();
13498 c1 = "x-tree-node-collapsed";
13499 c2 = "x-tree-node-expanded";
13502 c1 = "x-tree-node-expanded";
13503 c2 = "x-tree-node-collapsed";
13506 this.removeClass("x-tree-node-leaf");
13507 this.wasLeaf = false;
13509 if(this.c1 != c1 || this.c2 != c2){
13510 Roo.fly(this.elNode).replaceClass(c1, c2);
13511 this.c1 = c1; this.c2 = c2;
13514 // this changes non-leafs into leafs if they have no children.
13515 // it's not very rational behaviour..
13517 if(!this.wasLeaf && this.node.leaf){
13518 Roo.fly(this.elNode).replaceClass("x-tree-node-expanded", "x-tree-node-leaf");
13521 this.wasLeaf = true;
13524 var ecc = "x-tree-ec-icon "+cls;
13525 if(this.ecc != ecc){
13526 this.ecNode.className = ecc;
13532 getChildIndent : function(){
13533 if(!this.childIndent){
13537 if(!p.isRoot || (p.isRoot && p.ownerTree.rootVisible)){
13539 buf.unshift('<img src="'+this.emptyIcon+'" class="x-tree-elbow-line" />');
13541 buf.unshift('<img src="'+this.emptyIcon+'" class="x-tree-icon" />');
13546 this.childIndent = buf.join("");
13548 return this.childIndent;
13551 renderIndent : function(){
13554 var p = this.node.parentNode;
13556 indent = p.ui.getChildIndent();
13558 if(this.indentMarkup != indent){ // don't rerender if not required
13559 this.indentNode.innerHTML = indent;
13560 this.indentMarkup = indent;
13562 this.updateExpandIcon();
13567 Roo.tree.RootTreeNodeUI = function(){
13568 Roo.tree.RootTreeNodeUI.superclass.constructor.apply(this, arguments);
13570 Roo.extend(Roo.tree.RootTreeNodeUI, Roo.tree.TreeNodeUI, {
13571 render : function(){
13572 if(!this.rendered){
13573 var targetNode = this.node.ownerTree.innerCt.dom;
13574 this.node.expanded = true;
13575 targetNode.innerHTML = '<div class="x-tree-root-node"></div>';
13576 this.wrap = this.ctNode = targetNode.firstChild;
13579 collapse : function(){
13581 expand : function(){
13585 * Ext JS Library 1.1.1
13586 * Copyright(c) 2006-2007, Ext JS, LLC.
13588 * Originally Released Under LGPL - original licence link has changed is not relivant.
13591 * <script type="text/javascript">
13594 * @class Roo.tree.TreeLoader
13595 * @extends Roo.util.Observable
13596 * A TreeLoader provides for lazy loading of an {@link Roo.tree.TreeNode}'s child
13597 * nodes from a specified URL. The response must be a javascript Array definition
13598 * who's elements are node definition objects. eg:
13603 { 'id': 1, 'text': 'A folder Node', 'leaf': false },
13604 { 'id': 2, 'text': 'A leaf Node', 'leaf': true }
13611 * The old style respose with just an array is still supported, but not recommended.
13614 * A server request is sent, and child nodes are loaded only when a node is expanded.
13615 * The loading node's id is passed to the server under the parameter name "node" to
13616 * enable the server to produce the correct child nodes.
13618 * To pass extra parameters, an event handler may be attached to the "beforeload"
13619 * event, and the parameters specified in the TreeLoader's baseParams property:
13621 myTreeLoader.on("beforeload", function(treeLoader, node) {
13622 this.baseParams.category = node.attributes.category;
13627 * This would pass an HTTP parameter called "category" to the server containing
13628 * the value of the Node's "category" attribute.
13630 * Creates a new Treeloader.
13631 * @param {Object} config A config object containing config properties.
13633 Roo.tree.TreeLoader = function(config){
13634 this.baseParams = {};
13635 this.requestMethod = "POST";
13636 Roo.apply(this, config);
13641 * @event beforeload
13642 * Fires before a network request is made to retrieve the Json text which specifies a node's children.
13643 * @param {Object} This TreeLoader object.
13644 * @param {Object} node The {@link Roo.tree.TreeNode} object being loaded.
13645 * @param {Object} callback The callback function specified in the {@link #load} call.
13650 * Fires when the node has been successfuly loaded.
13651 * @param {Object} This TreeLoader object.
13652 * @param {Object} node The {@link Roo.tree.TreeNode} object being loaded.
13653 * @param {Object} response The response object containing the data from the server.
13657 * @event loadexception
13658 * Fires if the network request failed.
13659 * @param {Object} This TreeLoader object.
13660 * @param {Object} node The {@link Roo.tree.TreeNode} object being loaded.
13661 * @param {Object} response The response object containing the data from the server.
13663 loadexception : true,
13666 * Fires before a node is created, enabling you to return custom Node types
13667 * @param {Object} This TreeLoader object.
13668 * @param {Object} attr - the data returned from the AJAX call (modify it to suit)
13673 Roo.tree.TreeLoader.superclass.constructor.call(this);
13676 Roo.extend(Roo.tree.TreeLoader, Roo.util.Observable, {
13678 * @cfg {String} dataUrl The URL from which to request a Json string which
13679 * specifies an array of node definition object representing the child nodes
13683 * @cfg {String} requestMethod either GET or POST
13684 * defaults to POST (due to BC)
13688 * @cfg {Object} baseParams (optional) An object containing properties which
13689 * specify HTTP parameters to be passed to each request for child nodes.
13692 * @cfg {Object} baseAttrs (optional) An object containing attributes to be added to all nodes
13693 * created by this loader. If the attributes sent by the server have an attribute in this object,
13694 * they take priority.
13697 * @cfg {Object} uiProviders (optional) An object containing properties which
13699 * DEPRECATED - use 'create' event handler to modify attributes - which affect creation.
13700 * specify custom {@link Roo.tree.TreeNodeUI} implementations. If the optional
13701 * <i>uiProvider</i> attribute of a returned child node is a string rather
13702 * than a reference to a TreeNodeUI implementation, this that string value
13703 * is used as a property name in the uiProviders object. You can define the provider named
13704 * 'default' , and this will be used for all nodes (if no uiProvider is delivered by the node data)
13709 * @cfg {Boolean} clearOnLoad (optional) Default to true. Remove previously existing
13710 * child nodes before loading.
13712 clearOnLoad : true,
13715 * @cfg {String} root (optional) Default to false. Use this to read data from an object
13716 * property on loading, rather than expecting an array. (eg. more compatible to a standard
13717 * Grid query { data : [ .....] }
13722 * @cfg {String} queryParam (optional)
13723 * Name of the query as it will be passed on the querystring (defaults to 'node')
13724 * eg. the request will be ?node=[id]
13731 * Load an {@link Roo.tree.TreeNode} from the URL specified in the constructor.
13732 * This is called automatically when a node is expanded, but may be used to reload
13733 * a node (or append new children if the {@link #clearOnLoad} option is false.)
13734 * @param {Roo.tree.TreeNode} node
13735 * @param {Function} callback
13737 load : function(node, callback){
13738 if(this.clearOnLoad){
13739 while(node.firstChild){
13740 node.removeChild(node.firstChild);
13743 if(node.attributes.children){ // preloaded json children
13744 var cs = node.attributes.children;
13745 for(var i = 0, len = cs.length; i < len; i++){
13746 node.appendChild(this.createNode(cs[i]));
13748 if(typeof callback == "function"){
13751 }else if(this.dataUrl){
13752 this.requestData(node, callback);
13756 getParams: function(node){
13757 var buf = [], bp = this.baseParams;
13758 for(var key in bp){
13759 if(typeof bp[key] != "function"){
13760 buf.push(encodeURIComponent(key), "=", encodeURIComponent(bp[key]), "&");
13763 var n = this.queryParam === false ? 'node' : this.queryParam;
13764 buf.push(n + "=", encodeURIComponent(node.id));
13765 return buf.join("");
13768 requestData : function(node, callback){
13769 if(this.fireEvent("beforeload", this, node, callback) !== false){
13770 this.transId = Roo.Ajax.request({
13771 method:this.requestMethod,
13772 url: this.dataUrl||this.url,
13773 success: this.handleResponse,
13774 failure: this.handleFailure,
13776 argument: {callback: callback, node: node},
13777 params: this.getParams(node)
13780 // if the load is cancelled, make sure we notify
13781 // the node that we are done
13782 if(typeof callback == "function"){
13788 isLoading : function(){
13789 return this.transId ? true : false;
13792 abort : function(){
13793 if(this.isLoading()){
13794 Roo.Ajax.abort(this.transId);
13799 createNode : function(attr)
13801 // apply baseAttrs, nice idea Corey!
13802 if(this.baseAttrs){
13803 Roo.applyIf(attr, this.baseAttrs);
13805 if(this.applyLoader !== false){
13806 attr.loader = this;
13808 // uiProvider = depreciated..
13810 if(typeof(attr.uiProvider) == 'string'){
13811 attr.uiProvider = this.uiProviders[attr.uiProvider] ||
13812 /** eval:var:attr */ eval(attr.uiProvider);
13814 if(typeof(this.uiProviders['default']) != 'undefined') {
13815 attr.uiProvider = this.uiProviders['default'];
13818 this.fireEvent('create', this, attr);
13820 attr.leaf = typeof(attr.leaf) == 'string' ? attr.leaf * 1 : attr.leaf;
13822 new Roo.tree.TreeNode(attr) :
13823 new Roo.tree.AsyncTreeNode(attr));
13826 processResponse : function(response, node, callback)
13828 var json = response.responseText;
13831 var o = Roo.decode(json);
13833 if (this.root === false && typeof(o.success) != undefined) {
13834 this.root = 'data'; // the default behaviour for list like data..
13837 if (this.root !== false && !o.success) {
13838 // it's a failure condition.
13839 var a = response.argument;
13840 this.fireEvent("loadexception", this, a.node, response);
13841 Roo.log("Load failed - should have a handler really");
13847 if (this.root !== false) {
13851 for(var i = 0, len = o.length; i < len; i++){
13852 var n = this.createNode(o[i]);
13854 node.appendChild(n);
13857 if(typeof callback == "function"){
13858 callback(this, node);
13861 this.handleFailure(response);
13865 handleResponse : function(response){
13866 this.transId = false;
13867 var a = response.argument;
13868 this.processResponse(response, a.node, a.callback);
13869 this.fireEvent("load", this, a.node, response);
13872 handleFailure : function(response)
13874 // should handle failure better..
13875 this.transId = false;
13876 var a = response.argument;
13877 this.fireEvent("loadexception", this, a.node, response);
13878 if(typeof a.callback == "function"){
13879 a.callback(this, a.node);
13884 * Ext JS Library 1.1.1
13885 * Copyright(c) 2006-2007, Ext JS, LLC.
13887 * Originally Released Under LGPL - original licence link has changed is not relivant.
13890 * <script type="text/javascript">
13894 * @class Roo.tree.TreeFilter
13895 * Note this class is experimental and doesn't update the indent (lines) or expand collapse icons of the nodes
13896 * @param {TreePanel} tree
13897 * @param {Object} config (optional)
13899 Roo.tree.TreeFilter = function(tree, config){
13901 this.filtered = {};
13902 Roo.apply(this, config);
13905 Roo.tree.TreeFilter.prototype = {
13912 * Filter the data by a specific attribute.
13913 * @param {String/RegExp} value Either string that the attribute value
13914 * should start with or a RegExp to test against the attribute
13915 * @param {String} attr (optional) The attribute passed in your node's attributes collection. Defaults to "text".
13916 * @param {TreeNode} startNode (optional) The node to start the filter at.
13918 filter : function(value, attr, startNode){
13919 attr = attr || "text";
13921 if(typeof value == "string"){
13922 var vlen = value.length;
13923 // auto clear empty filter
13924 if(vlen == 0 && this.clearBlank){
13928 value = value.toLowerCase();
13930 return n.attributes[attr].substr(0, vlen).toLowerCase() == value;
13932 }else if(value.exec){ // regex?
13934 return value.test(n.attributes[attr]);
13937 throw 'Illegal filter type, must be string or regex';
13939 this.filterBy(f, null, startNode);
13943 * Filter by a function. The passed function will be called with each
13944 * node in the tree (or from the startNode). If the function returns true, the node is kept
13945 * otherwise it is filtered. If a node is filtered, its children are also filtered.
13946 * @param {Function} fn The filter function
13947 * @param {Object} scope (optional) The scope of the function (defaults to the current node)
13949 filterBy : function(fn, scope, startNode){
13950 startNode = startNode || this.tree.root;
13951 if(this.autoClear){
13954 var af = this.filtered, rv = this.reverse;
13955 var f = function(n){
13956 if(n == startNode){
13962 var m = fn.call(scope || n, n);
13970 startNode.cascade(f);
13973 if(typeof id != "function"){
13975 if(n && n.parentNode){
13976 n.parentNode.removeChild(n);
13984 * Clears the current filter. Note: with the "remove" option
13985 * set a filter cannot be cleared.
13987 clear : function(){
13989 var af = this.filtered;
13991 if(typeof id != "function"){
13998 this.filtered = {};
14003 * Ext JS Library 1.1.1
14004 * Copyright(c) 2006-2007, Ext JS, LLC.
14006 * Originally Released Under LGPL - original licence link has changed is not relivant.
14009 * <script type="text/javascript">
14014 * @class Roo.tree.TreeSorter
14015 * Provides sorting of nodes in a TreePanel
14017 * @cfg {Boolean} folderSort True to sort leaf nodes under non leaf nodes
14018 * @cfg {String} property The named attribute on the node to sort by (defaults to text)
14019 * @cfg {String} dir The direction to sort (asc or desc) (defaults to asc)
14020 * @cfg {String} leafAttr The attribute used to determine leaf nodes in folder sort (defaults to "leaf")
14021 * @cfg {Boolean} caseSensitive true for case sensitive sort (defaults to false)
14022 * @cfg {Function} sortType A custom "casting" function used to convert node values before sorting
14024 * @param {TreePanel} tree
14025 * @param {Object} config
14027 Roo.tree.TreeSorter = function(tree, config){
14028 Roo.apply(this, config);
14029 tree.on("beforechildrenrendered", this.doSort, this);
14030 tree.on("append", this.updateSort, this);
14031 tree.on("insert", this.updateSort, this);
14033 var dsc = this.dir && this.dir.toLowerCase() == "desc";
14034 var p = this.property || "text";
14035 var sortType = this.sortType;
14036 var fs = this.folderSort;
14037 var cs = this.caseSensitive === true;
14038 var leafAttr = this.leafAttr || 'leaf';
14040 this.sortFn = function(n1, n2){
14042 if(n1.attributes[leafAttr] && !n2.attributes[leafAttr]){
14045 if(!n1.attributes[leafAttr] && n2.attributes[leafAttr]){
14049 var v1 = sortType ? sortType(n1) : (cs ? n1.attributes[p] : n1.attributes[p].toUpperCase());
14050 var v2 = sortType ? sortType(n2) : (cs ? n2.attributes[p] : n2.attributes[p].toUpperCase());
14052 return dsc ? +1 : -1;
14054 return dsc ? -1 : +1;
14061 Roo.tree.TreeSorter.prototype = {
14062 doSort : function(node){
14063 node.sort(this.sortFn);
14066 compareNodes : function(n1, n2){
14067 return (n1.text.toUpperCase() > n2.text.toUpperCase() ? 1 : -1);
14070 updateSort : function(tree, node){
14071 if(node.childrenRendered){
14072 this.doSort.defer(1, this, [node]);
14077 * Ext JS Library 1.1.1
14078 * Copyright(c) 2006-2007, Ext JS, LLC.
14080 * Originally Released Under LGPL - original licence link has changed is not relivant.
14083 * <script type="text/javascript">
14086 if(Roo.dd.DropZone){
14088 Roo.tree.TreeDropZone = function(tree, config){
14089 this.allowParentInsert = false;
14090 this.allowContainerDrop = false;
14091 this.appendOnly = false;
14092 Roo.tree.TreeDropZone.superclass.constructor.call(this, tree.innerCt, config);
14094 this.lastInsertClass = "x-tree-no-status";
14095 this.dragOverData = {};
14098 Roo.extend(Roo.tree.TreeDropZone, Roo.dd.DropZone, {
14099 ddGroup : "TreeDD",
14102 expandDelay : 1000,
14104 expandNode : function(node){
14105 if(node.hasChildNodes() && !node.isExpanded()){
14106 node.expand(false, null, this.triggerCacheRefresh.createDelegate(this));
14110 queueExpand : function(node){
14111 this.expandProcId = this.expandNode.defer(this.expandDelay, this, [node]);
14114 cancelExpand : function(){
14115 if(this.expandProcId){
14116 clearTimeout(this.expandProcId);
14117 this.expandProcId = false;
14121 isValidDropPoint : function(n, pt, dd, e, data){
14122 if(!n || !data){ return false; }
14123 var targetNode = n.node;
14124 var dropNode = data.node;
14125 // default drop rules
14126 if(!(targetNode && targetNode.isTarget && pt)){
14129 if(pt == "append" && targetNode.allowChildren === false){
14132 if((pt == "above" || pt == "below") && (targetNode.parentNode && targetNode.parentNode.allowChildren === false)){
14135 if(dropNode && (targetNode == dropNode || dropNode.contains(targetNode))){
14138 // reuse the object
14139 var overEvent = this.dragOverData;
14140 overEvent.tree = this.tree;
14141 overEvent.target = targetNode;
14142 overEvent.data = data;
14143 overEvent.point = pt;
14144 overEvent.source = dd;
14145 overEvent.rawEvent = e;
14146 overEvent.dropNode = dropNode;
14147 overEvent.cancel = false;
14148 var result = this.tree.fireEvent("nodedragover", overEvent);
14149 return overEvent.cancel === false && result !== false;
14152 getDropPoint : function(e, n, dd)
14156 return tn.allowChildren !== false ? "append" : false; // always append for root
14158 var dragEl = n.ddel;
14159 var t = Roo.lib.Dom.getY(dragEl), b = t + dragEl.offsetHeight;
14160 var y = Roo.lib.Event.getPageY(e);
14161 //var noAppend = tn.allowChildren === false || tn.isLeaf();
14163 // we may drop nodes anywhere, as long as allowChildren has not been set to false..
14164 var noAppend = tn.allowChildren === false;
14165 if(this.appendOnly || tn.parentNode.allowChildren === false){
14166 return noAppend ? false : "append";
14168 var noBelow = false;
14169 if(!this.allowParentInsert){
14170 noBelow = tn.hasChildNodes() && tn.isExpanded();
14172 var q = (b - t) / (noAppend ? 2 : 3);
14173 if(y >= t && y < (t + q)){
14175 }else if(!noBelow && (noAppend || y >= b-q && y <= b)){
14182 onNodeEnter : function(n, dd, e, data)
14184 this.cancelExpand();
14187 onNodeOver : function(n, dd, e, data)
14190 var pt = this.getDropPoint(e, n, dd);
14193 // auto node expand check
14194 if(!this.expandProcId && pt == "append" && node.hasChildNodes() && !n.node.isExpanded()){
14195 this.queueExpand(node);
14196 }else if(pt != "append"){
14197 this.cancelExpand();
14200 // set the insert point style on the target node
14201 var returnCls = this.dropNotAllowed;
14202 if(this.isValidDropPoint(n, pt, dd, e, data)){
14207 returnCls = n.node.isFirst() ? "x-tree-drop-ok-above" : "x-tree-drop-ok-between";
14208 cls = "x-tree-drag-insert-above";
14209 }else if(pt == "below"){
14210 returnCls = n.node.isLast() ? "x-tree-drop-ok-below" : "x-tree-drop-ok-between";
14211 cls = "x-tree-drag-insert-below";
14213 returnCls = "x-tree-drop-ok-append";
14214 cls = "x-tree-drag-append";
14216 if(this.lastInsertClass != cls){
14217 Roo.fly(el).replaceClass(this.lastInsertClass, cls);
14218 this.lastInsertClass = cls;
14225 onNodeOut : function(n, dd, e, data){
14227 this.cancelExpand();
14228 this.removeDropIndicators(n);
14231 onNodeDrop : function(n, dd, e, data){
14232 var point = this.getDropPoint(e, n, dd);
14233 var targetNode = n.node;
14234 targetNode.ui.startDrop();
14235 if(!this.isValidDropPoint(n, point, dd, e, data)){
14236 targetNode.ui.endDrop();
14239 // first try to find the drop node
14240 var dropNode = data.node || (dd.getTreeNode ? dd.getTreeNode(data, targetNode, point, e) : null);
14243 target: targetNode,
14248 dropNode: dropNode,
14251 var retval = this.tree.fireEvent("beforenodedrop", dropEvent);
14252 if(retval === false || dropEvent.cancel === true || !dropEvent.dropNode){
14253 targetNode.ui.endDrop();
14256 // allow target changing
14257 targetNode = dropEvent.target;
14258 if(point == "append" && !targetNode.isExpanded()){
14259 targetNode.expand(false, null, function(){
14260 this.completeDrop(dropEvent);
14261 }.createDelegate(this));
14263 this.completeDrop(dropEvent);
14268 completeDrop : function(de){
14269 var ns = de.dropNode, p = de.point, t = de.target;
14270 if(!(ns instanceof Array)){
14274 for(var i = 0, len = ns.length; i < len; i++){
14277 t.parentNode.insertBefore(n, t);
14278 }else if(p == "below"){
14279 t.parentNode.insertBefore(n, t.nextSibling);
14285 if(this.tree.hlDrop){
14289 this.tree.fireEvent("nodedrop", de);
14292 afterNodeMoved : function(dd, data, e, targetNode, dropNode){
14293 if(this.tree.hlDrop){
14294 dropNode.ui.focus();
14295 dropNode.ui.highlight();
14297 this.tree.fireEvent("nodedrop", this.tree, targetNode, data, dd, e);
14300 getTree : function(){
14304 removeDropIndicators : function(n){
14307 Roo.fly(el).removeClass([
14308 "x-tree-drag-insert-above",
14309 "x-tree-drag-insert-below",
14310 "x-tree-drag-append"]);
14311 this.lastInsertClass = "_noclass";
14315 beforeDragDrop : function(target, e, id){
14316 this.cancelExpand();
14320 afterRepair : function(data){
14321 if(data && Roo.enableFx){
14322 data.node.ui.highlight();
14332 * Ext JS Library 1.1.1
14333 * Copyright(c) 2006-2007, Ext JS, LLC.
14335 * Originally Released Under LGPL - original licence link has changed is not relivant.
14338 * <script type="text/javascript">
14342 if(Roo.dd.DragZone){
14343 Roo.tree.TreeDragZone = function(tree, config){
14344 Roo.tree.TreeDragZone.superclass.constructor.call(this, tree.getTreeEl(), config);
14348 Roo.extend(Roo.tree.TreeDragZone, Roo.dd.DragZone, {
14349 ddGroup : "TreeDD",
14351 onBeforeDrag : function(data, e){
14353 return n && n.draggable && !n.disabled;
14357 onInitDrag : function(e){
14358 var data = this.dragData;
14359 this.tree.getSelectionModel().select(data.node);
14360 this.proxy.update("");
14361 data.node.ui.appendDDGhost(this.proxy.ghost.dom);
14362 this.tree.fireEvent("startdrag", this.tree, data.node, e);
14365 getRepairXY : function(e, data){
14366 return data.node.ui.getDDRepairXY();
14369 onEndDrag : function(data, e){
14370 this.tree.fireEvent("enddrag", this.tree, data.node, e);
14375 onValidDrop : function(dd, e, id){
14376 this.tree.fireEvent("dragdrop", this.tree, this.dragData.node, dd, e);
14380 beforeInvalidDrop : function(e, id){
14381 // this scrolls the original position back into view
14382 var sm = this.tree.getSelectionModel();
14383 sm.clearSelections();
14384 sm.select(this.dragData.node);
14389 * Ext JS Library 1.1.1
14390 * Copyright(c) 2006-2007, Ext JS, LLC.
14392 * Originally Released Under LGPL - original licence link has changed is not relivant.
14395 * <script type="text/javascript">
14398 * @class Roo.tree.TreeEditor
14399 * @extends Roo.Editor
14400 * Provides editor functionality for inline tree node editing. Any valid {@link Roo.form.Field} can be used
14401 * as the editor field.
14403 * @param {Object} config (used to be the tree panel.)
14404 * @param {Object} oldconfig DEPRECIATED Either a prebuilt {@link Roo.form.Field} instance or a Field config object
14406 * @cfg {Roo.tree.TreePanel} tree The tree to bind to.
14407 * @cfg {Roo.form.TextField|Object} field The field configuration
14411 Roo.tree.TreeEditor = function(config, oldconfig) { // was -- (tree, config){
14414 if (oldconfig) { // old style..
14415 field = oldconfig.events ? oldconfig : new Roo.form.TextField(oldconfig);
14418 tree = config.tree;
14419 config.field = config.field || {};
14420 config.field.xtype = 'TextField';
14421 field = Roo.factory(config.field, Roo.form);
14423 config = config || {};
14428 * @event beforenodeedit
14429 * Fires when editing is initiated, but before the value changes. Editing can be canceled by returning
14430 * false from the handler of this event.
14431 * @param {Editor} this
14432 * @param {Roo.tree.Node} node
14434 "beforenodeedit" : true
14438 Roo.tree.TreeEditor.superclass.constructor.call(this, field, config);
14442 tree.on('beforeclick', this.beforeNodeClick, this);
14443 tree.getTreeEl().on('mousedown', this.hide, this);
14444 this.on('complete', this.updateNode, this);
14445 this.on('beforestartedit', this.fitToTree, this);
14446 this.on('startedit', this.bindScroll, this, {delay:10});
14447 this.on('specialkey', this.onSpecialKey, this);
14450 Roo.extend(Roo.tree.TreeEditor, Roo.Editor, {
14452 * @cfg {String} alignment
14453 * The position to align to (see {@link Roo.Element#alignTo} for more details, defaults to "l-l").
14459 * @cfg {Boolean} hideEl
14460 * True to hide the bound element while the editor is displayed (defaults to false)
14464 * @cfg {String} cls
14465 * CSS class to apply to the editor (defaults to "x-small-editor x-tree-editor")
14467 cls: "x-small-editor x-tree-editor",
14469 * @cfg {Boolean} shim
14470 * True to shim the editor if selects/iframes could be displayed beneath it (defaults to false)
14476 * @cfg {Number} maxWidth
14477 * The maximum width in pixels of the editor field (defaults to 250). Note that if the maxWidth would exceed
14478 * the containing tree element's size, it will be automatically limited for you to the container width, taking
14479 * scroll and client offsets into account prior to each edit.
14486 fitToTree : function(ed, el){
14487 var td = this.tree.getTreeEl().dom, nd = el.dom;
14488 if(td.scrollLeft > nd.offsetLeft){ // ensure the node left point is visible
14489 td.scrollLeft = nd.offsetLeft;
14493 (td.clientWidth > 20 ? td.clientWidth : td.offsetWidth) - Math.max(0, nd.offsetLeft-td.scrollLeft) - /*cushion*/5);
14494 this.setSize(w, '');
14496 return this.fireEvent('beforenodeedit', this, this.editNode);
14501 triggerEdit : function(node){
14502 this.completeEdit();
14503 this.editNode = node;
14504 this.startEdit(node.ui.textNode, node.text);
14508 bindScroll : function(){
14509 this.tree.getTreeEl().on('scroll', this.cancelEdit, this);
14513 beforeNodeClick : function(node, e){
14514 var sinceLast = (this.lastClick ? this.lastClick.getElapsed() : 0);
14515 this.lastClick = new Date();
14516 if(sinceLast > this.editDelay && this.tree.getSelectionModel().isSelected(node)){
14518 this.triggerEdit(node);
14525 updateNode : function(ed, value){
14526 this.tree.getTreeEl().un('scroll', this.cancelEdit, this);
14527 this.editNode.setText(value);
14531 onHide : function(){
14532 Roo.tree.TreeEditor.superclass.onHide.call(this);
14534 this.editNode.ui.focus();
14539 onSpecialKey : function(field, e){
14540 var k = e.getKey();
14544 }else if(k == e.ENTER && !e.hasModifier()){
14546 this.completeEdit();
14549 });//<Script type="text/javascript">
14552 * Ext JS Library 1.1.1
14553 * Copyright(c) 2006-2007, Ext JS, LLC.
14555 * Originally Released Under LGPL - original licence link has changed is not relivant.
14558 * <script type="text/javascript">
14562 * Not documented??? - probably should be...
14565 Roo.tree.ColumnNodeUI = Roo.extend(Roo.tree.TreeNodeUI, {
14566 //focus: Roo.emptyFn, // prevent odd scrolling behavior
14568 renderElements : function(n, a, targetNode, bulkRender){
14569 //consel.log("renderElements?");
14570 this.indentMarkup = n.parentNode ? n.parentNode.ui.getChildIndent() : '';
14572 var t = n.getOwnerTree();
14573 var tid = Pman.Tab.Document_TypesTree.tree.el.id;
14575 var cols = t.columns;
14576 var bw = t.borderWidth;
14578 var href = a.href ? a.href : Roo.isGecko ? "" : "#";
14579 var cb = typeof a.checked == "boolean";
14580 var tx = String.format('{0}',n.text || (c.renderer ? c.renderer(a[c.dataIndex], n, a) : a[c.dataIndex]));
14581 var colcls = 'x-t-' + tid + '-c0';
14583 '<li class="x-tree-node">',
14586 '<div class="x-tree-node-el ', a.cls,'">',
14588 '<div class="x-tree-col ', colcls, '" style="width:', c.width-bw, 'px;">',
14591 '<span class="x-tree-node-indent">',this.indentMarkup,'</span>',
14592 '<img src="', this.emptyIcon, '" class="x-tree-ec-icon " />',
14593 '<img src="', a.icon || this.emptyIcon, '" class="x-tree-node-icon',
14594 (a.icon ? ' x-tree-node-inline-icon' : ''),
14595 (a.iconCls ? ' '+a.iconCls : ''),
14596 '" unselectable="on" />',
14597 (cb ? ('<input class="x-tree-node-cb" type="checkbox" ' +
14598 (a.checked ? 'checked="checked" />' : ' />')) : ''),
14600 '<a class="x-tree-node-anchor" hidefocus="on" href="',href,'" tabIndex="1" ',
14601 (a.hrefTarget ? ' target="' +a.hrefTarget + '"' : ''), '>',
14602 '<span unselectable="on" qtip="' + tx + '">',
14606 '<a class="x-tree-node-anchor" hidefocus="on" href="',href,'" tabIndex="1" ',
14607 (a.hrefTarget ? ' target="' +a.hrefTarget + '"' : ''), '>'
14609 for(var i = 1, len = cols.length; i < len; i++){
14611 colcls = 'x-t-' + tid + '-c' +i;
14612 tx = String.format('{0}', (c.renderer ? c.renderer(a[c.dataIndex], n, a) : a[c.dataIndex]));
14613 buf.push('<div class="x-tree-col ', colcls, ' ' ,(c.cls?c.cls:''),'" style="width:',c.width-bw,'px;">',
14614 '<div class="x-tree-col-text" qtip="' + tx +'">',tx,"</div>",
14620 '<div class="x-clear"></div></div>',
14621 '<ul class="x-tree-node-ct" style="display:none;"></ul>',
14624 if(bulkRender !== true && n.nextSibling && n.nextSibling.ui.getEl()){
14625 this.wrap = Roo.DomHelper.insertHtml("beforeBegin",
14626 n.nextSibling.ui.getEl(), buf.join(""));
14628 this.wrap = Roo.DomHelper.insertHtml("beforeEnd", targetNode, buf.join(""));
14630 var el = this.wrap.firstChild;
14632 this.elNode = el.firstChild;
14633 this.ranchor = el.childNodes[1];
14634 this.ctNode = this.wrap.childNodes[1];
14635 var cs = el.firstChild.childNodes;
14636 this.indentNode = cs[0];
14637 this.ecNode = cs[1];
14638 this.iconNode = cs[2];
14641 this.checkbox = cs[3];
14644 this.anchor = cs[index];
14646 this.textNode = cs[index].firstChild;
14648 //el.on("click", this.onClick, this);
14649 //el.on("dblclick", this.onDblClick, this);
14652 // console.log(this);
14654 initEvents : function(){
14655 Roo.tree.ColumnNodeUI.superclass.initEvents.call(this);
14658 var a = this.ranchor;
14660 var el = Roo.get(a);
14662 if(Roo.isOpera){ // opera render bug ignores the CSS
14663 el.setStyle("text-decoration", "none");
14666 el.on("click", this.onClick, this);
14667 el.on("dblclick", this.onDblClick, this);
14668 el.on("contextmenu", this.onContextMenu, this);
14672 /*onSelectedChange : function(state){
14675 this.addClass("x-tree-selected");
14678 this.removeClass("x-tree-selected");
14681 addClass : function(cls){
14683 Roo.fly(this.elRow).addClass(cls);
14689 removeClass : function(cls){
14691 Roo.fly(this.elRow).removeClass(cls);
14697 });//<Script type="text/javascript">
14701 * Ext JS Library 1.1.1
14702 * Copyright(c) 2006-2007, Ext JS, LLC.
14704 * Originally Released Under LGPL - original licence link has changed is not relivant.
14707 * <script type="text/javascript">
14712 * @class Roo.tree.ColumnTree
14713 * @extends Roo.data.TreePanel
14714 * @cfg {Object} columns Including width, header, renderer, cls, dataIndex
14715 * @cfg {int} borderWidth compined right/left border allowance
14717 * @param {String/HTMLElement/Element} el The container element
14718 * @param {Object} config
14720 Roo.tree.ColumnTree = function(el, config)
14722 Roo.tree.ColumnTree.superclass.constructor.call(this, el , config);
14726 * Fire this event on a container when it resizes
14727 * @param {int} w Width
14728 * @param {int} h Height
14732 this.on('resize', this.onResize, this);
14735 Roo.extend(Roo.tree.ColumnTree, Roo.tree.TreePanel, {
14739 borderWidth: Roo.isBorderBox ? 0 : 2,
14742 render : function(){
14743 // add the header.....
14745 Roo.tree.ColumnTree.superclass.render.apply(this);
14747 this.el.addClass('x-column-tree');
14749 this.headers = this.el.createChild(
14750 {cls:'x-tree-headers'},this.innerCt.dom);
14752 var cols = this.columns, c;
14753 var totalWidth = 0;
14755 var len = cols.length;
14756 for(var i = 0; i < len; i++){
14758 totalWidth += c.width;
14759 this.headEls.push(this.headers.createChild({
14760 cls:'x-tree-hd ' + (c.cls?c.cls+'-hd':''),
14762 cls:'x-tree-hd-text',
14765 style:'width:'+(c.width-this.borderWidth)+'px;'
14768 this.headers.createChild({cls:'x-clear'});
14769 // prevent floats from wrapping when clipped
14770 this.headers.setWidth(totalWidth);
14771 //this.innerCt.setWidth(totalWidth);
14772 this.innerCt.setStyle({ overflow: 'auto' });
14773 this.onResize(this.width, this.height);
14777 onResize : function(w,h)
14782 this.innerCt.setWidth(this.width);
14783 this.innerCt.setHeight(this.height-20);
14786 var cols = this.columns, c;
14787 var totalWidth = 0;
14789 var len = cols.length;
14790 for(var i = 0; i < len; i++){
14792 if (this.autoExpandColumn !== false && c.dataIndex == this.autoExpandColumn) {
14793 // it's the expander..
14794 expEl = this.headEls[i];
14797 totalWidth += c.width;
14801 expEl.setWidth( ((w - totalWidth)-this.borderWidth - 20));
14803 this.headers.setWidth(w-20);
14812 * Ext JS Library 1.1.1
14813 * Copyright(c) 2006-2007, Ext JS, LLC.
14815 * Originally Released Under LGPL - original licence link has changed is not relivant.
14818 * <script type="text/javascript">
14822 * @class Roo.menu.Menu
14823 * @extends Roo.util.Observable
14824 * A menu object. This is the container to which you add all other menu items. Menu can also serve a as a base class
14825 * when you want a specialzed menu based off of another component (like {@link Roo.menu.DateMenu} for example).
14827 * Creates a new Menu
14828 * @param {Object} config Configuration options
14830 Roo.menu.Menu = function(config){
14832 Roo.menu.Menu.superclass.constructor.call(this, config);
14834 this.id = this.id || Roo.id();
14837 * @event beforeshow
14838 * Fires before this menu is displayed
14839 * @param {Roo.menu.Menu} this
14843 * @event beforehide
14844 * Fires before this menu is hidden
14845 * @param {Roo.menu.Menu} this
14850 * Fires after this menu is displayed
14851 * @param {Roo.menu.Menu} this
14856 * Fires after this menu is hidden
14857 * @param {Roo.menu.Menu} this
14862 * Fires when this menu is clicked (or when the enter key is pressed while it is active)
14863 * @param {Roo.menu.Menu} this
14864 * @param {Roo.menu.Item} menuItem The menu item that was clicked
14865 * @param {Roo.EventObject} e
14870 * Fires when the mouse is hovering over this menu
14871 * @param {Roo.menu.Menu} this
14872 * @param {Roo.EventObject} e
14873 * @param {Roo.menu.Item} menuItem The menu item that was clicked
14878 * Fires when the mouse exits this menu
14879 * @param {Roo.menu.Menu} this
14880 * @param {Roo.EventObject} e
14881 * @param {Roo.menu.Item} menuItem The menu item that was clicked
14886 * Fires when a menu item contained in this menu is clicked
14887 * @param {Roo.menu.BaseItem} baseItem The BaseItem that was clicked
14888 * @param {Roo.EventObject} e
14892 if (this.registerMenu) {
14893 Roo.menu.MenuMgr.register(this);
14896 var mis = this.items;
14897 this.items = new Roo.util.MixedCollection();
14899 this.add.apply(this, mis);
14903 Roo.extend(Roo.menu.Menu, Roo.util.Observable, {
14905 * @cfg {Number} minWidth The minimum width of the menu in pixels (defaults to 120)
14909 * @cfg {Boolean/String} shadow True or "sides" for the default effect, "frame" for 4-way shadow, and "drop"
14910 * for bottom-right shadow (defaults to "sides")
14914 * @cfg {String} subMenuAlign The {@link Roo.Element#alignTo} anchor position value to use for submenus of
14915 * this menu (defaults to "tl-tr?")
14917 subMenuAlign : "tl-tr?",
14919 * @cfg {String} defaultAlign The default {@link Roo.Element#alignTo) anchor position value for this menu
14920 * relative to its element of origin (defaults to "tl-bl?")
14922 defaultAlign : "tl-bl?",
14924 * @cfg {Boolean} allowOtherMenus True to allow multiple menus to be displayed at the same time (defaults to false)
14926 allowOtherMenus : false,
14928 * @cfg {Boolean} registerMenu True (default) - means that clicking on screen etc. hides it.
14930 registerMenu : true,
14935 render : function(){
14939 var el = this.el = new Roo.Layer({
14941 shadow:this.shadow,
14943 parentEl: this.parentEl || document.body,
14947 this.keyNav = new Roo.menu.MenuNav(this);
14950 el.addClass("x-menu-plain");
14953 el.addClass(this.cls);
14955 // generic focus element
14956 this.focusEl = el.createChild({
14957 tag: "a", cls: "x-menu-focus", href: "#", onclick: "return false;", tabIndex:"-1"
14959 var ul = el.createChild({tag: "ul", cls: "x-menu-list"});
14960 //disabling touch- as it's causing issues ..
14961 //ul.on(Roo.isTouch ? 'touchstart' : 'click' , this.onClick, this);
14962 ul.on('click' , this.onClick, this);
14965 ul.on("mouseover", this.onMouseOver, this);
14966 ul.on("mouseout", this.onMouseOut, this);
14967 this.items.each(function(item){
14972 var li = document.createElement("li");
14973 li.className = "x-menu-list-item";
14974 ul.dom.appendChild(li);
14975 item.render(li, this);
14982 autoWidth : function(){
14983 var el = this.el, ul = this.ul;
14987 var w = this.width;
14990 }else if(Roo.isIE){
14991 el.setWidth(this.minWidth);
14992 var t = el.dom.offsetWidth; // force recalc
14993 el.setWidth(ul.getWidth()+el.getFrameWidth("lr"));
14998 delayAutoWidth : function(){
15001 this.awTask = new Roo.util.DelayedTask(this.autoWidth, this);
15003 this.awTask.delay(20);
15008 findTargetItem : function(e){
15009 var t = e.getTarget(".x-menu-list-item", this.ul, true);
15010 if(t && t.menuItemId){
15011 return this.items.get(t.menuItemId);
15016 onClick : function(e){
15017 Roo.log("menu.onClick");
15018 var t = this.findTargetItem(e);
15023 if (Roo.isTouch && e.type == 'touchstart' && t.menu && !t.disabled) {
15024 if(t == this.activeItem && t.shouldDeactivate(e)){
15025 this.activeItem.deactivate();
15026 delete this.activeItem;
15030 this.setActiveItem(t, true);
15038 this.fireEvent("click", this, t, e);
15042 setActiveItem : function(item, autoExpand){
15043 if(item != this.activeItem){
15044 if(this.activeItem){
15045 this.activeItem.deactivate();
15047 this.activeItem = item;
15048 item.activate(autoExpand);
15049 }else if(autoExpand){
15055 tryActivate : function(start, step){
15056 var items = this.items;
15057 for(var i = start, len = items.length; i >= 0 && i < len; i+= step){
15058 var item = items.get(i);
15059 if(!item.disabled && item.canActivate){
15060 this.setActiveItem(item, false);
15068 onMouseOver : function(e){
15070 if(t = this.findTargetItem(e)){
15071 if(t.canActivate && !t.disabled){
15072 this.setActiveItem(t, true);
15075 this.fireEvent("mouseover", this, e, t);
15079 onMouseOut : function(e){
15081 if(t = this.findTargetItem(e)){
15082 if(t == this.activeItem && t.shouldDeactivate(e)){
15083 this.activeItem.deactivate();
15084 delete this.activeItem;
15087 this.fireEvent("mouseout", this, e, t);
15091 * Read-only. Returns true if the menu is currently displayed, else false.
15094 isVisible : function(){
15095 return this.el && !this.hidden;
15099 * Displays this menu relative to another element
15100 * @param {String/HTMLElement/Roo.Element} element The element to align to
15101 * @param {String} position (optional) The {@link Roo.Element#alignTo} anchor position to use in aligning to
15102 * the element (defaults to this.defaultAlign)
15103 * @param {Roo.menu.Menu} parentMenu (optional) This menu's parent menu, if applicable (defaults to undefined)
15105 show : function(el, pos, parentMenu){
15106 this.parentMenu = parentMenu;
15110 this.fireEvent("beforeshow", this);
15111 this.showAt(this.el.getAlignToXY(el, pos || this.defaultAlign), parentMenu, false);
15115 * Displays this menu at a specific xy position
15116 * @param {Array} xyPosition Contains X & Y [x, y] values for the position at which to show the menu (coordinates are page-based)
15117 * @param {Roo.menu.Menu} parentMenu (optional) This menu's parent menu, if applicable (defaults to undefined)
15119 showAt : function(xy, parentMenu, /* private: */_e){
15120 this.parentMenu = parentMenu;
15125 this.fireEvent("beforeshow", this);
15126 xy = this.el.adjustForConstraints(xy);
15130 this.hidden = false;
15132 this.fireEvent("show", this);
15135 focus : function(){
15137 this.doFocus.defer(50, this);
15141 doFocus : function(){
15143 this.focusEl.focus();
15148 * Hides this menu and optionally all parent menus
15149 * @param {Boolean} deep (optional) True to hide all parent menus recursively, if any (defaults to false)
15151 hide : function(deep){
15152 if(this.el && this.isVisible()){
15153 this.fireEvent("beforehide", this);
15154 if(this.activeItem){
15155 this.activeItem.deactivate();
15156 this.activeItem = null;
15159 this.hidden = true;
15160 this.fireEvent("hide", this);
15162 if(deep === true && this.parentMenu){
15163 this.parentMenu.hide(true);
15168 * Addds one or more items of any type supported by the Menu class, or that can be converted into menu items.
15169 * Any of the following are valid:
15171 * <li>Any menu item object based on {@link Roo.menu.Item}</li>
15172 * <li>An HTMLElement object which will be converted to a menu item</li>
15173 * <li>A menu item config object that will be created as a new menu item</li>
15174 * <li>A string, which can either be '-' or 'separator' to add a menu separator, otherwise
15175 * it will be converted into a {@link Roo.menu.TextItem} and added</li>
15180 var menu = new Roo.menu.Menu();
15182 // Create a menu item to add by reference
15183 var menuItem = new Roo.menu.Item({ text: 'New Item!' });
15185 // Add a bunch of items at once using different methods.
15186 // Only the last item added will be returned.
15187 var item = menu.add(
15188 menuItem, // add existing item by ref
15189 'Dynamic Item', // new TextItem
15190 '-', // new separator
15191 { text: 'Config Item' } // new item by config
15194 * @param {Mixed} args One or more menu items, menu item configs or other objects that can be converted to menu items
15195 * @return {Roo.menu.Item} The menu item that was added, or the last one if multiple items were added
15198 var a = arguments, l = a.length, item;
15199 for(var i = 0; i < l; i++){
15201 if ((typeof(el) == "object") && el.xtype && el.xns) {
15202 el = Roo.factory(el, Roo.menu);
15205 if(el.render){ // some kind of Item
15206 item = this.addItem(el);
15207 }else if(typeof el == "string"){ // string
15208 if(el == "separator" || el == "-"){
15209 item = this.addSeparator();
15211 item = this.addText(el);
15213 }else if(el.tagName || el.el){ // element
15214 item = this.addElement(el);
15215 }else if(typeof el == "object"){ // must be menu item config?
15216 item = this.addMenuItem(el);
15223 * Returns this menu's underlying {@link Roo.Element} object
15224 * @return {Roo.Element} The element
15226 getEl : function(){
15234 * Adds a separator bar to the menu
15235 * @return {Roo.menu.Item} The menu item that was added
15237 addSeparator : function(){
15238 return this.addItem(new Roo.menu.Separator());
15242 * Adds an {@link Roo.Element} object to the menu
15243 * @param {String/HTMLElement/Roo.Element} el The element or DOM node to add, or its id
15244 * @return {Roo.menu.Item} The menu item that was added
15246 addElement : function(el){
15247 return this.addItem(new Roo.menu.BaseItem(el));
15251 * Adds an existing object based on {@link Roo.menu.Item} to the menu
15252 * @param {Roo.menu.Item} item The menu item to add
15253 * @return {Roo.menu.Item} The menu item that was added
15255 addItem : function(item){
15256 this.items.add(item);
15258 var li = document.createElement("li");
15259 li.className = "x-menu-list-item";
15260 this.ul.dom.appendChild(li);
15261 item.render(li, this);
15262 this.delayAutoWidth();
15268 * Creates a new {@link Roo.menu.Item} based an the supplied config object and adds it to the menu
15269 * @param {Object} config A MenuItem config object
15270 * @return {Roo.menu.Item} The menu item that was added
15272 addMenuItem : function(config){
15273 if(!(config instanceof Roo.menu.Item)){
15274 if(typeof config.checked == "boolean"){ // must be check menu item config?
15275 config = new Roo.menu.CheckItem(config);
15277 config = new Roo.menu.Item(config);
15280 return this.addItem(config);
15284 * Creates a new {@link Roo.menu.TextItem} with the supplied text and adds it to the menu
15285 * @param {String} text The text to display in the menu item
15286 * @return {Roo.menu.Item} The menu item that was added
15288 addText : function(text){
15289 return this.addItem(new Roo.menu.TextItem({ text : text }));
15293 * Inserts an existing object based on {@link Roo.menu.Item} to the menu at a specified index
15294 * @param {Number} index The index in the menu's list of current items where the new item should be inserted
15295 * @param {Roo.menu.Item} item The menu item to add
15296 * @return {Roo.menu.Item} The menu item that was added
15298 insert : function(index, item){
15299 this.items.insert(index, item);
15301 var li = document.createElement("li");
15302 li.className = "x-menu-list-item";
15303 this.ul.dom.insertBefore(li, this.ul.dom.childNodes[index]);
15304 item.render(li, this);
15305 this.delayAutoWidth();
15311 * Removes an {@link Roo.menu.Item} from the menu and destroys the object
15312 * @param {Roo.menu.Item} item The menu item to remove
15314 remove : function(item){
15315 this.items.removeKey(item.id);
15320 * Removes and destroys all items in the menu
15322 removeAll : function(){
15324 while(f = this.items.first()){
15330 // MenuNav is a private utility class used internally by the Menu
15331 Roo.menu.MenuNav = function(menu){
15332 Roo.menu.MenuNav.superclass.constructor.call(this, menu.el);
15333 this.scope = this.menu = menu;
15336 Roo.extend(Roo.menu.MenuNav, Roo.KeyNav, {
15337 doRelay : function(e, h){
15338 var k = e.getKey();
15339 if(!this.menu.activeItem && e.isNavKeyPress() && k != e.SPACE && k != e.RETURN){
15340 this.menu.tryActivate(0, 1);
15343 return h.call(this.scope || this, e, this.menu);
15346 up : function(e, m){
15347 if(!m.tryActivate(m.items.indexOf(m.activeItem)-1, -1)){
15348 m.tryActivate(m.items.length-1, -1);
15352 down : function(e, m){
15353 if(!m.tryActivate(m.items.indexOf(m.activeItem)+1, 1)){
15354 m.tryActivate(0, 1);
15358 right : function(e, m){
15360 m.activeItem.expandMenu(true);
15364 left : function(e, m){
15366 if(m.parentMenu && m.parentMenu.activeItem){
15367 m.parentMenu.activeItem.activate();
15371 enter : function(e, m){
15373 e.stopPropagation();
15374 m.activeItem.onClick(e);
15375 m.fireEvent("click", this, m.activeItem);
15381 * Ext JS Library 1.1.1
15382 * Copyright(c) 2006-2007, Ext JS, LLC.
15384 * Originally Released Under LGPL - original licence link has changed is not relivant.
15387 * <script type="text/javascript">
15391 * @class Roo.menu.MenuMgr
15392 * Provides a common registry of all menu items on a page so that they can be easily accessed by id.
15395 Roo.menu.MenuMgr = function(){
15396 var menus, active, groups = {}, attached = false, lastShow = new Date();
15398 // private - called when first menu is created
15401 active = new Roo.util.MixedCollection();
15402 Roo.get(document).addKeyListener(27, function(){
15403 if(active.length > 0){
15410 function hideAll(){
15411 if(active && active.length > 0){
15412 var c = active.clone();
15413 c.each(function(m){
15420 function onHide(m){
15422 if(active.length < 1){
15423 Roo.get(document).un("mousedown", onMouseDown);
15429 function onShow(m){
15430 var last = active.last();
15431 lastShow = new Date();
15434 Roo.get(document).on("mousedown", onMouseDown);
15438 m.getEl().setZIndex(parseInt(m.parentMenu.getEl().getStyle("z-index"), 10) + 3);
15439 m.parentMenu.activeChild = m;
15440 }else if(last && last.isVisible()){
15441 m.getEl().setZIndex(parseInt(last.getEl().getStyle("z-index"), 10) + 3);
15446 function onBeforeHide(m){
15448 m.activeChild.hide();
15450 if(m.autoHideTimer){
15451 clearTimeout(m.autoHideTimer);
15452 delete m.autoHideTimer;
15457 function onBeforeShow(m){
15458 var pm = m.parentMenu;
15459 if(!pm && !m.allowOtherMenus){
15461 }else if(pm && pm.activeChild && active != m){
15462 pm.activeChild.hide();
15467 function onMouseDown(e){
15468 if(lastShow.getElapsed() > 50 && active.length > 0 && !e.getTarget(".x-menu")){
15474 function onBeforeCheck(mi, state){
15476 var g = groups[mi.group];
15477 for(var i = 0, l = g.length; i < l; i++){
15479 g[i].setChecked(false);
15488 * Hides all menus that are currently visible
15490 hideAll : function(){
15495 register : function(menu){
15499 menus[menu.id] = menu;
15500 menu.on("beforehide", onBeforeHide);
15501 menu.on("hide", onHide);
15502 menu.on("beforeshow", onBeforeShow);
15503 menu.on("show", onShow);
15504 var g = menu.group;
15505 if(g && menu.events["checkchange"]){
15509 groups[g].push(menu);
15510 menu.on("checkchange", onCheck);
15515 * Returns a {@link Roo.menu.Menu} object
15516 * @param {String/Object} menu The string menu id, an existing menu object reference, or a Menu config that will
15517 * be used to generate and return a new Menu instance.
15519 get : function(menu){
15520 if(typeof menu == "string"){ // menu id
15521 return menus[menu];
15522 }else if(menu.events){ // menu instance
15524 }else if(typeof menu.length == 'number'){ // array of menu items?
15525 return new Roo.menu.Menu({items:menu});
15526 }else{ // otherwise, must be a config
15527 return new Roo.menu.Menu(menu);
15532 unregister : function(menu){
15533 delete menus[menu.id];
15534 menu.un("beforehide", onBeforeHide);
15535 menu.un("hide", onHide);
15536 menu.un("beforeshow", onBeforeShow);
15537 menu.un("show", onShow);
15538 var g = menu.group;
15539 if(g && menu.events["checkchange"]){
15540 groups[g].remove(menu);
15541 menu.un("checkchange", onCheck);
15546 registerCheckable : function(menuItem){
15547 var g = menuItem.group;
15552 groups[g].push(menuItem);
15553 menuItem.on("beforecheckchange", onBeforeCheck);
15558 unregisterCheckable : function(menuItem){
15559 var g = menuItem.group;
15561 groups[g].remove(menuItem);
15562 menuItem.un("beforecheckchange", onBeforeCheck);
15568 * Ext JS Library 1.1.1
15569 * Copyright(c) 2006-2007, Ext JS, LLC.
15571 * Originally Released Under LGPL - original licence link has changed is not relivant.
15574 * <script type="text/javascript">
15579 * @class Roo.menu.BaseItem
15580 * @extends Roo.Component
15581 * The base class for all items that render into menus. BaseItem provides default rendering, activated state
15582 * management and base configuration options shared by all menu components.
15584 * Creates a new BaseItem
15585 * @param {Object} config Configuration options
15587 Roo.menu.BaseItem = function(config){
15588 Roo.menu.BaseItem.superclass.constructor.call(this, config);
15593 * Fires when this item is clicked
15594 * @param {Roo.menu.BaseItem} this
15595 * @param {Roo.EventObject} e
15600 * Fires when this item is activated
15601 * @param {Roo.menu.BaseItem} this
15605 * @event deactivate
15606 * Fires when this item is deactivated
15607 * @param {Roo.menu.BaseItem} this
15613 this.on("click", this.handler, this.scope, true);
15617 Roo.extend(Roo.menu.BaseItem, Roo.Component, {
15619 * @cfg {Function} handler
15620 * A function that will handle the click event of this menu item (defaults to undefined)
15623 * @cfg {Boolean} canActivate True if this item can be visually activated (defaults to false)
15625 canActivate : false,
15628 * @cfg {Boolean} hidden True to prevent creation of this menu item (defaults to false)
15633 * @cfg {String} activeClass The CSS class to use when the item becomes activated (defaults to "x-menu-item-active")
15635 activeClass : "x-menu-item-active",
15637 * @cfg {Boolean} hideOnClick True to hide the containing menu after this item is clicked (defaults to true)
15639 hideOnClick : true,
15641 * @cfg {Number} hideDelay Length of time in milliseconds to wait before hiding after a click (defaults to 100)
15646 ctype: "Roo.menu.BaseItem",
15649 actionMode : "container",
15652 render : function(container, parentMenu){
15653 this.parentMenu = parentMenu;
15654 Roo.menu.BaseItem.superclass.render.call(this, container);
15655 this.container.menuItemId = this.id;
15659 onRender : function(container, position){
15660 this.el = Roo.get(this.el);
15661 container.dom.appendChild(this.el.dom);
15665 onClick : function(e){
15666 if(!this.disabled && this.fireEvent("click", this, e) !== false
15667 && this.parentMenu.fireEvent("itemclick", this, e) !== false){
15668 this.handleClick(e);
15675 activate : function(){
15679 var li = this.container;
15680 li.addClass(this.activeClass);
15681 this.region = li.getRegion().adjust(2, 2, -2, -2);
15682 this.fireEvent("activate", this);
15687 deactivate : function(){
15688 this.container.removeClass(this.activeClass);
15689 this.fireEvent("deactivate", this);
15693 shouldDeactivate : function(e){
15694 return !this.region || !this.region.contains(e.getPoint());
15698 handleClick : function(e){
15699 if(this.hideOnClick){
15700 this.parentMenu.hide.defer(this.hideDelay, this.parentMenu, [true]);
15705 expandMenu : function(autoActivate){
15710 hideMenu : function(){
15715 * Ext JS Library 1.1.1
15716 * Copyright(c) 2006-2007, Ext JS, LLC.
15718 * Originally Released Under LGPL - original licence link has changed is not relivant.
15721 * <script type="text/javascript">
15725 * @class Roo.menu.Adapter
15726 * @extends Roo.menu.BaseItem
15727 * 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.
15728 * It provides basic rendering, activation management and enable/disable logic required to work in menus.
15730 * Creates a new Adapter
15731 * @param {Object} config Configuration options
15733 Roo.menu.Adapter = function(component, config){
15734 Roo.menu.Adapter.superclass.constructor.call(this, config);
15735 this.component = component;
15737 Roo.extend(Roo.menu.Adapter, Roo.menu.BaseItem, {
15739 canActivate : true,
15742 onRender : function(container, position){
15743 this.component.render(container);
15744 this.el = this.component.getEl();
15748 activate : function(){
15752 this.component.focus();
15753 this.fireEvent("activate", this);
15758 deactivate : function(){
15759 this.fireEvent("deactivate", this);
15763 disable : function(){
15764 this.component.disable();
15765 Roo.menu.Adapter.superclass.disable.call(this);
15769 enable : function(){
15770 this.component.enable();
15771 Roo.menu.Adapter.superclass.enable.call(this);
15775 * Ext JS Library 1.1.1
15776 * Copyright(c) 2006-2007, Ext JS, LLC.
15778 * Originally Released Under LGPL - original licence link has changed is not relivant.
15781 * <script type="text/javascript">
15785 * @class Roo.menu.TextItem
15786 * @extends Roo.menu.BaseItem
15787 * Adds a static text string to a menu, usually used as either a heading or group separator.
15788 * Note: old style constructor with text is still supported.
15791 * Creates a new TextItem
15792 * @param {Object} cfg Configuration
15794 Roo.menu.TextItem = function(cfg){
15795 if (typeof(cfg) == 'string') {
15798 Roo.apply(this,cfg);
15801 Roo.menu.TextItem.superclass.constructor.call(this);
15804 Roo.extend(Roo.menu.TextItem, Roo.menu.BaseItem, {
15806 * @cfg {Boolean} text Text to show on item.
15811 * @cfg {Boolean} hideOnClick True to hide the containing menu after this item is clicked (defaults to false)
15813 hideOnClick : false,
15815 * @cfg {String} itemCls The default CSS class to use for text items (defaults to "x-menu-text")
15817 itemCls : "x-menu-text",
15820 onRender : function(){
15821 var s = document.createElement("span");
15822 s.className = this.itemCls;
15823 s.innerHTML = this.text;
15825 Roo.menu.TextItem.superclass.onRender.apply(this, arguments);
15829 * Ext JS Library 1.1.1
15830 * Copyright(c) 2006-2007, Ext JS, LLC.
15832 * Originally Released Under LGPL - original licence link has changed is not relivant.
15835 * <script type="text/javascript">
15839 * @class Roo.menu.Separator
15840 * @extends Roo.menu.BaseItem
15841 * Adds a separator bar to a menu, used to divide logical groups of menu items. Generally you will
15842 * add one of these by using "-" in you call to add() or in your items config rather than creating one directly.
15844 * @param {Object} config Configuration options
15846 Roo.menu.Separator = function(config){
15847 Roo.menu.Separator.superclass.constructor.call(this, config);
15850 Roo.extend(Roo.menu.Separator, Roo.menu.BaseItem, {
15852 * @cfg {String} itemCls The default CSS class to use for separators (defaults to "x-menu-sep")
15854 itemCls : "x-menu-sep",
15856 * @cfg {Boolean} hideOnClick True to hide the containing menu after this item is clicked (defaults to false)
15858 hideOnClick : false,
15861 onRender : function(li){
15862 var s = document.createElement("span");
15863 s.className = this.itemCls;
15864 s.innerHTML = " ";
15866 li.addClass("x-menu-sep-li");
15867 Roo.menu.Separator.superclass.onRender.apply(this, arguments);
15871 * Ext JS Library 1.1.1
15872 * Copyright(c) 2006-2007, Ext JS, LLC.
15874 * Originally Released Under LGPL - original licence link has changed is not relivant.
15877 * <script type="text/javascript">
15880 * @class Roo.menu.Item
15881 * @extends Roo.menu.BaseItem
15882 * A base class for all menu items that require menu-related functionality (like sub-menus) and are not static
15883 * display items. Item extends the base functionality of {@link Roo.menu.BaseItem} by adding menu-specific
15884 * activation and click handling.
15886 * Creates a new Item
15887 * @param {Object} config Configuration options
15889 Roo.menu.Item = function(config){
15890 Roo.menu.Item.superclass.constructor.call(this, config);
15892 this.menu = Roo.menu.MenuMgr.get(this.menu);
15895 Roo.extend(Roo.menu.Item, Roo.menu.BaseItem, {
15898 * @cfg {String} text
15899 * The text to show on the menu item.
15903 * @cfg {String} HTML to render in menu
15904 * The text to show on the menu item (HTML version).
15908 * @cfg {String} icon
15909 * The path to an icon to display in this menu item (defaults to Roo.BLANK_IMAGE_URL)
15913 * @cfg {String} itemCls The default CSS class to use for menu items (defaults to "x-menu-item")
15915 itemCls : "x-menu-item",
15917 * @cfg {Boolean} canActivate True if this item can be visually activated (defaults to true)
15919 canActivate : true,
15921 * @cfg {Number} showDelay Length of time in milliseconds to wait before showing this item (defaults to 200)
15924 // doc'd in BaseItem
15928 ctype: "Roo.menu.Item",
15931 onRender : function(container, position){
15932 var el = document.createElement("a");
15933 el.hideFocus = true;
15934 el.unselectable = "on";
15935 el.href = this.href || "#";
15936 if(this.hrefTarget){
15937 el.target = this.hrefTarget;
15939 el.className = this.itemCls + (this.menu ? " x-menu-item-arrow" : "") + (this.cls ? " " + this.cls : "");
15941 var html = this.html.length ? this.html : String.format('{0}',this.text);
15943 el.innerHTML = String.format(
15944 '<img src="{0}" class="x-menu-item-icon {1}" />' + html,
15945 this.icon || Roo.BLANK_IMAGE_URL, this.iconCls || '');
15947 Roo.menu.Item.superclass.onRender.call(this, container, position);
15951 * Sets the text to display in this menu item
15952 * @param {String} text The text to display
15953 * @param {Boolean} isHTML true to indicate text is pure html.
15955 setText : function(text, isHTML){
15963 var html = this.html.length ? this.html : String.format('{0}',this.text);
15965 this.el.update(String.format(
15966 '<img src="{0}" class="x-menu-item-icon {2}">' + html,
15967 this.icon || Roo.BLANK_IMAGE_URL, this.text, this.iconCls || ''));
15968 this.parentMenu.autoWidth();
15973 handleClick : function(e){
15974 if(!this.href){ // if no link defined, stop the event automatically
15977 Roo.menu.Item.superclass.handleClick.apply(this, arguments);
15981 activate : function(autoExpand){
15982 if(Roo.menu.Item.superclass.activate.apply(this, arguments)){
15992 shouldDeactivate : function(e){
15993 if(Roo.menu.Item.superclass.shouldDeactivate.call(this, e)){
15994 if(this.menu && this.menu.isVisible()){
15995 return !this.menu.getEl().getRegion().contains(e.getPoint());
16003 deactivate : function(){
16004 Roo.menu.Item.superclass.deactivate.apply(this, arguments);
16009 expandMenu : function(autoActivate){
16010 if(!this.disabled && this.menu){
16011 clearTimeout(this.hideTimer);
16012 delete this.hideTimer;
16013 if(!this.menu.isVisible() && !this.showTimer){
16014 this.showTimer = this.deferExpand.defer(this.showDelay, this, [autoActivate]);
16015 }else if (this.menu.isVisible() && autoActivate){
16016 this.menu.tryActivate(0, 1);
16022 deferExpand : function(autoActivate){
16023 delete this.showTimer;
16024 this.menu.show(this.container, this.parentMenu.subMenuAlign || "tl-tr?", this.parentMenu);
16026 this.menu.tryActivate(0, 1);
16031 hideMenu : function(){
16032 clearTimeout(this.showTimer);
16033 delete this.showTimer;
16034 if(!this.hideTimer && this.menu && this.menu.isVisible()){
16035 this.hideTimer = this.deferHide.defer(this.hideDelay, this);
16040 deferHide : function(){
16041 delete this.hideTimer;
16046 * Ext JS Library 1.1.1
16047 * Copyright(c) 2006-2007, Ext JS, LLC.
16049 * Originally Released Under LGPL - original licence link has changed is not relivant.
16052 * <script type="text/javascript">
16056 * @class Roo.menu.CheckItem
16057 * @extends Roo.menu.Item
16058 * Adds a menu item that contains a checkbox by default, but can also be part of a radio group.
16060 * Creates a new CheckItem
16061 * @param {Object} config Configuration options
16063 Roo.menu.CheckItem = function(config){
16064 Roo.menu.CheckItem.superclass.constructor.call(this, config);
16067 * @event beforecheckchange
16068 * Fires before the checked value is set, providing an opportunity to cancel if needed
16069 * @param {Roo.menu.CheckItem} this
16070 * @param {Boolean} checked The new checked value that will be set
16072 "beforecheckchange" : true,
16074 * @event checkchange
16075 * Fires after the checked value has been set
16076 * @param {Roo.menu.CheckItem} this
16077 * @param {Boolean} checked The checked value that was set
16079 "checkchange" : true
16081 if(this.checkHandler){
16082 this.on('checkchange', this.checkHandler, this.scope);
16085 Roo.extend(Roo.menu.CheckItem, Roo.menu.Item, {
16087 * @cfg {String} group
16088 * All check items with the same group name will automatically be grouped into a single-select
16089 * radio button group (defaults to '')
16092 * @cfg {String} itemCls The default CSS class to use for check items (defaults to "x-menu-item x-menu-check-item")
16094 itemCls : "x-menu-item x-menu-check-item",
16096 * @cfg {String} groupClass The default CSS class to use for radio group check items (defaults to "x-menu-group-item")
16098 groupClass : "x-menu-group-item",
16101 * @cfg {Boolean} checked True to initialize this checkbox as checked (defaults to false). Note that
16102 * if this checkbox is part of a radio group (group = true) only the last item in the group that is
16103 * initialized with checked = true will be rendered as checked.
16108 ctype: "Roo.menu.CheckItem",
16111 onRender : function(c){
16112 Roo.menu.CheckItem.superclass.onRender.apply(this, arguments);
16114 this.el.addClass(this.groupClass);
16116 Roo.menu.MenuMgr.registerCheckable(this);
16118 this.checked = false;
16119 this.setChecked(true, true);
16124 destroy : function(){
16126 Roo.menu.MenuMgr.unregisterCheckable(this);
16128 Roo.menu.CheckItem.superclass.destroy.apply(this, arguments);
16132 * Set the checked state of this item
16133 * @param {Boolean} checked The new checked value
16134 * @param {Boolean} suppressEvent (optional) True to prevent the checkchange event from firing (defaults to false)
16136 setChecked : function(state, suppressEvent){
16137 if(this.checked != state && this.fireEvent("beforecheckchange", this, state) !== false){
16138 if(this.container){
16139 this.container[state ? "addClass" : "removeClass"]("x-menu-item-checked");
16141 this.checked = state;
16142 if(suppressEvent !== true){
16143 this.fireEvent("checkchange", this, state);
16149 handleClick : function(e){
16150 if(!this.disabled && !(this.checked && this.group)){// disable unselect on radio item
16151 this.setChecked(!this.checked);
16153 Roo.menu.CheckItem.superclass.handleClick.apply(this, arguments);
16157 * Ext JS Library 1.1.1
16158 * Copyright(c) 2006-2007, Ext JS, LLC.
16160 * Originally Released Under LGPL - original licence link has changed is not relivant.
16163 * <script type="text/javascript">
16167 * @class Roo.menu.DateItem
16168 * @extends Roo.menu.Adapter
16169 * A menu item that wraps the {@link Roo.DatPicker} component.
16171 * Creates a new DateItem
16172 * @param {Object} config Configuration options
16174 Roo.menu.DateItem = function(config){
16175 Roo.menu.DateItem.superclass.constructor.call(this, new Roo.DatePicker(config), config);
16176 /** The Roo.DatePicker object @type Roo.DatePicker */
16177 this.picker = this.component;
16178 this.addEvents({select: true});
16180 this.picker.on("render", function(picker){
16181 picker.getEl().swallowEvent("click");
16182 picker.container.addClass("x-menu-date-item");
16185 this.picker.on("select", this.onSelect, this);
16188 Roo.extend(Roo.menu.DateItem, Roo.menu.Adapter, {
16190 onSelect : function(picker, date){
16191 this.fireEvent("select", this, date, picker);
16192 Roo.menu.DateItem.superclass.handleClick.call(this);
16196 * Ext JS Library 1.1.1
16197 * Copyright(c) 2006-2007, Ext JS, LLC.
16199 * Originally Released Under LGPL - original licence link has changed is not relivant.
16202 * <script type="text/javascript">
16206 * @class Roo.menu.ColorItem
16207 * @extends Roo.menu.Adapter
16208 * A menu item that wraps the {@link Roo.ColorPalette} component.
16210 * Creates a new ColorItem
16211 * @param {Object} config Configuration options
16213 Roo.menu.ColorItem = function(config){
16214 Roo.menu.ColorItem.superclass.constructor.call(this, new Roo.ColorPalette(config), config);
16215 /** The Roo.ColorPalette object @type Roo.ColorPalette */
16216 this.palette = this.component;
16217 this.relayEvents(this.palette, ["select"]);
16218 if(this.selectHandler){
16219 this.on('select', this.selectHandler, this.scope);
16222 Roo.extend(Roo.menu.ColorItem, Roo.menu.Adapter);/*
16224 * Ext JS Library 1.1.1
16225 * Copyright(c) 2006-2007, Ext JS, LLC.
16227 * Originally Released Under LGPL - original licence link has changed is not relivant.
16230 * <script type="text/javascript">
16235 * @class Roo.menu.DateMenu
16236 * @extends Roo.menu.Menu
16237 * A menu containing a {@link Roo.menu.DateItem} component (which provides a date picker).
16239 * Creates a new DateMenu
16240 * @param {Object} config Configuration options
16242 Roo.menu.DateMenu = function(config){
16243 Roo.menu.DateMenu.superclass.constructor.call(this, config);
16245 var di = new Roo.menu.DateItem(config);
16248 * The {@link Roo.DatePicker} instance for this DateMenu
16251 this.picker = di.picker;
16254 * @param {DatePicker} picker
16255 * @param {Date} date
16257 this.relayEvents(di, ["select"]);
16258 this.on('beforeshow', function(){
16260 this.picker.hideMonthPicker(false);
16264 Roo.extend(Roo.menu.DateMenu, Roo.menu.Menu, {
16268 * Ext JS Library 1.1.1
16269 * Copyright(c) 2006-2007, Ext JS, LLC.
16271 * Originally Released Under LGPL - original licence link has changed is not relivant.
16274 * <script type="text/javascript">
16279 * @class Roo.menu.ColorMenu
16280 * @extends Roo.menu.Menu
16281 * A menu containing a {@link Roo.menu.ColorItem} component (which provides a basic color picker).
16283 * Creates a new ColorMenu
16284 * @param {Object} config Configuration options
16286 Roo.menu.ColorMenu = function(config){
16287 Roo.menu.ColorMenu.superclass.constructor.call(this, config);
16289 var ci = new Roo.menu.ColorItem(config);
16292 * The {@link Roo.ColorPalette} instance for this ColorMenu
16293 * @type ColorPalette
16295 this.palette = ci.palette;
16298 * @param {ColorPalette} palette
16299 * @param {String} color
16301 this.relayEvents(ci, ["select"]);
16303 Roo.extend(Roo.menu.ColorMenu, Roo.menu.Menu);/*
16305 * Ext JS Library 1.1.1
16306 * Copyright(c) 2006-2007, Ext JS, LLC.
16308 * Originally Released Under LGPL - original licence link has changed is not relivant.
16311 * <script type="text/javascript">
16315 * @class Roo.form.TextItem
16316 * @extends Roo.BoxComponent
16317 * Base class for form fields that provides default event handling, sizing, value handling and other functionality.
16319 * Creates a new TextItem
16320 * @param {Object} config Configuration options
16322 Roo.form.TextItem = function(config){
16323 Roo.form.TextItem.superclass.constructor.call(this, config);
16326 Roo.extend(Roo.form.TextItem, Roo.BoxComponent, {
16329 * @cfg {String} tag the tag for this item (default div)
16333 * @cfg {String} html the content for this item
16337 getAutoCreate : function()
16350 onRender : function(ct, position)
16352 Roo.form.TextItem.superclass.onRender.call(this, ct, position);
16355 var cfg = this.getAutoCreate();
16357 cfg.name = typeof(this.name) == 'undefined' ? this.id : this.name;
16359 if (!cfg.name.length) {
16362 this.el = ct.createChild(cfg, position);
16368 * Ext JS Library 1.1.1
16369 * Copyright(c) 2006-2007, Ext JS, LLC.
16371 * Originally Released Under LGPL - original licence link has changed is not relivant.
16374 * <script type="text/javascript">
16378 * @class Roo.form.Field
16379 * @extends Roo.BoxComponent
16380 * Base class for form fields that provides default event handling, sizing, value handling and other functionality.
16382 * Creates a new Field
16383 * @param {Object} config Configuration options
16385 Roo.form.Field = function(config){
16386 Roo.form.Field.superclass.constructor.call(this, config);
16389 Roo.extend(Roo.form.Field, Roo.BoxComponent, {
16391 * @cfg {String} fieldLabel Label to use when rendering a form.
16394 * @cfg {String} qtip Mouse over tip
16398 * @cfg {String} invalidClass The CSS class to use when marking a field invalid (defaults to "x-form-invalid")
16400 invalidClass : "x-form-invalid",
16402 * @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")
16404 invalidText : "The value in this field is invalid",
16406 * @cfg {String} focusClass The CSS class to use when the field receives focus (defaults to "x-form-focus")
16408 focusClass : "x-form-focus",
16410 * @cfg {String/Boolean} validationEvent The event that should initiate field validation. Set to false to disable
16411 automatic validation (defaults to "keyup").
16413 validationEvent : "keyup",
16415 * @cfg {Boolean} validateOnBlur Whether the field should validate when it loses focus (defaults to true).
16417 validateOnBlur : true,
16419 * @cfg {Number} validationDelay The length of time in milliseconds after user input begins until validation is initiated (defaults to 250)
16421 validationDelay : 250,
16423 * @cfg {String/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to
16424 * {tag: "input", type: "text", size: "20", autocomplete: "off"})
16426 defaultAutoCreate : {tag: "input", type: "text", size: "20", autocomplete: "new-password"},
16428 * @cfg {String} fieldClass The default CSS class for the field (defaults to "x-form-field")
16430 fieldClass : "x-form-field",
16432 * @cfg {String} msgTarget The location where error text should display. Should be one of the following values (defaults to 'qtip'):
16435 ----------- ----------------------------------------------------------------------
16436 qtip Display a quick tip when the user hovers over the field
16437 title Display a default browser title attribute popup
16438 under Add a block div beneath the field containing the error text
16439 side Add an error icon to the right of the field with a popup on hover
16440 [element id] Add the error text directly to the innerHTML of the specified element
16443 msgTarget : 'qtip',
16445 * @cfg {String} msgFx <b>Experimental</b> The effect used when displaying a validation message under the field (defaults to 'normal').
16450 * @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.
16455 * @cfg {Boolean} disabled True to disable the field (defaults to false).
16460 * @cfg {String} inputType The type attribute for input fields -- e.g. radio, text, password (defaults to "text").
16462 inputType : undefined,
16465 * @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).
16467 tabIndex : undefined,
16470 isFormField : true,
16475 * @property {Roo.Element} fieldEl
16476 * Element Containing the rendered Field (with label etc.)
16479 * @cfg {Mixed} value A value to initialize this field with.
16484 * @cfg {String} name The field's HTML name attribute.
16487 * @cfg {String} cls A CSS class to apply to the field's underlying element.
16490 loadedValue : false,
16494 initComponent : function(){
16495 Roo.form.Field.superclass.initComponent.call(this);
16499 * Fires when this field receives input focus.
16500 * @param {Roo.form.Field} this
16505 * Fires when this field loses input focus.
16506 * @param {Roo.form.Field} this
16510 * @event specialkey
16511 * Fires when any key related to navigation (arrows, tab, enter, esc, etc.) is pressed. You can check
16512 * {@link Roo.EventObject#getKey} to determine which key was pressed.
16513 * @param {Roo.form.Field} this
16514 * @param {Roo.EventObject} e The event object
16519 * Fires just before the field blurs if the field value has changed.
16520 * @param {Roo.form.Field} this
16521 * @param {Mixed} newValue The new value
16522 * @param {Mixed} oldValue The original value
16527 * Fires after the field has been marked as invalid.
16528 * @param {Roo.form.Field} this
16529 * @param {String} msg The validation message
16534 * Fires after the field has been validated with no errors.
16535 * @param {Roo.form.Field} this
16540 * Fires after the key up
16541 * @param {Roo.form.Field} this
16542 * @param {Roo.EventObject} e The event Object
16549 * Returns the name attribute of the field if available
16550 * @return {String} name The field name
16552 getName: function(){
16553 return this.rendered && this.el.dom.name ? this.el.dom.name : (this.hiddenName || '');
16557 onRender : function(ct, position){
16558 Roo.form.Field.superclass.onRender.call(this, ct, position);
16560 var cfg = this.getAutoCreate();
16562 cfg.name = typeof(this.name) == 'undefined' ? this.id : this.name;
16564 if (!cfg.name.length) {
16567 if(this.inputType){
16568 cfg.type = this.inputType;
16570 this.el = ct.createChild(cfg, position);
16572 var type = this.el.dom.type;
16574 if(type == 'password'){
16577 this.el.addClass('x-form-'+type);
16580 this.el.dom.readOnly = true;
16582 if(this.tabIndex !== undefined){
16583 this.el.dom.setAttribute('tabIndex', this.tabIndex);
16586 this.el.addClass([this.fieldClass, this.cls]);
16591 * Apply the behaviors of this component to an existing element. <b>This is used instead of render().</b>
16592 * @param {String/HTMLElement/Element} el The id of the node, a DOM node or an existing Element
16593 * @return {Roo.form.Field} this
16595 applyTo : function(target){
16596 this.allowDomMove = false;
16597 this.el = Roo.get(target);
16598 this.render(this.el.dom.parentNode);
16603 initValue : function(){
16604 if(this.value !== undefined){
16605 this.setValue(this.value);
16606 }else if(this.el.dom.value.length > 0){
16607 this.setValue(this.el.dom.value);
16612 * Returns true if this field has been changed since it was originally loaded and is not disabled.
16613 * DEPRICATED - it never worked well - use hasChanged/resetHasChanged.
16615 isDirty : function() {
16616 if(this.disabled) {
16619 return String(this.getValue()) !== String(this.originalValue);
16623 * stores the current value in loadedValue
16625 resetHasChanged : function()
16627 this.loadedValue = String(this.getValue());
16630 * checks the current value against the 'loaded' value.
16631 * Note - will return false if 'resetHasChanged' has not been called first.
16633 hasChanged : function()
16635 if(this.disabled || this.readOnly) {
16638 return this.loadedValue !== false && String(this.getValue()) !== this.loadedValue;
16644 afterRender : function(){
16645 Roo.form.Field.superclass.afterRender.call(this);
16650 fireKey : function(e){
16651 //Roo.log('field ' + e.getKey());
16652 if(e.isNavKeyPress()){
16653 this.fireEvent("specialkey", this, e);
16658 * Resets the current field value to the originally loaded value and clears any validation messages
16660 reset : function(){
16661 this.setValue(this.resetValue);
16662 this.originalValue = this.getValue();
16663 this.clearInvalid();
16667 initEvents : function(){
16668 // safari killled keypress - so keydown is now used..
16669 this.el.on("keydown" , this.fireKey, this);
16670 this.el.on("focus", this.onFocus, this);
16671 this.el.on("blur", this.onBlur, this);
16672 this.el.relayEvent('keyup', this);
16674 // reference to original value for reset
16675 this.originalValue = this.getValue();
16676 this.resetValue = this.getValue();
16680 onFocus : function(){
16681 if(!Roo.isOpera && this.focusClass){ // don't touch in Opera
16682 this.el.addClass(this.focusClass);
16684 if(!this.hasFocus){
16685 this.hasFocus = true;
16686 this.startValue = this.getValue();
16687 this.fireEvent("focus", this);
16691 beforeBlur : Roo.emptyFn,
16694 onBlur : function(){
16696 if(!Roo.isOpera && this.focusClass){ // don't touch in Opera
16697 this.el.removeClass(this.focusClass);
16699 this.hasFocus = false;
16700 if(this.validationEvent !== false && this.validateOnBlur && this.validationEvent != "blur"){
16703 var v = this.getValue();
16704 if(String(v) !== String(this.startValue)){
16705 this.fireEvent('change', this, v, this.startValue);
16707 this.fireEvent("blur", this);
16711 * Returns whether or not the field value is currently valid
16712 * @param {Boolean} preventMark True to disable marking the field invalid
16713 * @return {Boolean} True if the value is valid, else false
16715 isValid : function(preventMark){
16719 var restore = this.preventMark;
16720 this.preventMark = preventMark === true;
16721 var v = this.validateValue(this.processValue(this.getRawValue()));
16722 this.preventMark = restore;
16727 * Validates the field value
16728 * @return {Boolean} True if the value is valid, else false
16730 validate : function(){
16731 if(this.disabled || this.validateValue(this.processValue(this.getRawValue()))){
16732 this.clearInvalid();
16738 processValue : function(value){
16743 // Subclasses should provide the validation implementation by overriding this
16744 validateValue : function(value){
16749 * Mark this field as invalid
16750 * @param {String} msg The validation message
16752 markInvalid : function(msg){
16753 if(!this.rendered || this.preventMark){ // not rendered
16757 var obj = (typeof(this.combo) != 'undefined') ? this.combo : this; // fix the combox array!!
16759 obj.el.addClass(this.invalidClass);
16760 msg = msg || this.invalidText;
16761 switch(this.msgTarget){
16763 obj.el.dom.qtip = msg;
16764 obj.el.dom.qclass = 'x-form-invalid-tip';
16765 if(Roo.QuickTips){ // fix for floating editors interacting with DND
16766 Roo.QuickTips.enable();
16770 this.el.dom.title = msg;
16774 var elp = this.el.findParent('.x-form-element', 5, true);
16775 this.errorEl = elp.createChild({cls:'x-form-invalid-msg'});
16776 this.errorEl.setWidth(elp.getWidth(true)-20);
16778 this.errorEl.update(msg);
16779 Roo.form.Field.msgFx[this.msgFx].show(this.errorEl, this);
16782 if(!this.errorIcon){
16783 var elp = this.el.findParent('.x-form-element', 5, true);
16784 this.errorIcon = elp.createChild({cls:'x-form-invalid-icon'});
16786 this.alignErrorIcon();
16787 this.errorIcon.dom.qtip = msg;
16788 this.errorIcon.dom.qclass = 'x-form-invalid-tip';
16789 this.errorIcon.show();
16790 this.on('resize', this.alignErrorIcon, this);
16793 var t = Roo.getDom(this.msgTarget);
16795 t.style.display = this.msgDisplay;
16798 this.fireEvent('invalid', this, msg);
16802 alignErrorIcon : function(){
16803 this.errorIcon.alignTo(this.el, 'tl-tr', [2, 0]);
16807 * Clear any invalid styles/messages for this field
16809 clearInvalid : function(){
16810 if(!this.rendered || this.preventMark){ // not rendered
16813 var obj = (typeof(this.combo) != 'undefined') ? this.combo : this; // fix the combox array!!
16815 obj.el.removeClass(this.invalidClass);
16816 switch(this.msgTarget){
16818 obj.el.dom.qtip = '';
16821 this.el.dom.title = '';
16825 Roo.form.Field.msgFx[this.msgFx].hide(this.errorEl, this);
16829 if(this.errorIcon){
16830 this.errorIcon.dom.qtip = '';
16831 this.errorIcon.hide();
16832 this.un('resize', this.alignErrorIcon, this);
16836 var t = Roo.getDom(this.msgTarget);
16838 t.style.display = 'none';
16841 this.fireEvent('valid', this);
16845 * Returns the raw data value which may or may not be a valid, defined value. To return a normalized value see {@link #getValue}.
16846 * @return {Mixed} value The field value
16848 getRawValue : function(){
16849 var v = this.el.getValue();
16855 * Returns the normalized data value (undefined or emptyText will be returned as ''). To return the raw value see {@link #getRawValue}.
16856 * @return {Mixed} value The field value
16858 getValue : function(){
16859 var v = this.el.getValue();
16865 * Sets the underlying DOM field's value directly, bypassing validation. To set the value with validation see {@link #setValue}.
16866 * @param {Mixed} value The value to set
16868 setRawValue : function(v){
16869 return this.el.dom.value = (v === null || v === undefined ? '' : v);
16873 * Sets a data value into the field and validates it. To set the value directly without validation see {@link #setRawValue}.
16874 * @param {Mixed} value The value to set
16876 setValue : function(v){
16879 this.el.dom.value = (v === null || v === undefined ? '' : v);
16884 adjustSize : function(w, h){
16885 var s = Roo.form.Field.superclass.adjustSize.call(this, w, h);
16886 s.width = this.adjustWidth(this.el.dom.tagName, s.width);
16890 adjustWidth : function(tag, w){
16891 tag = tag.toLowerCase();
16892 if(typeof w == 'number' && Roo.isStrict && !Roo.isSafari){
16893 if(Roo.isIE && (tag == 'input' || tag == 'textarea')){
16894 if(tag == 'input'){
16897 if(tag == 'textarea'){
16900 }else if(Roo.isOpera){
16901 if(tag == 'input'){
16904 if(tag == 'textarea'){
16914 // anything other than normal should be considered experimental
16915 Roo.form.Field.msgFx = {
16917 show: function(msgEl, f){
16918 msgEl.setDisplayed('block');
16921 hide : function(msgEl, f){
16922 msgEl.setDisplayed(false).update('');
16927 show: function(msgEl, f){
16928 msgEl.slideIn('t', {stopFx:true});
16931 hide : function(msgEl, f){
16932 msgEl.slideOut('t', {stopFx:true,useDisplay:true});
16937 show: function(msgEl, f){
16938 msgEl.fixDisplay();
16939 msgEl.alignTo(f.el, 'tl-tr');
16940 msgEl.slideIn('l', {stopFx:true});
16943 hide : function(msgEl, f){
16944 msgEl.slideOut('l', {stopFx:true,useDisplay:true});
16949 * Ext JS Library 1.1.1
16950 * Copyright(c) 2006-2007, Ext JS, LLC.
16952 * Originally Released Under LGPL - original licence link has changed is not relivant.
16955 * <script type="text/javascript">
16960 * @class Roo.form.TextField
16961 * @extends Roo.form.Field
16962 * Basic text field. Can be used as a direct replacement for traditional text inputs, or as the base
16963 * class for more sophisticated input controls (like {@link Roo.form.TextArea} and {@link Roo.form.ComboBox}).
16965 * Creates a new TextField
16966 * @param {Object} config Configuration options
16968 Roo.form.TextField = function(config){
16969 Roo.form.TextField.superclass.constructor.call(this, config);
16973 * Fires when the autosize function is triggered. The field may or may not have actually changed size
16974 * according to the default logic, but this event provides a hook for the developer to apply additional
16975 * logic at runtime to resize the field if needed.
16976 * @param {Roo.form.Field} this This text field
16977 * @param {Number} width The new field width
16983 Roo.extend(Roo.form.TextField, Roo.form.Field, {
16985 * @cfg {Boolean} grow True if this field should automatically grow and shrink to its content
16989 * @cfg {Number} growMin The minimum width to allow when grow = true (defaults to 30)
16993 * @cfg {Number} growMax The maximum width to allow when grow = true (defaults to 800)
16997 * @cfg {String} vtype A validation type name as defined in {@link Roo.form.VTypes} (defaults to null)
17001 * @cfg {String} maskRe An input mask regular expression that will be used to filter keystrokes that don't match (defaults to null)
17005 * @cfg {Boolean} disableKeyFilter True to disable input keystroke filtering (defaults to false)
17007 disableKeyFilter : false,
17009 * @cfg {Boolean} allowBlank False to validate that the value length > 0 (defaults to true)
17013 * @cfg {Number} minLength Minimum input field length required (defaults to 0)
17017 * @cfg {Number} maxLength Maximum input field length allowed (defaults to Number.MAX_VALUE)
17019 maxLength : Number.MAX_VALUE,
17021 * @cfg {String} minLengthText Error text to display if the minimum length validation fails (defaults to "The minimum length for this field is {minLength}")
17023 minLengthText : "The minimum length for this field is {0}",
17025 * @cfg {String} maxLengthText Error text to display if the maximum length validation fails (defaults to "The maximum length for this field is {maxLength}")
17027 maxLengthText : "The maximum length for this field is {0}",
17029 * @cfg {Boolean} selectOnFocus True to automatically select any existing field text when the field receives input focus (defaults to false)
17031 selectOnFocus : false,
17033 * @cfg {Boolean} allowLeadingSpace True to prevent the stripping of leading white space
17035 allowLeadingSpace : false,
17037 * @cfg {String} blankText Error text to display if the allow blank validation fails (defaults to "This field is required")
17039 blankText : "This field is required",
17041 * @cfg {Function} validator A custom validation function to be called during field validation (defaults to null).
17042 * If available, this function will be called only after the basic validators all return true, and will be passed the
17043 * current field value and expected to return boolean true if the value is valid or a string error message if invalid.
17047 * @cfg {RegExp} regex A JavaScript RegExp object to be tested against the field value during validation (defaults to null).
17048 * If available, this regex will be evaluated only after the basic validators all return true, and will be passed the
17049 * current field value. If the test fails, the field will be marked invalid using {@link #regexText}.
17053 * @cfg {String} regexText The error text to display if {@link #regex} is used and the test fails during validation (defaults to "")
17057 * @cfg {String} emptyText The default text to display in an empty field - placeholder... (defaults to null).
17063 initEvents : function()
17065 if (this.emptyText) {
17066 this.el.attr('placeholder', this.emptyText);
17069 Roo.form.TextField.superclass.initEvents.call(this);
17070 if(this.validationEvent == 'keyup'){
17071 this.validationTask = new Roo.util.DelayedTask(this.validate, this);
17072 this.el.on('keyup', this.filterValidation, this);
17074 else if(this.validationEvent !== false){
17075 this.el.on(this.validationEvent, this.validate, this, {buffer: this.validationDelay});
17078 if(this.selectOnFocus){
17079 this.on("focus", this.preFocus, this);
17081 if (!this.allowLeadingSpace) {
17082 this.on('blur', this.cleanLeadingSpace, this);
17085 if(this.maskRe || (this.vtype && this.disableKeyFilter !== true && (this.maskRe = Roo.form.VTypes[this.vtype+'Mask']))){
17086 this.el.on("keypress", this.filterKeys, this);
17089 this.el.on("keyup", this.onKeyUp, this, {buffer:50});
17090 this.el.on("click", this.autoSize, this);
17092 if(this.el.is('input[type=password]') && Roo.isSafari){
17093 this.el.on('keydown', this.SafariOnKeyDown, this);
17097 processValue : function(value){
17098 if(this.stripCharsRe){
17099 var newValue = value.replace(this.stripCharsRe, '');
17100 if(newValue !== value){
17101 this.setRawValue(newValue);
17108 filterValidation : function(e){
17109 if(!e.isNavKeyPress()){
17110 this.validationTask.delay(this.validationDelay);
17115 onKeyUp : function(e){
17116 if(!e.isNavKeyPress()){
17120 // private - clean the leading white space
17121 cleanLeadingSpace : function(e)
17123 if ( this.inputType == 'file') {
17127 this.setValue((this.getValue() + '').replace(/^\s+/,''));
17130 * Resets the current field value to the originally-loaded value and clears any validation messages.
17133 reset : function(){
17134 Roo.form.TextField.superclass.reset.call(this);
17138 preFocus : function(){
17140 if(this.selectOnFocus){
17141 this.el.dom.select();
17147 filterKeys : function(e){
17148 var k = e.getKey();
17149 if(!Roo.isIE && (e.isNavKeyPress() || k == e.BACKSPACE || (k == e.DELETE && e.button == -1))){
17152 var c = e.getCharCode(), cc = String.fromCharCode(c);
17153 if(Roo.isIE && (e.isSpecialKey() || !cc)){
17156 if(!this.maskRe.test(cc)){
17161 setValue : function(v){
17163 Roo.form.TextField.superclass.setValue.apply(this, arguments);
17169 * Validates a value according to the field's validation rules and marks the field as invalid
17170 * if the validation fails
17171 * @param {Mixed} value The value to validate
17172 * @return {Boolean} True if the value is valid, else false
17174 validateValue : function(value){
17175 if(value.length < 1) { // if it's blank
17176 if(this.allowBlank){
17177 this.clearInvalid();
17180 this.markInvalid(this.blankText);
17184 if(value.length < this.minLength){
17185 this.markInvalid(String.format(this.minLengthText, this.minLength));
17188 if(value.length > this.maxLength){
17189 this.markInvalid(String.format(this.maxLengthText, this.maxLength));
17193 var vt = Roo.form.VTypes;
17194 if(!vt[this.vtype](value, this)){
17195 this.markInvalid(this.vtypeText || vt[this.vtype +'Text']);
17199 if(typeof this.validator == "function"){
17200 var msg = this.validator(value);
17202 this.markInvalid(msg);
17206 if(this.regex && !this.regex.test(value)){
17207 this.markInvalid(this.regexText);
17214 * Selects text in this field
17215 * @param {Number} start (optional) The index where the selection should start (defaults to 0)
17216 * @param {Number} end (optional) The index where the selection should end (defaults to the text length)
17218 selectText : function(start, end){
17219 var v = this.getRawValue();
17221 start = start === undefined ? 0 : start;
17222 end = end === undefined ? v.length : end;
17223 var d = this.el.dom;
17224 if(d.setSelectionRange){
17225 d.setSelectionRange(start, end);
17226 }else if(d.createTextRange){
17227 var range = d.createTextRange();
17228 range.moveStart("character", start);
17229 range.moveEnd("character", v.length-end);
17236 * Automatically grows the field to accomodate the width of the text up to the maximum field width allowed.
17237 * This only takes effect if grow = true, and fires the autosize event.
17239 autoSize : function(){
17240 if(!this.grow || !this.rendered){
17244 this.metrics = Roo.util.TextMetrics.createInstance(this.el);
17247 var v = el.dom.value;
17248 var d = document.createElement('div');
17249 d.appendChild(document.createTextNode(v));
17253 var w = Math.min(this.growMax, Math.max(this.metrics.getWidth(v) + /* add extra padding */ 10, this.growMin));
17254 this.el.setWidth(w);
17255 this.fireEvent("autosize", this, w);
17259 SafariOnKeyDown : function(event)
17261 // this is a workaround for a password hang bug on chrome/ webkit.
17263 var isSelectAll = false;
17265 if(this.el.dom.selectionEnd > 0){
17266 isSelectAll = (this.el.dom.selectionEnd - this.el.dom.selectionStart - this.getValue().length == 0) ? true : false;
17268 if(((event.getKey() == 8 || event.getKey() == 46) && this.getValue().length ==1)){ // backspace and delete key
17269 event.preventDefault();
17274 if(isSelectAll && event.getCharCode() > 31){ // backspace and delete key
17276 event.preventDefault();
17277 // this is very hacky as keydown always get's upper case.
17279 var cc = String.fromCharCode(event.getCharCode());
17282 this.setValue( event.shiftKey ? cc : cc.toLowerCase());
17290 * Ext JS Library 1.1.1
17291 * Copyright(c) 2006-2007, Ext JS, LLC.
17293 * Originally Released Under LGPL - original licence link has changed is not relivant.
17296 * <script type="text/javascript">
17300 * @class Roo.form.Hidden
17301 * @extends Roo.form.TextField
17302 * Simple Hidden element used on forms
17304 * usage: form.add(new Roo.form.HiddenField({ 'name' : 'test1' }));
17307 * Creates a new Hidden form element.
17308 * @param {Object} config Configuration options
17313 // easy hidden field...
17314 Roo.form.Hidden = function(config){
17315 Roo.form.Hidden.superclass.constructor.call(this, config);
17318 Roo.extend(Roo.form.Hidden, Roo.form.TextField, {
17320 inputType: 'hidden',
17323 labelSeparator: '',
17325 itemCls : 'x-form-item-display-none'
17333 * Ext JS Library 1.1.1
17334 * Copyright(c) 2006-2007, Ext JS, LLC.
17336 * Originally Released Under LGPL - original licence link has changed is not relivant.
17339 * <script type="text/javascript">
17343 * @class Roo.form.TriggerField
17344 * @extends Roo.form.TextField
17345 * Provides a convenient wrapper for TextFields that adds a clickable trigger button (looks like a combobox by default).
17346 * The trigger has no default action, so you must assign a function to implement the trigger click handler by
17347 * overriding {@link #onTriggerClick}. You can create a TriggerField directly, as it renders exactly like a combobox
17348 * for which you can provide a custom implementation. For example:
17350 var trigger = new Roo.form.TriggerField();
17351 trigger.onTriggerClick = myTriggerFn;
17352 trigger.applyTo('my-field');
17355 * However, in general you will most likely want to use TriggerField as the base class for a reusable component.
17356 * {@link Roo.form.DateField} and {@link Roo.form.ComboBox} are perfect examples of this.
17357 * @cfg {String} triggerClass An additional CSS class used to style the trigger button. The trigger will always get the
17358 * class 'x-form-trigger' by default and triggerClass will be <b>appended</b> if specified.
17360 * Create a new TriggerField.
17361 * @param {Object} config Configuration options (valid {@Roo.form.TextField} config options will also be applied
17362 * to the base TextField)
17364 Roo.form.TriggerField = function(config){
17365 this.mimicing = false;
17366 Roo.form.TriggerField.superclass.constructor.call(this, config);
17369 Roo.extend(Roo.form.TriggerField, Roo.form.TextField, {
17371 * @cfg {String} triggerClass A CSS class to apply to the trigger
17374 * @cfg {String/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to
17375 * {tag: "input", type: "text", size: "16", autocomplete: "off"})
17377 defaultAutoCreate : {tag: "input", type: "text", size: "16", autocomplete: "new-password"},
17379 * @cfg {Boolean} hideTrigger True to hide the trigger element and display only the base text field (defaults to false)
17383 /** @cfg {Boolean} grow @hide */
17384 /** @cfg {Number} growMin @hide */
17385 /** @cfg {Number} growMax @hide */
17391 autoSize: Roo.emptyFn,
17395 deferHeight : true,
17398 actionMode : 'wrap',
17400 onResize : function(w, h){
17401 Roo.form.TriggerField.superclass.onResize.apply(this, arguments);
17402 if(typeof w == 'number'){
17403 var x = w - this.trigger.getWidth();
17404 this.el.setWidth(this.adjustWidth('input', x));
17405 this.trigger.setStyle('left', x+'px');
17410 adjustSize : Roo.BoxComponent.prototype.adjustSize,
17413 getResizeEl : function(){
17418 getPositionEl : function(){
17423 alignErrorIcon : function(){
17424 this.errorIcon.alignTo(this.wrap, 'tl-tr', [2, 0]);
17428 onRender : function(ct, position){
17429 Roo.form.TriggerField.superclass.onRender.call(this, ct, position);
17430 this.wrap = this.el.wrap({cls: "x-form-field-wrap"});
17431 this.trigger = this.wrap.createChild(this.triggerConfig ||
17432 {tag: "img", src: Roo.BLANK_IMAGE_URL, cls: "x-form-trigger " + this.triggerClass});
17433 if(this.hideTrigger){
17434 this.trigger.setDisplayed(false);
17436 this.initTrigger();
17438 this.wrap.setWidth(this.el.getWidth()+this.trigger.getWidth());
17443 initTrigger : function(){
17444 this.trigger.on("click", this.onTriggerClick, this, {preventDefault:true});
17445 this.trigger.addClassOnOver('x-form-trigger-over');
17446 this.trigger.addClassOnClick('x-form-trigger-click');
17450 onDestroy : function(){
17452 this.trigger.removeAllListeners();
17453 this.trigger.remove();
17456 this.wrap.remove();
17458 Roo.form.TriggerField.superclass.onDestroy.call(this);
17462 onFocus : function(){
17463 Roo.form.TriggerField.superclass.onFocus.call(this);
17464 if(!this.mimicing){
17465 this.wrap.addClass('x-trigger-wrap-focus');
17466 this.mimicing = true;
17467 Roo.get(Roo.isIE ? document.body : document).on("mousedown", this.mimicBlur, this);
17468 if(this.monitorTab){
17469 this.el.on("keydown", this.checkTab, this);
17475 checkTab : function(e){
17476 if(e.getKey() == e.TAB){
17477 this.triggerBlur();
17482 onBlur : function(){
17487 mimicBlur : function(e, t){
17488 if(!this.wrap.contains(t) && this.validateBlur()){
17489 this.triggerBlur();
17494 triggerBlur : function(){
17495 this.mimicing = false;
17496 Roo.get(Roo.isIE ? document.body : document).un("mousedown", this.mimicBlur);
17497 if(this.monitorTab){
17498 this.el.un("keydown", this.checkTab, this);
17500 this.wrap.removeClass('x-trigger-wrap-focus');
17501 Roo.form.TriggerField.superclass.onBlur.call(this);
17505 // This should be overriden by any subclass that needs to check whether or not the field can be blurred.
17506 validateBlur : function(e, t){
17511 onDisable : function(){
17512 Roo.form.TriggerField.superclass.onDisable.call(this);
17514 this.wrap.addClass('x-item-disabled');
17519 onEnable : function(){
17520 Roo.form.TriggerField.superclass.onEnable.call(this);
17522 this.wrap.removeClass('x-item-disabled');
17527 onShow : function(){
17528 var ae = this.getActionEl();
17531 ae.dom.style.display = '';
17532 ae.dom.style.visibility = 'visible';
17538 onHide : function(){
17539 var ae = this.getActionEl();
17540 ae.dom.style.display = 'none';
17544 * The function that should handle the trigger's click event. This method does nothing by default until overridden
17545 * by an implementing function.
17547 * @param {EventObject} e
17549 onTriggerClick : Roo.emptyFn
17552 // TwinTriggerField is not a public class to be used directly. It is meant as an abstract base class
17553 // to be extended by an implementing class. For an example of implementing this class, see the custom
17554 // SearchField implementation here: http://extjs.com/deploy/ext/examples/form/custom.html
17555 Roo.form.TwinTriggerField = Roo.extend(Roo.form.TriggerField, {
17556 initComponent : function(){
17557 Roo.form.TwinTriggerField.superclass.initComponent.call(this);
17559 this.triggerConfig = {
17560 tag:'span', cls:'x-form-twin-triggers', cn:[
17561 {tag: "img", src: Roo.BLANK_IMAGE_URL, cls: "x-form-trigger " + this.trigger1Class},
17562 {tag: "img", src: Roo.BLANK_IMAGE_URL, cls: "x-form-trigger " + this.trigger2Class}
17566 getTrigger : function(index){
17567 return this.triggers[index];
17570 initTrigger : function(){
17571 var ts = this.trigger.select('.x-form-trigger', true);
17572 this.wrap.setStyle('overflow', 'hidden');
17573 var triggerField = this;
17574 ts.each(function(t, all, index){
17575 t.hide = function(){
17576 var w = triggerField.wrap.getWidth();
17577 this.dom.style.display = 'none';
17578 triggerField.el.setWidth(w-triggerField.trigger.getWidth());
17580 t.show = function(){
17581 var w = triggerField.wrap.getWidth();
17582 this.dom.style.display = '';
17583 triggerField.el.setWidth(w-triggerField.trigger.getWidth());
17585 var triggerIndex = 'Trigger'+(index+1);
17587 if(this['hide'+triggerIndex]){
17588 t.dom.style.display = 'none';
17590 t.on("click", this['on'+triggerIndex+'Click'], this, {preventDefault:true});
17591 t.addClassOnOver('x-form-trigger-over');
17592 t.addClassOnClick('x-form-trigger-click');
17594 this.triggers = ts.elements;
17597 onTrigger1Click : Roo.emptyFn,
17598 onTrigger2Click : Roo.emptyFn
17601 * Ext JS Library 1.1.1
17602 * Copyright(c) 2006-2007, Ext JS, LLC.
17604 * Originally Released Under LGPL - original licence link has changed is not relivant.
17607 * <script type="text/javascript">
17611 * @class Roo.form.TextArea
17612 * @extends Roo.form.TextField
17613 * Multiline text field. Can be used as a direct replacement for traditional textarea fields, plus adds
17614 * support for auto-sizing.
17616 * Creates a new TextArea
17617 * @param {Object} config Configuration options
17619 Roo.form.TextArea = function(config){
17620 Roo.form.TextArea.superclass.constructor.call(this, config);
17621 // these are provided exchanges for backwards compat
17622 // minHeight/maxHeight were replaced by growMin/growMax to be
17623 // compatible with TextField growing config values
17624 if(this.minHeight !== undefined){
17625 this.growMin = this.minHeight;
17627 if(this.maxHeight !== undefined){
17628 this.growMax = this.maxHeight;
17632 Roo.extend(Roo.form.TextArea, Roo.form.TextField, {
17634 * @cfg {Number} growMin The minimum height to allow when grow = true (defaults to 60)
17638 * @cfg {Number} growMax The maximum height to allow when grow = true (defaults to 1000)
17642 * @cfg {Boolean} preventScrollbars True to prevent scrollbars from appearing regardless of how much text is
17643 * in the field (equivalent to setting overflow: hidden, defaults to false)
17645 preventScrollbars: false,
17647 * @cfg {String/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to
17648 * {tag: "textarea", style: "width:300px;height:60px;", autocomplete: "off"})
17652 onRender : function(ct, position){
17654 this.defaultAutoCreate = {
17656 style:"width:300px;height:60px;",
17657 autocomplete: "new-password"
17660 Roo.form.TextArea.superclass.onRender.call(this, ct, position);
17662 this.textSizeEl = Roo.DomHelper.append(document.body, {
17663 tag: "pre", cls: "x-form-grow-sizer"
17665 if(this.preventScrollbars){
17666 this.el.setStyle("overflow", "hidden");
17668 this.el.setHeight(this.growMin);
17672 onDestroy : function(){
17673 if(this.textSizeEl){
17674 this.textSizeEl.parentNode.removeChild(this.textSizeEl);
17676 Roo.form.TextArea.superclass.onDestroy.call(this);
17680 onKeyUp : function(e){
17681 if(!e.isNavKeyPress() || e.getKey() == e.ENTER){
17687 * Automatically grows the field to accomodate the height of the text up to the maximum field height allowed.
17688 * This only takes effect if grow = true, and fires the autosize event if the height changes.
17690 autoSize : function(){
17691 if(!this.grow || !this.textSizeEl){
17695 var v = el.dom.value;
17696 var ts = this.textSizeEl;
17699 ts.appendChild(document.createTextNode(v));
17702 Roo.fly(ts).setWidth(this.el.getWidth());
17704 v = "  ";
17707 v = v.replace(/\n/g, '<p> </p>');
17709 v += " \n ";
17712 var h = Math.min(this.growMax, Math.max(ts.offsetHeight, this.growMin));
17713 if(h != this.lastHeight){
17714 this.lastHeight = h;
17715 this.el.setHeight(h);
17716 this.fireEvent("autosize", this, h);
17721 * Ext JS Library 1.1.1
17722 * Copyright(c) 2006-2007, Ext JS, LLC.
17724 * Originally Released Under LGPL - original licence link has changed is not relivant.
17727 * <script type="text/javascript">
17732 * @class Roo.form.NumberField
17733 * @extends Roo.form.TextField
17734 * Numeric text field that provides automatic keystroke filtering and numeric validation.
17736 * Creates a new NumberField
17737 * @param {Object} config Configuration options
17739 Roo.form.NumberField = function(config){
17740 Roo.form.NumberField.superclass.constructor.call(this, config);
17743 Roo.extend(Roo.form.NumberField, Roo.form.TextField, {
17745 * @cfg {String} fieldClass The default CSS class for the field (defaults to "x-form-field x-form-num-field")
17747 fieldClass: "x-form-field x-form-num-field",
17749 * @cfg {Boolean} allowDecimals False to disallow decimal values (defaults to true)
17751 allowDecimals : true,
17753 * @cfg {String} decimalSeparator Character(s) to allow as the decimal separator (defaults to '.')
17755 decimalSeparator : ".",
17757 * @cfg {Number} decimalPrecision The maximum precision to display after the decimal separator (defaults to 2)
17759 decimalPrecision : 2,
17761 * @cfg {Boolean} allowNegative False to prevent entering a negative sign (defaults to true)
17763 allowNegative : true,
17765 * @cfg {Number} minValue The minimum allowed value (defaults to Number.NEGATIVE_INFINITY)
17767 minValue : Number.NEGATIVE_INFINITY,
17769 * @cfg {Number} maxValue The maximum allowed value (defaults to Number.MAX_VALUE)
17771 maxValue : Number.MAX_VALUE,
17773 * @cfg {String} minText Error text to display if the minimum value validation fails (defaults to "The minimum value for this field is {minValue}")
17775 minText : "The minimum value for this field is {0}",
17777 * @cfg {String} maxText Error text to display if the maximum value validation fails (defaults to "The maximum value for this field is {maxValue}")
17779 maxText : "The maximum value for this field is {0}",
17781 * @cfg {String} nanText Error text to display if the value is not a valid number. For example, this can happen
17782 * if a valid character like '.' or '-' is left in the field with no number (defaults to "{value} is not a valid number")
17784 nanText : "{0} is not a valid number",
17787 initEvents : function(){
17788 Roo.form.NumberField.superclass.initEvents.call(this);
17789 var allowed = "0123456789";
17790 if(this.allowDecimals){
17791 allowed += this.decimalSeparator;
17793 if(this.allowNegative){
17796 this.stripCharsRe = new RegExp('[^'+allowed+']', 'gi');
17797 var keyPress = function(e){
17798 var k = e.getKey();
17799 if(!Roo.isIE && (e.isSpecialKey() || k == e.BACKSPACE || k == e.DELETE)){
17802 var c = e.getCharCode();
17803 if(allowed.indexOf(String.fromCharCode(c)) === -1){
17807 this.el.on("keypress", keyPress, this);
17811 validateValue : function(value){
17812 if(!Roo.form.NumberField.superclass.validateValue.call(this, value)){
17815 if(value.length < 1){ // if it's blank and textfield didn't flag it then it's valid
17818 var num = this.parseValue(value);
17820 this.markInvalid(String.format(this.nanText, value));
17823 if(num < this.minValue){
17824 this.markInvalid(String.format(this.minText, this.minValue));
17827 if(num > this.maxValue){
17828 this.markInvalid(String.format(this.maxText, this.maxValue));
17834 getValue : function(){
17835 return this.fixPrecision(this.parseValue(Roo.form.NumberField.superclass.getValue.call(this)));
17839 parseValue : function(value){
17840 value = parseFloat(String(value).replace(this.decimalSeparator, "."));
17841 return isNaN(value) ? '' : value;
17845 fixPrecision : function(value){
17846 var nan = isNaN(value);
17847 if(!this.allowDecimals || this.decimalPrecision == -1 || nan || !value){
17848 return nan ? '' : value;
17850 return parseFloat(value).toFixed(this.decimalPrecision);
17853 setValue : function(v){
17854 v = this.fixPrecision(v);
17855 Roo.form.NumberField.superclass.setValue.call(this, String(v).replace(".", this.decimalSeparator));
17859 decimalPrecisionFcn : function(v){
17860 return Math.floor(v);
17863 beforeBlur : function(){
17864 var v = this.parseValue(this.getRawValue());
17871 * Ext JS Library 1.1.1
17872 * Copyright(c) 2006-2007, Ext JS, LLC.
17874 * Originally Released Under LGPL - original licence link has changed is not relivant.
17877 * <script type="text/javascript">
17881 * @class Roo.form.DateField
17882 * @extends Roo.form.TriggerField
17883 * Provides a date input field with a {@link Roo.DatePicker} dropdown and automatic date validation.
17885 * Create a new DateField
17886 * @param {Object} config
17888 Roo.form.DateField = function(config)
17890 Roo.form.DateField.superclass.constructor.call(this, config);
17896 * Fires when a date is selected
17897 * @param {Roo.form.DateField} combo This combo box
17898 * @param {Date} date The date selected
17905 if(typeof this.minValue == "string") {
17906 this.minValue = this.parseDate(this.minValue);
17908 if(typeof this.maxValue == "string") {
17909 this.maxValue = this.parseDate(this.maxValue);
17911 this.ddMatch = null;
17912 if(this.disabledDates){
17913 var dd = this.disabledDates;
17915 for(var i = 0; i < dd.length; i++){
17917 if(i != dd.length-1) {
17921 this.ddMatch = new RegExp(re + ")");
17925 Roo.extend(Roo.form.DateField, Roo.form.TriggerField, {
17927 * @cfg {String} format
17928 * The default date format string which can be overriden for localization support. The format must be
17929 * valid according to {@link Date#parseDate} (defaults to 'm/d/y').
17933 * @cfg {String} altFormats
17934 * Multiple date formats separated by "|" to try when parsing a user input value and it doesn't match the defined
17935 * format (defaults to 'm/d/Y|m-d-y|m-d-Y|m/d|m-d|d').
17937 altFormats : "m/d/Y|m-d-y|m-d-Y|m/d|m-d|md|mdy|mdY|d",
17939 * @cfg {Array} disabledDays
17940 * An array of days to disable, 0 based. For example, [0, 6] disables Sunday and Saturday (defaults to null).
17942 disabledDays : null,
17944 * @cfg {String} disabledDaysText
17945 * The tooltip to display when the date falls on a disabled day (defaults to 'Disabled')
17947 disabledDaysText : "Disabled",
17949 * @cfg {Array} disabledDates
17950 * An array of "dates" to disable, as strings. These strings will be used to build a dynamic regular
17951 * expression so they are very powerful. Some examples:
17953 * <li>["03/08/2003", "09/16/2003"] would disable those exact dates</li>
17954 * <li>["03/08", "09/16"] would disable those days for every year</li>
17955 * <li>["^03/08"] would only match the beginning (useful if you are using short years)</li>
17956 * <li>["03/../2006"] would disable every day in March 2006</li>
17957 * <li>["^03"] would disable every day in every March</li>
17959 * In order to support regular expressions, if you are using a date format that has "." in it, you will have to
17960 * escape the dot when restricting dates. For example: ["03\\.08\\.03"].
17962 disabledDates : null,
17964 * @cfg {String} disabledDatesText
17965 * The tooltip text to display when the date falls on a disabled date (defaults to 'Disabled')
17967 disabledDatesText : "Disabled",
17969 * @cfg {Date/String} minValue
17970 * The minimum allowed date. Can be either a Javascript date object or a string date in a
17971 * valid format (defaults to null).
17975 * @cfg {Date/String} maxValue
17976 * The maximum allowed date. Can be either a Javascript date object or a string date in a
17977 * valid format (defaults to null).
17981 * @cfg {String} minText
17982 * The error text to display when the date in the cell is before minValue (defaults to
17983 * 'The date in this field must be after {minValue}').
17985 minText : "The date in this field must be equal to or after {0}",
17987 * @cfg {String} maxText
17988 * The error text to display when the date in the cell is after maxValue (defaults to
17989 * 'The date in this field must be before {maxValue}').
17991 maxText : "The date in this field must be equal to or before {0}",
17993 * @cfg {String} invalidText
17994 * The error text to display when the date in the field is invalid (defaults to
17995 * '{value} is not a valid date - it must be in the format {format}').
17997 invalidText : "{0} is not a valid date - it must be in the format {1}",
17999 * @cfg {String} triggerClass
18000 * An additional CSS class used to style the trigger button. The trigger will always get the
18001 * class 'x-form-trigger' and triggerClass will be <b>appended</b> if specified (defaults to 'x-form-date-trigger'
18002 * which displays a calendar icon).
18004 triggerClass : 'x-form-date-trigger',
18008 * @cfg {Boolean} useIso
18009 * if enabled, then the date field will use a hidden field to store the
18010 * real value as iso formated date. default (false)
18014 * @cfg {String/Object} autoCreate
18015 * A DomHelper element spec, or true for a default element spec (defaults to
18016 * {tag: "input", type: "text", size: "10", autocomplete: "off"})
18019 defaultAutoCreate : {tag: "input", type: "text", size: "10", autocomplete: "off"},
18022 hiddenField: false,
18024 onRender : function(ct, position)
18026 Roo.form.DateField.superclass.onRender.call(this, ct, position);
18028 //this.el.dom.removeAttribute('name');
18029 Roo.log("Changing name?");
18030 this.el.dom.setAttribute('name', this.name + '____hidden___' );
18031 this.hiddenField = this.el.insertSibling({ tag:'input', type:'hidden', name: this.name },
18033 this.hiddenField.value = this.value ? this.formatDate(this.value, 'Y-m-d') : '';
18034 // prevent input submission
18035 this.hiddenName = this.name;
18042 validateValue : function(value)
18044 value = this.formatDate(value);
18045 if(!Roo.form.DateField.superclass.validateValue.call(this, value)){
18046 Roo.log('super failed');
18049 if(value.length < 1){ // if it's blank and textfield didn't flag it then it's valid
18052 var svalue = value;
18053 value = this.parseDate(value);
18055 Roo.log('parse date failed' + svalue);
18056 this.markInvalid(String.format(this.invalidText, svalue, this.format));
18059 var time = value.getTime();
18060 if(this.minValue && time < this.minValue.getTime()){
18061 this.markInvalid(String.format(this.minText, this.formatDate(this.minValue)));
18064 if(this.maxValue && time > this.maxValue.getTime()){
18065 this.markInvalid(String.format(this.maxText, this.formatDate(this.maxValue)));
18068 if(this.disabledDays){
18069 var day = value.getDay();
18070 for(var i = 0; i < this.disabledDays.length; i++) {
18071 if(day === this.disabledDays[i]){
18072 this.markInvalid(this.disabledDaysText);
18077 var fvalue = this.formatDate(value);
18078 if(this.ddMatch && this.ddMatch.test(fvalue)){
18079 this.markInvalid(String.format(this.disabledDatesText, fvalue));
18086 // Provides logic to override the default TriggerField.validateBlur which just returns true
18087 validateBlur : function(){
18088 return !this.menu || !this.menu.isVisible();
18091 getName: function()
18093 // returns hidden if it's set..
18094 if (!this.rendered) {return ''};
18095 return !this.hiddenName && this.el.dom.name ? this.el.dom.name : (this.hiddenName || '');
18100 * Returns the current date value of the date field.
18101 * @return {Date} The date value
18103 getValue : function(){
18105 return this.hiddenField ?
18106 this.hiddenField.value :
18107 this.parseDate(Roo.form.DateField.superclass.getValue.call(this)) || "";
18111 * Sets the value of the date field. You can pass a date object or any string that can be parsed into a valid
18112 * date, using DateField.format as the date format, according to the same rules as {@link Date#parseDate}
18113 * (the default format used is "m/d/y").
18116 //All of these calls set the same date value (May 4, 2006)
18118 //Pass a date object:
18119 var dt = new Date('5/4/06');
18120 dateField.setValue(dt);
18122 //Pass a date string (default format):
18123 dateField.setValue('5/4/06');
18125 //Pass a date string (custom format):
18126 dateField.format = 'Y-m-d';
18127 dateField.setValue('2006-5-4');
18129 * @param {String/Date} date The date or valid date string
18131 setValue : function(date){
18132 if (this.hiddenField) {
18133 this.hiddenField.value = this.formatDate(this.parseDate(date), 'Y-m-d');
18135 Roo.form.DateField.superclass.setValue.call(this, this.formatDate(this.parseDate(date)));
18136 // make sure the value field is always stored as a date..
18137 this.value = this.parseDate(date);
18143 parseDate : function(value){
18144 if(!value || value instanceof Date){
18147 var v = Date.parseDate(value, this.format);
18148 if (!v && this.useIso) {
18149 v = Date.parseDate(value, 'Y-m-d');
18151 if(!v && this.altFormats){
18152 if(!this.altFormatsArray){
18153 this.altFormatsArray = this.altFormats.split("|");
18155 for(var i = 0, len = this.altFormatsArray.length; i < len && !v; i++){
18156 v = Date.parseDate(value, this.altFormatsArray[i]);
18163 formatDate : function(date, fmt){
18164 return (!date || !(date instanceof Date)) ?
18165 date : date.dateFormat(fmt || this.format);
18170 select: function(m, d){
18173 this.fireEvent('select', this, d);
18175 show : function(){ // retain focus styling
18179 this.focus.defer(10, this);
18180 var ml = this.menuListeners;
18181 this.menu.un("select", ml.select, this);
18182 this.menu.un("show", ml.show, this);
18183 this.menu.un("hide", ml.hide, this);
18188 // Implements the default empty TriggerField.onTriggerClick function to display the DatePicker
18189 onTriggerClick : function(){
18193 if(this.menu == null){
18194 this.menu = new Roo.menu.DateMenu();
18196 Roo.apply(this.menu.picker, {
18197 showClear: this.allowBlank,
18198 minDate : this.minValue,
18199 maxDate : this.maxValue,
18200 disabledDatesRE : this.ddMatch,
18201 disabledDatesText : this.disabledDatesText,
18202 disabledDays : this.disabledDays,
18203 disabledDaysText : this.disabledDaysText,
18204 format : this.useIso ? 'Y-m-d' : this.format,
18205 minText : String.format(this.minText, this.formatDate(this.minValue)),
18206 maxText : String.format(this.maxText, this.formatDate(this.maxValue))
18208 this.menu.on(Roo.apply({}, this.menuListeners, {
18211 this.menu.picker.setValue(this.getValue() || new Date());
18212 this.menu.show(this.el, "tl-bl?");
18215 beforeBlur : function(){
18216 var v = this.parseDate(this.getRawValue());
18226 isDirty : function() {
18227 if(this.disabled) {
18231 if(typeof(this.startValue) === 'undefined'){
18235 return String(this.getValue()) !== String(this.startValue);
18239 cleanLeadingSpace : function(e)
18246 * Ext JS Library 1.1.1
18247 * Copyright(c) 2006-2007, Ext JS, LLC.
18249 * Originally Released Under LGPL - original licence link has changed is not relivant.
18252 * <script type="text/javascript">
18256 * @class Roo.form.MonthField
18257 * @extends Roo.form.TriggerField
18258 * Provides a date input field with a {@link Roo.DatePicker} dropdown and automatic date validation.
18260 * Create a new MonthField
18261 * @param {Object} config
18263 Roo.form.MonthField = function(config){
18265 Roo.form.MonthField.superclass.constructor.call(this, config);
18271 * Fires when a date is selected
18272 * @param {Roo.form.MonthFieeld} combo This combo box
18273 * @param {Date} date The date selected
18280 if(typeof this.minValue == "string") {
18281 this.minValue = this.parseDate(this.minValue);
18283 if(typeof this.maxValue == "string") {
18284 this.maxValue = this.parseDate(this.maxValue);
18286 this.ddMatch = null;
18287 if(this.disabledDates){
18288 var dd = this.disabledDates;
18290 for(var i = 0; i < dd.length; i++){
18292 if(i != dd.length-1) {
18296 this.ddMatch = new RegExp(re + ")");
18300 Roo.extend(Roo.form.MonthField, Roo.form.TriggerField, {
18302 * @cfg {String} format
18303 * The default date format string which can be overriden for localization support. The format must be
18304 * valid according to {@link Date#parseDate} (defaults to 'm/d/y').
18308 * @cfg {String} altFormats
18309 * Multiple date formats separated by "|" to try when parsing a user input value and it doesn't match the defined
18310 * format (defaults to 'm/d/Y|m-d-y|m-d-Y|m/d|m-d|d').
18312 altFormats : "M Y|m/Y|m-y|m-Y|my|mY",
18314 * @cfg {Array} disabledDays
18315 * An array of days to disable, 0 based. For example, [0, 6] disables Sunday and Saturday (defaults to null).
18317 disabledDays : [0,1,2,3,4,5,6],
18319 * @cfg {String} disabledDaysText
18320 * The tooltip to display when the date falls on a disabled day (defaults to 'Disabled')
18322 disabledDaysText : "Disabled",
18324 * @cfg {Array} disabledDates
18325 * An array of "dates" to disable, as strings. These strings will be used to build a dynamic regular
18326 * expression so they are very powerful. Some examples:
18328 * <li>["03/08/2003", "09/16/2003"] would disable those exact dates</li>
18329 * <li>["03/08", "09/16"] would disable those days for every year</li>
18330 * <li>["^03/08"] would only match the beginning (useful if you are using short years)</li>
18331 * <li>["03/../2006"] would disable every day in March 2006</li>
18332 * <li>["^03"] would disable every day in every March</li>
18334 * In order to support regular expressions, if you are using a date format that has "." in it, you will have to
18335 * escape the dot when restricting dates. For example: ["03\\.08\\.03"].
18337 disabledDates : null,
18339 * @cfg {String} disabledDatesText
18340 * The tooltip text to display when the date falls on a disabled date (defaults to 'Disabled')
18342 disabledDatesText : "Disabled",
18344 * @cfg {Date/String} minValue
18345 * The minimum allowed date. Can be either a Javascript date object or a string date in a
18346 * valid format (defaults to null).
18350 * @cfg {Date/String} maxValue
18351 * The maximum allowed date. Can be either a Javascript date object or a string date in a
18352 * valid format (defaults to null).
18356 * @cfg {String} minText
18357 * The error text to display when the date in the cell is before minValue (defaults to
18358 * 'The date in this field must be after {minValue}').
18360 minText : "The date in this field must be equal to or after {0}",
18362 * @cfg {String} maxTextf
18363 * The error text to display when the date in the cell is after maxValue (defaults to
18364 * 'The date in this field must be before {maxValue}').
18366 maxText : "The date in this field must be equal to or before {0}",
18368 * @cfg {String} invalidText
18369 * The error text to display when the date in the field is invalid (defaults to
18370 * '{value} is not a valid date - it must be in the format {format}').
18372 invalidText : "{0} is not a valid date - it must be in the format {1}",
18374 * @cfg {String} triggerClass
18375 * An additional CSS class used to style the trigger button. The trigger will always get the
18376 * class 'x-form-trigger' and triggerClass will be <b>appended</b> if specified (defaults to 'x-form-date-trigger'
18377 * which displays a calendar icon).
18379 triggerClass : 'x-form-date-trigger',
18383 * @cfg {Boolean} useIso
18384 * if enabled, then the date field will use a hidden field to store the
18385 * real value as iso formated date. default (true)
18389 * @cfg {String/Object} autoCreate
18390 * A DomHelper element spec, or true for a default element spec (defaults to
18391 * {tag: "input", type: "text", size: "10", autocomplete: "off"})
18394 defaultAutoCreate : {tag: "input", type: "text", size: "10", autocomplete: "new-password"},
18397 hiddenField: false,
18399 hideMonthPicker : false,
18401 onRender : function(ct, position)
18403 Roo.form.MonthField.superclass.onRender.call(this, ct, position);
18405 this.el.dom.removeAttribute('name');
18406 this.hiddenField = this.el.insertSibling({ tag:'input', type:'hidden', name: this.name },
18408 this.hiddenField.value = this.value ? this.formatDate(this.value, 'Y-m-d') : '';
18409 // prevent input submission
18410 this.hiddenName = this.name;
18417 validateValue : function(value)
18419 value = this.formatDate(value);
18420 if(!Roo.form.MonthField.superclass.validateValue.call(this, value)){
18423 if(value.length < 1){ // if it's blank and textfield didn't flag it then it's valid
18426 var svalue = value;
18427 value = this.parseDate(value);
18429 this.markInvalid(String.format(this.invalidText, svalue, this.format));
18432 var time = value.getTime();
18433 if(this.minValue && time < this.minValue.getTime()){
18434 this.markInvalid(String.format(this.minText, this.formatDate(this.minValue)));
18437 if(this.maxValue && time > this.maxValue.getTime()){
18438 this.markInvalid(String.format(this.maxText, this.formatDate(this.maxValue)));
18441 /*if(this.disabledDays){
18442 var day = value.getDay();
18443 for(var i = 0; i < this.disabledDays.length; i++) {
18444 if(day === this.disabledDays[i]){
18445 this.markInvalid(this.disabledDaysText);
18451 var fvalue = this.formatDate(value);
18452 /*if(this.ddMatch && this.ddMatch.test(fvalue)){
18453 this.markInvalid(String.format(this.disabledDatesText, fvalue));
18461 // Provides logic to override the default TriggerField.validateBlur which just returns true
18462 validateBlur : function(){
18463 return !this.menu || !this.menu.isVisible();
18467 * Returns the current date value of the date field.
18468 * @return {Date} The date value
18470 getValue : function(){
18474 return this.hiddenField ?
18475 this.hiddenField.value :
18476 this.parseDate(Roo.form.MonthField.superclass.getValue.call(this)) || "";
18480 * Sets the value of the date field. You can pass a date object or any string that can be parsed into a valid
18481 * date, using MonthField.format as the date format, according to the same rules as {@link Date#parseDate}
18482 * (the default format used is "m/d/y").
18485 //All of these calls set the same date value (May 4, 2006)
18487 //Pass a date object:
18488 var dt = new Date('5/4/06');
18489 monthField.setValue(dt);
18491 //Pass a date string (default format):
18492 monthField.setValue('5/4/06');
18494 //Pass a date string (custom format):
18495 monthField.format = 'Y-m-d';
18496 monthField.setValue('2006-5-4');
18498 * @param {String/Date} date The date or valid date string
18500 setValue : function(date){
18501 Roo.log('month setValue' + date);
18502 // can only be first of month..
18504 var val = this.parseDate(date);
18506 if (this.hiddenField) {
18507 this.hiddenField.value = this.formatDate(this.parseDate(date), 'Y-m-d');
18509 Roo.form.MonthField.superclass.setValue.call(this, this.formatDate(this.parseDate(date)));
18510 this.value = this.parseDate(date);
18514 parseDate : function(value){
18515 if(!value || value instanceof Date){
18516 value = value ? Date.parseDate(value.format('Y-m') + '-01', 'Y-m-d') : null;
18519 var v = Date.parseDate(value, this.format);
18520 if (!v && this.useIso) {
18521 v = Date.parseDate(value, 'Y-m-d');
18525 v = Date.parseDate(v.format('Y-m') +'-01', 'Y-m-d');
18529 if(!v && this.altFormats){
18530 if(!this.altFormatsArray){
18531 this.altFormatsArray = this.altFormats.split("|");
18533 for(var i = 0, len = this.altFormatsArray.length; i < len && !v; i++){
18534 v = Date.parseDate(value, this.altFormatsArray[i]);
18541 formatDate : function(date, fmt){
18542 return (!date || !(date instanceof Date)) ?
18543 date : date.dateFormat(fmt || this.format);
18548 select: function(m, d){
18550 this.fireEvent('select', this, d);
18552 show : function(){ // retain focus styling
18556 this.focus.defer(10, this);
18557 var ml = this.menuListeners;
18558 this.menu.un("select", ml.select, this);
18559 this.menu.un("show", ml.show, this);
18560 this.menu.un("hide", ml.hide, this);
18564 // Implements the default empty TriggerField.onTriggerClick function to display the DatePicker
18565 onTriggerClick : function(){
18569 if(this.menu == null){
18570 this.menu = new Roo.menu.DateMenu();
18574 Roo.apply(this.menu.picker, {
18576 showClear: this.allowBlank,
18577 minDate : this.minValue,
18578 maxDate : this.maxValue,
18579 disabledDatesRE : this.ddMatch,
18580 disabledDatesText : this.disabledDatesText,
18582 format : this.useIso ? 'Y-m-d' : this.format,
18583 minText : String.format(this.minText, this.formatDate(this.minValue)),
18584 maxText : String.format(this.maxText, this.formatDate(this.maxValue))
18587 this.menu.on(Roo.apply({}, this.menuListeners, {
18595 // hide month picker get's called when we called by 'before hide';
18597 var ignorehide = true;
18598 p.hideMonthPicker = function(disableAnim){
18602 if(this.monthPicker){
18603 Roo.log("hideMonthPicker called");
18604 if(disableAnim === true){
18605 this.monthPicker.hide();
18607 this.monthPicker.slideOut('t', {duration:.2});
18608 p.setValue(new Date(m.picker.mpSelYear, m.picker.mpSelMonth, 1));
18609 p.fireEvent("select", this, this.value);
18615 Roo.log('picker set value');
18616 Roo.log(this.getValue());
18617 p.setValue(this.getValue() ? this.parseDate(this.getValue()) : new Date());
18618 m.show(this.el, 'tl-bl?');
18619 ignorehide = false;
18620 // this will trigger hideMonthPicker..
18623 // hidden the day picker
18624 Roo.select('.x-date-picker table', true).first().dom.style.visibility = "hidden";
18630 p.showMonthPicker.defer(100, p);
18636 beforeBlur : function(){
18637 var v = this.parseDate(this.getRawValue());
18643 /** @cfg {Boolean} grow @hide */
18644 /** @cfg {Number} growMin @hide */
18645 /** @cfg {Number} growMax @hide */
18652 * Ext JS Library 1.1.1
18653 * Copyright(c) 2006-2007, Ext JS, LLC.
18655 * Originally Released Under LGPL - original licence link has changed is not relivant.
18658 * <script type="text/javascript">
18663 * @class Roo.form.ComboBox
18664 * @extends Roo.form.TriggerField
18665 * A combobox control with support for autocomplete, remote-loading, paging and many other features.
18667 * Create a new ComboBox.
18668 * @param {Object} config Configuration options
18670 Roo.form.ComboBox = function(config){
18671 Roo.form.ComboBox.superclass.constructor.call(this, config);
18675 * Fires when the dropdown list is expanded
18676 * @param {Roo.form.ComboBox} combo This combo box
18681 * Fires when the dropdown list is collapsed
18682 * @param {Roo.form.ComboBox} combo This combo box
18686 * @event beforeselect
18687 * Fires before a list item is selected. Return false to cancel the selection.
18688 * @param {Roo.form.ComboBox} combo This combo box
18689 * @param {Roo.data.Record} record The data record returned from the underlying store
18690 * @param {Number} index The index of the selected item in the dropdown list
18692 'beforeselect' : true,
18695 * Fires when a list item is selected
18696 * @param {Roo.form.ComboBox} combo This combo box
18697 * @param {Roo.data.Record} record The data record returned from the underlying store (or false on clear)
18698 * @param {Number} index The index of the selected item in the dropdown list
18702 * @event beforequery
18703 * Fires before all queries are processed. Return false to cancel the query or set cancel to true.
18704 * The event object passed has these properties:
18705 * @param {Roo.form.ComboBox} combo This combo box
18706 * @param {String} query The query
18707 * @param {Boolean} forceAll true to force "all" query
18708 * @param {Boolean} cancel true to cancel the query
18709 * @param {Object} e The query event object
18711 'beforequery': true,
18714 * Fires when the 'add' icon is pressed (add a listener to enable add button)
18715 * @param {Roo.form.ComboBox} combo This combo box
18720 * Fires when the 'edit' icon is pressed (add a listener to enable add button)
18721 * @param {Roo.form.ComboBox} combo This combo box
18722 * @param {Roo.data.Record|false} record The data record returned from the underlying store (or false on nothing selected)
18728 if(this.transform){
18729 this.allowDomMove = false;
18730 var s = Roo.getDom(this.transform);
18731 if(!this.hiddenName){
18732 this.hiddenName = s.name;
18735 this.mode = 'local';
18736 var d = [], opts = s.options;
18737 for(var i = 0, len = opts.length;i < len; i++){
18739 var value = (Roo.isIE ? o.getAttributeNode('value').specified : o.hasAttribute('value')) ? o.value : o.text;
18741 this.value = value;
18743 d.push([value, o.text]);
18745 this.store = new Roo.data.SimpleStore({
18747 fields: ['value', 'text'],
18750 this.valueField = 'value';
18751 this.displayField = 'text';
18753 s.name = Roo.id(); // wipe out the name in case somewhere else they have a reference
18754 if(!this.lazyRender){
18755 this.target = true;
18756 this.el = Roo.DomHelper.insertBefore(s, this.autoCreate || this.defaultAutoCreate);
18757 s.parentNode.removeChild(s); // remove it
18758 this.render(this.el.parentNode);
18760 s.parentNode.removeChild(s); // remove it
18765 this.store = Roo.factory(this.store, Roo.data);
18768 this.selectedIndex = -1;
18769 if(this.mode == 'local'){
18770 if(config.queryDelay === undefined){
18771 this.queryDelay = 10;
18773 if(config.minChars === undefined){
18779 Roo.extend(Roo.form.ComboBox, Roo.form.TriggerField, {
18781 * @cfg {String/HTMLElement/Element} transform The id, DOM node or element of an existing select to convert to a ComboBox
18784 * @cfg {Boolean} lazyRender True to prevent the ComboBox from rendering until requested (should always be used when
18785 * rendering into an Roo.Editor, defaults to false)
18788 * @cfg {Boolean/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to:
18789 * {tag: "input", type: "text", size: "24", autocomplete: "off"})
18792 * @cfg {Roo.data.Store} store The data store to which this combo is bound (defaults to undefined)
18795 * @cfg {String} title If supplied, a header element is created containing this text and added into the top of
18796 * the dropdown list (defaults to undefined, with no header element)
18800 * @cfg {String/Roo.Template} tpl The template to use to render the output
18804 defaultAutoCreate : {tag: "input", type: "text", size: "24", autocomplete: "off"},
18806 * @cfg {Number} listWidth The width in pixels of the dropdown list (defaults to the width of the ComboBox field)
18808 listWidth: undefined,
18810 * @cfg {String} displayField The underlying data field name to bind to this CombBox (defaults to undefined if
18811 * mode = 'remote' or 'text' if mode = 'local')
18813 displayField: undefined,
18815 * @cfg {String} valueField The underlying data value name to bind to this CombBox (defaults to undefined if
18816 * mode = 'remote' or 'value' if mode = 'local').
18817 * Note: use of a valueField requires the user make a selection
18818 * in order for a value to be mapped.
18820 valueField: undefined,
18824 * @cfg {String} hiddenName If specified, a hidden form field with this name is dynamically generated to store the
18825 * field's data value (defaults to the underlying DOM element's name)
18827 hiddenName: undefined,
18829 * @cfg {String} listClass CSS class to apply to the dropdown list element (defaults to '')
18833 * @cfg {String} selectedClass CSS class to apply to the selected item in the dropdown list (defaults to 'x-combo-selected')
18835 selectedClass: 'x-combo-selected',
18837 * @cfg {String} triggerClass An additional CSS class used to style the trigger button. The trigger will always get the
18838 * class 'x-form-trigger' and triggerClass will be <b>appended</b> if specified (defaults to 'x-form-arrow-trigger'
18839 * which displays a downward arrow icon).
18841 triggerClass : 'x-form-arrow-trigger',
18843 * @cfg {Boolean/String} shadow True or "sides" for the default effect, "frame" for 4-way shadow, and "drop" for bottom-right
18847 * @cfg {String} listAlign A valid anchor position value. See {@link Roo.Element#alignTo} for details on supported
18848 * anchor positions (defaults to 'tl-bl')
18850 listAlign: 'tl-bl?',
18852 * @cfg {Number} maxHeight The maximum height in pixels of the dropdown list before scrollbars are shown (defaults to 300)
18856 * @cfg {String} triggerAction The action to execute when the trigger field is activated. Use 'all' to run the
18857 * query specified by the allQuery config option (defaults to 'query')
18859 triggerAction: 'query',
18861 * @cfg {Number} minChars The minimum number of characters the user must type before autocomplete and typeahead activate
18862 * (defaults to 4, does not apply if editable = false)
18866 * @cfg {Boolean} typeAhead True to populate and autoselect the remainder of the text being typed after a configurable
18867 * delay (typeAheadDelay) if it matches a known value (defaults to false)
18871 * @cfg {Number} queryDelay The length of time in milliseconds to delay between the start of typing and sending the
18872 * query to filter the dropdown list (defaults to 500 if mode = 'remote' or 10 if mode = 'local')
18876 * @cfg {Number} pageSize If greater than 0, a paging toolbar is displayed in the footer of the dropdown list and the
18877 * filter queries will execute with page start and limit parameters. Only applies when mode = 'remote' (defaults to 0)
18881 * @cfg {Boolean} selectOnFocus True to select any existing text in the field immediately on focus. Only applies
18882 * when editable = true (defaults to false)
18884 selectOnFocus:false,
18886 * @cfg {String} queryParam Name of the query as it will be passed on the querystring (defaults to 'query')
18888 queryParam: 'query',
18890 * @cfg {String} loadingText The text to display in the dropdown list while data is loading. Only applies
18891 * when mode = 'remote' (defaults to 'Loading...')
18893 loadingText: 'Loading...',
18895 * @cfg {Boolean} resizable True to add a resize handle to the bottom of the dropdown list (defaults to false)
18899 * @cfg {Number} handleHeight The height in pixels of the dropdown list resize handle if resizable = true (defaults to 8)
18903 * @cfg {Boolean} editable False to prevent the user from typing text directly into the field, just like a
18904 * traditional select (defaults to true)
18908 * @cfg {String} allQuery The text query to send to the server to return all records for the list with no filtering (defaults to '')
18912 * @cfg {String} mode Set to 'local' if the ComboBox loads local data (defaults to 'remote' which loads from the server)
18916 * @cfg {Number} minListWidth The minimum width of the dropdown list in pixels (defaults to 70, will be ignored if
18917 * listWidth has a higher value)
18921 * @cfg {Boolean} forceSelection True to restrict the selected value to one of the values in the list, false to
18922 * allow the user to set arbitrary text into the field (defaults to false)
18924 forceSelection:false,
18926 * @cfg {Number} typeAheadDelay The length of time in milliseconds to wait until the typeahead text is displayed
18927 * if typeAhead = true (defaults to 250)
18929 typeAheadDelay : 250,
18931 * @cfg {String} valueNotFoundText When using a name/value combo, if the value passed to setValue is not found in
18932 * the store, valueNotFoundText will be displayed as the field text if defined (defaults to undefined)
18934 valueNotFoundText : undefined,
18936 * @cfg {Boolean} blockFocus Prevents all focus calls, so it can work with things like HTML edtor bar
18938 blockFocus : false,
18941 * @cfg {Boolean} disableClear Disable showing of clear button.
18943 disableClear : false,
18945 * @cfg {Boolean} alwaysQuery Disable caching of results, and always send query
18947 alwaysQuery : false,
18953 // element that contains real text value.. (when hidden is used..)
18956 onRender : function(ct, position)
18958 Roo.form.ComboBox.superclass.onRender.call(this, ct, position);
18960 if(this.hiddenName){
18961 this.hiddenField = this.el.insertSibling({tag:'input', type:'hidden', name: this.hiddenName, id: (this.hiddenId||this.hiddenName)},
18963 this.hiddenField.value =
18964 this.hiddenValue !== undefined ? this.hiddenValue :
18965 this.value !== undefined ? this.value : '';
18967 // prevent input submission
18968 this.el.dom.removeAttribute('name');
18974 this.el.dom.setAttribute('autocomplete', 'off');
18977 var cls = 'x-combo-list';
18979 this.list = new Roo.Layer({
18980 shadow: this.shadow, cls: [cls, this.listClass].join(' '), constrain:false
18983 var lw = this.listWidth || Math.max(this.wrap.getWidth(), this.minListWidth);
18984 this.list.setWidth(lw);
18985 this.list.swallowEvent('mousewheel');
18986 this.assetHeight = 0;
18989 this.header = this.list.createChild({cls:cls+'-hd', html: this.title});
18990 this.assetHeight += this.header.getHeight();
18993 this.innerList = this.list.createChild({cls:cls+'-inner'});
18994 this.innerList.on('mouseover', this.onViewOver, this);
18995 this.innerList.on('mousemove', this.onViewMove, this);
18996 this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
18998 if(this.allowBlank && !this.pageSize && !this.disableClear){
18999 this.footer = this.list.createChild({cls:cls+'-ft'});
19000 this.pageTb = new Roo.Toolbar(this.footer);
19004 this.footer = this.list.createChild({cls:cls+'-ft'});
19005 this.pageTb = new Roo.PagingToolbar(this.footer, this.store,
19006 {pageSize: this.pageSize});
19010 if (this.pageTb && this.allowBlank && !this.disableClear) {
19012 this.pageTb.add(new Roo.Toolbar.Fill(), {
19013 cls: 'x-btn-icon x-btn-clear',
19015 handler: function()
19018 _this.clearValue();
19019 _this.onSelect(false, -1);
19024 this.assetHeight += this.footer.getHeight();
19029 this.tpl = '<div class="'+cls+'-item">{' + this.displayField + '}</div>';
19032 this.view = new Roo.View(this.innerList, this.tpl, {
19035 selectedClass: this.selectedClass
19038 this.view.on('click', this.onViewClick, this);
19040 this.store.on('beforeload', this.onBeforeLoad, this);
19041 this.store.on('load', this.onLoad, this);
19042 this.store.on('loadexception', this.onLoadException, this);
19044 if(this.resizable){
19045 this.resizer = new Roo.Resizable(this.list, {
19046 pinned:true, handles:'se'
19048 this.resizer.on('resize', function(r, w, h){
19049 this.maxHeight = h-this.handleHeight-this.list.getFrameWidth('tb')-this.assetHeight;
19050 this.listWidth = w;
19051 this.innerList.setWidth(w - this.list.getFrameWidth('lr'));
19052 this.restrictHeight();
19054 this[this.pageSize?'footer':'innerList'].setStyle('margin-bottom', this.handleHeight+'px');
19056 if(!this.editable){
19057 this.editable = true;
19058 this.setEditable(false);
19062 if (typeof(this.events.add.listeners) != 'undefined') {
19064 this.addicon = this.wrap.createChild(
19065 {tag: 'img', src: Roo.BLANK_IMAGE_URL, cls: 'x-form-combo-add' });
19067 this.addicon.on('click', function(e) {
19068 this.fireEvent('add', this);
19071 if (typeof(this.events.edit.listeners) != 'undefined') {
19073 this.editicon = this.wrap.createChild(
19074 {tag: 'img', src: Roo.BLANK_IMAGE_URL, cls: 'x-form-combo-edit' });
19075 if (this.addicon) {
19076 this.editicon.setStyle('margin-left', '40px');
19078 this.editicon.on('click', function(e) {
19080 // we fire even if inothing is selected..
19081 this.fireEvent('edit', this, this.lastData );
19091 initEvents : function(){
19092 Roo.form.ComboBox.superclass.initEvents.call(this);
19094 this.keyNav = new Roo.KeyNav(this.el, {
19095 "up" : function(e){
19096 this.inKeyMode = true;
19100 "down" : function(e){
19101 if(!this.isExpanded()){
19102 this.onTriggerClick();
19104 this.inKeyMode = true;
19109 "enter" : function(e){
19110 this.onViewClick();
19114 "esc" : function(e){
19118 "tab" : function(e){
19119 this.onViewClick(false);
19120 this.fireEvent("specialkey", this, e);
19126 doRelay : function(foo, bar, hname){
19127 if(hname == 'down' || this.scope.isExpanded()){
19128 return Roo.KeyNav.prototype.doRelay.apply(this, arguments);
19135 this.queryDelay = Math.max(this.queryDelay || 10,
19136 this.mode == 'local' ? 10 : 250);
19137 this.dqTask = new Roo.util.DelayedTask(this.initQuery, this);
19138 if(this.typeAhead){
19139 this.taTask = new Roo.util.DelayedTask(this.onTypeAhead, this);
19141 if(this.editable !== false){
19142 this.el.on("keyup", this.onKeyUp, this);
19144 if(this.forceSelection){
19145 this.on('blur', this.doForce, this);
19149 onDestroy : function(){
19151 this.view.setStore(null);
19152 this.view.el.removeAllListeners();
19153 this.view.el.remove();
19154 this.view.purgeListeners();
19157 this.list.destroy();
19160 this.store.un('beforeload', this.onBeforeLoad, this);
19161 this.store.un('load', this.onLoad, this);
19162 this.store.un('loadexception', this.onLoadException, this);
19164 Roo.form.ComboBox.superclass.onDestroy.call(this);
19168 fireKey : function(e){
19169 if(e.isNavKeyPress() && !this.list.isVisible()){
19170 this.fireEvent("specialkey", this, e);
19175 onResize: function(w, h){
19176 Roo.form.ComboBox.superclass.onResize.apply(this, arguments);
19178 if(typeof w != 'number'){
19179 // we do not handle it!?!?
19182 var tw = this.trigger.getWidth();
19183 tw += this.addicon ? this.addicon.getWidth() : 0;
19184 tw += this.editicon ? this.editicon.getWidth() : 0;
19186 this.el.setWidth( this.adjustWidth('input', x));
19188 this.trigger.setStyle('left', x+'px');
19190 if(this.list && this.listWidth === undefined){
19191 var lw = Math.max(x + this.trigger.getWidth(), this.minListWidth);
19192 this.list.setWidth(lw);
19193 this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
19201 * Allow or prevent the user from directly editing the field text. If false is passed,
19202 * the user will only be able to select from the items defined in the dropdown list. This method
19203 * is the runtime equivalent of setting the 'editable' config option at config time.
19204 * @param {Boolean} value True to allow the user to directly edit the field text
19206 setEditable : function(value){
19207 if(value == this.editable){
19210 this.editable = value;
19212 this.el.dom.setAttribute('readOnly', true);
19213 this.el.on('mousedown', this.onTriggerClick, this);
19214 this.el.addClass('x-combo-noedit');
19216 this.el.dom.setAttribute('readOnly', false);
19217 this.el.un('mousedown', this.onTriggerClick, this);
19218 this.el.removeClass('x-combo-noedit');
19223 onBeforeLoad : function(){
19224 if(!this.hasFocus){
19227 this.innerList.update(this.loadingText ?
19228 '<div class="loading-indicator">'+this.loadingText+'</div>' : '');
19229 this.restrictHeight();
19230 this.selectedIndex = -1;
19234 onLoad : function(){
19235 if(!this.hasFocus){
19238 if(this.store.getCount() > 0){
19240 this.restrictHeight();
19241 if(this.lastQuery == this.allQuery){
19243 this.el.dom.select();
19245 if(!this.selectByValue(this.value, true)){
19246 this.select(0, true);
19250 if(this.typeAhead && this.lastKey != Roo.EventObject.BACKSPACE && this.lastKey != Roo.EventObject.DELETE){
19251 this.taTask.delay(this.typeAheadDelay);
19255 this.onEmptyResults();
19260 onLoadException : function()
19263 Roo.log(this.store.reader.jsonData);
19264 if (this.store && typeof(this.store.reader.jsonData.errorMsg) != 'undefined') {
19265 Roo.MessageBox.alert("Error loading",this.store.reader.jsonData.errorMsg);
19271 onTypeAhead : function(){
19272 if(this.store.getCount() > 0){
19273 var r = this.store.getAt(0);
19274 var newValue = r.data[this.displayField];
19275 var len = newValue.length;
19276 var selStart = this.getRawValue().length;
19277 if(selStart != len){
19278 this.setRawValue(newValue);
19279 this.selectText(selStart, newValue.length);
19285 onSelect : function(record, index){
19286 if(this.fireEvent('beforeselect', this, record, index) !== false){
19287 this.setFromData(index > -1 ? record.data : false);
19289 this.fireEvent('select', this, record, index);
19294 * Returns the currently selected field value or empty string if no value is set.
19295 * @return {String} value The selected value
19297 getValue : function(){
19298 if(this.valueField){
19299 return typeof this.value != 'undefined' ? this.value : '';
19301 return Roo.form.ComboBox.superclass.getValue.call(this);
19305 * Clears any text/value currently set in the field
19307 clearValue : function(){
19308 if(this.hiddenField){
19309 this.hiddenField.value = '';
19312 this.setRawValue('');
19313 this.lastSelectionText = '';
19318 * Sets the specified value into the field. If the value finds a match, the corresponding record text
19319 * will be displayed in the field. If the value does not match the data value of an existing item,
19320 * and the valueNotFoundText config option is defined, it will be displayed as the default field text.
19321 * Otherwise the field will be blank (although the value will still be set).
19322 * @param {String} value The value to match
19324 setValue : function(v){
19326 if(this.valueField){
19327 var r = this.findRecord(this.valueField, v);
19329 text = r.data[this.displayField];
19330 }else if(this.valueNotFoundText !== undefined){
19331 text = this.valueNotFoundText;
19334 this.lastSelectionText = text;
19335 if(this.hiddenField){
19336 this.hiddenField.value = v;
19338 Roo.form.ComboBox.superclass.setValue.call(this, text);
19342 * @property {Object} the last set data for the element
19347 * Sets the value of the field based on a object which is related to the record format for the store.
19348 * @param {Object} value the value to set as. or false on reset?
19350 setFromData : function(o){
19351 var dv = ''; // display value
19352 var vv = ''; // value value..
19354 if (this.displayField) {
19355 dv = !o || typeof(o[this.displayField]) == 'undefined' ? '' : o[this.displayField];
19357 // this is an error condition!!!
19358 Roo.log('no displayField value set for '+ (this.name ? this.name : this.id));
19361 if(this.valueField){
19362 vv = !o || typeof(o[this.valueField]) == 'undefined' ? dv : o[this.valueField];
19364 if(this.hiddenField){
19365 this.hiddenField.value = vv;
19367 this.lastSelectionText = dv;
19368 Roo.form.ComboBox.superclass.setValue.call(this, dv);
19372 // no hidden field.. - we store the value in 'value', but still display
19373 // display field!!!!
19374 this.lastSelectionText = dv;
19375 Roo.form.ComboBox.superclass.setValue.call(this, dv);
19381 reset : function(){
19382 // overridden so that last data is reset..
19383 this.setValue(this.resetValue);
19384 this.originalValue = this.getValue();
19385 this.clearInvalid();
19386 this.lastData = false;
19388 this.view.clearSelections();
19392 findRecord : function(prop, value){
19394 if(this.store.getCount() > 0){
19395 this.store.each(function(r){
19396 if(r.data[prop] == value){
19406 getName: function()
19408 // returns hidden if it's set..
19409 if (!this.rendered) {return ''};
19410 return !this.hiddenName && this.el.dom.name ? this.el.dom.name : (this.hiddenName || '');
19414 onViewMove : function(e, t){
19415 this.inKeyMode = false;
19419 onViewOver : function(e, t){
19420 if(this.inKeyMode){ // prevent key nav and mouse over conflicts
19423 var item = this.view.findItemFromChild(t);
19425 var index = this.view.indexOf(item);
19426 this.select(index, false);
19431 onViewClick : function(doFocus)
19433 var index = this.view.getSelectedIndexes()[0];
19434 var r = this.store.getAt(index);
19436 this.onSelect(r, index);
19438 if(doFocus !== false && !this.blockFocus){
19444 restrictHeight : function(){
19445 this.innerList.dom.style.height = '';
19446 var inner = this.innerList.dom;
19447 var h = Math.max(inner.clientHeight, inner.offsetHeight, inner.scrollHeight);
19448 this.innerList.setHeight(h < this.maxHeight ? 'auto' : this.maxHeight);
19449 this.list.beginUpdate();
19450 this.list.setHeight(this.innerList.getHeight()+this.list.getFrameWidth('tb')+(this.resizable?this.handleHeight:0)+this.assetHeight);
19451 this.list.alignTo(this.el, this.listAlign);
19452 this.list.endUpdate();
19456 onEmptyResults : function(){
19461 * Returns true if the dropdown list is expanded, else false.
19463 isExpanded : function(){
19464 return this.list.isVisible();
19468 * Select an item in the dropdown list by its data value. This function does NOT cause the select event to fire.
19469 * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
19470 * @param {String} value The data value of the item to select
19471 * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
19472 * selected item if it is not currently in view (defaults to true)
19473 * @return {Boolean} True if the value matched an item in the list, else false
19475 selectByValue : function(v, scrollIntoView){
19476 if(v !== undefined && v !== null){
19477 var r = this.findRecord(this.valueField || this.displayField, v);
19479 this.select(this.store.indexOf(r), scrollIntoView);
19487 * Select an item in the dropdown list by its numeric index in the list. This function does NOT cause the select event to fire.
19488 * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
19489 * @param {Number} index The zero-based index of the list item to select
19490 * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
19491 * selected item if it is not currently in view (defaults to true)
19493 select : function(index, scrollIntoView){
19494 this.selectedIndex = index;
19495 this.view.select(index);
19496 if(scrollIntoView !== false){
19497 var el = this.view.getNode(index);
19499 this.innerList.scrollChildIntoView(el, false);
19505 selectNext : function(){
19506 var ct = this.store.getCount();
19508 if(this.selectedIndex == -1){
19510 }else if(this.selectedIndex < ct-1){
19511 this.select(this.selectedIndex+1);
19517 selectPrev : function(){
19518 var ct = this.store.getCount();
19520 if(this.selectedIndex == -1){
19522 }else if(this.selectedIndex != 0){
19523 this.select(this.selectedIndex-1);
19529 onKeyUp : function(e){
19530 if(this.editable !== false && !e.isSpecialKey()){
19531 this.lastKey = e.getKey();
19532 this.dqTask.delay(this.queryDelay);
19537 validateBlur : function(){
19538 return !this.list || !this.list.isVisible();
19542 initQuery : function(){
19543 this.doQuery(this.getRawValue());
19547 doForce : function(){
19548 if(this.el.dom.value.length > 0){
19549 this.el.dom.value =
19550 this.lastSelectionText === undefined ? '' : this.lastSelectionText;
19556 * Execute a query to filter the dropdown list. Fires the beforequery event prior to performing the
19557 * query allowing the query action to be canceled if needed.
19558 * @param {String} query The SQL query to execute
19559 * @param {Boolean} forceAll True to force the query to execute even if there are currently fewer characters
19560 * in the field than the minimum specified by the minChars config option. It also clears any filter previously
19561 * saved in the current store (defaults to false)
19563 doQuery : function(q, forceAll){
19564 if(q === undefined || q === null){
19569 forceAll: forceAll,
19573 if(this.fireEvent('beforequery', qe)===false || qe.cancel){
19577 forceAll = qe.forceAll;
19578 if(forceAll === true || (q.length >= this.minChars)){
19579 if(this.lastQuery != q || this.alwaysQuery){
19580 this.lastQuery = q;
19581 if(this.mode == 'local'){
19582 this.selectedIndex = -1;
19584 this.store.clearFilter();
19586 this.store.filter(this.displayField, q);
19590 this.store.baseParams[this.queryParam] = q;
19592 params: this.getParams(q)
19597 this.selectedIndex = -1;
19604 getParams : function(q){
19606 //p[this.queryParam] = q;
19609 p.limit = this.pageSize;
19615 * Hides the dropdown list if it is currently expanded. Fires the 'collapse' event on completion.
19617 collapse : function(){
19618 if(!this.isExpanded()){
19622 Roo.get(document).un('mousedown', this.collapseIf, this);
19623 Roo.get(document).un('mousewheel', this.collapseIf, this);
19624 if (!this.editable) {
19625 Roo.get(document).un('keydown', this.listKeyPress, this);
19627 this.fireEvent('collapse', this);
19631 collapseIf : function(e){
19632 if(!e.within(this.wrap) && !e.within(this.list)){
19638 * Expands the dropdown list if it is currently hidden. Fires the 'expand' event on completion.
19640 expand : function(){
19641 if(this.isExpanded() || !this.hasFocus){
19644 this.list.alignTo(this.el, this.listAlign);
19646 Roo.get(document).on('mousedown', this.collapseIf, this);
19647 Roo.get(document).on('mousewheel', this.collapseIf, this);
19648 if (!this.editable) {
19649 Roo.get(document).on('keydown', this.listKeyPress, this);
19652 this.fireEvent('expand', this);
19656 // Implements the default empty TriggerField.onTriggerClick function
19657 onTriggerClick : function(){
19661 if(this.isExpanded()){
19663 if (!this.blockFocus) {
19668 this.hasFocus = true;
19669 if(this.triggerAction == 'all') {
19670 this.doQuery(this.allQuery, true);
19672 this.doQuery(this.getRawValue());
19674 if (!this.blockFocus) {
19679 listKeyPress : function(e)
19681 //Roo.log('listkeypress');
19682 // scroll to first matching element based on key pres..
19683 if (e.isSpecialKey()) {
19686 var k = String.fromCharCode(e.getKey()).toUpperCase();
19689 var csel = this.view.getSelectedNodes();
19690 var cselitem = false;
19692 var ix = this.view.indexOf(csel[0]);
19693 cselitem = this.store.getAt(ix);
19694 if (!cselitem.get(this.displayField) || cselitem.get(this.displayField).substring(0,1).toUpperCase() != k) {
19700 this.store.each(function(v) {
19702 // start at existing selection.
19703 if (cselitem.id == v.id) {
19709 if (v.get(this.displayField) && v.get(this.displayField).substring(0,1).toUpperCase() == k) {
19710 match = this.store.indexOf(v);
19715 if (match === false) {
19716 return true; // no more action?
19719 this.view.select(match);
19720 var sn = Roo.get(this.view.getSelectedNodes()[0]);
19721 sn.scrollIntoView(sn.dom.parentNode, false);
19725 * @cfg {Boolean} grow
19729 * @cfg {Number} growMin
19733 * @cfg {Number} growMax
19741 * Copyright(c) 2010-2012, Roo J Solutions Limited
19748 * @class Roo.form.ComboBoxArray
19749 * @extends Roo.form.TextField
19750 * A facebook style adder... for lists of email / people / countries etc...
19751 * pick multiple items from a combo box, and shows each one.
19753 * Fred [x] Brian [x] [Pick another |v]
19756 * For this to work: it needs various extra information
19757 * - normal combo problay has
19759 * + displayField, valueField
19761 * For our purpose...
19764 * If we change from 'extends' to wrapping...
19771 * Create a new ComboBoxArray.
19772 * @param {Object} config Configuration options
19776 Roo.form.ComboBoxArray = function(config)
19780 * @event beforeremove
19781 * Fires before remove the value from the list
19782 * @param {Roo.form.ComboBoxArray} _self This combo box array
19783 * @param {Roo.form.ComboBoxArray.Item} item removed item
19785 'beforeremove' : true,
19788 * Fires when remove the value from the list
19789 * @param {Roo.form.ComboBoxArray} _self This combo box array
19790 * @param {Roo.form.ComboBoxArray.Item} item removed item
19797 Roo.form.ComboBoxArray.superclass.constructor.call(this, config);
19799 this.items = new Roo.util.MixedCollection(false);
19801 // construct the child combo...
19811 Roo.extend(Roo.form.ComboBoxArray, Roo.form.TextField,
19814 * @cfg {Roo.form.Combo} combo The combo box that is wrapped
19819 // behavies liek a hiddne field
19820 inputType: 'hidden',
19822 * @cfg {Number} width The width of the box that displays the selected element
19829 * @cfg {String} name The name of the visable items on this form (eg. titles not ids)
19833 * @cfg {String} hiddenName The hidden name of the field, often contains an comma seperated list of names
19835 hiddenName : false,
19838 // private the array of items that are displayed..
19840 // private - the hidden field el.
19842 // private - the filed el..
19845 //validateValue : function() { return true; }, // all values are ok!
19846 //onAddClick: function() { },
19848 onRender : function(ct, position)
19851 // create the standard hidden element
19852 //Roo.form.ComboBoxArray.superclass.onRender.call(this, ct, position);
19855 // give fake names to child combo;
19856 this.combo.hiddenName = this.hiddenName ? (this.hiddenName+'-subcombo') : this.hiddenName;
19857 this.combo.name = this.name ? (this.name+'-subcombo') : this.name;
19859 this.combo = Roo.factory(this.combo, Roo.form);
19860 this.combo.onRender(ct, position);
19861 if (typeof(this.combo.width) != 'undefined') {
19862 this.combo.onResize(this.combo.width,0);
19865 this.combo.initEvents();
19867 // assigned so form know we need to do this..
19868 this.store = this.combo.store;
19869 this.valueField = this.combo.valueField;
19870 this.displayField = this.combo.displayField ;
19873 this.combo.wrap.addClass('x-cbarray-grp');
19875 var cbwrap = this.combo.wrap.createChild(
19876 {tag: 'div', cls: 'x-cbarray-cb'},
19881 this.hiddenEl = this.combo.wrap.createChild({
19882 tag: 'input', type:'hidden' , name: this.hiddenName, value : ''
19884 this.el = this.combo.wrap.createChild({
19885 tag: 'input', type:'hidden' , name: this.name, value : ''
19887 // this.el.dom.removeAttribute("name");
19890 this.outerWrap = this.combo.wrap;
19891 this.wrap = cbwrap;
19893 this.outerWrap.setWidth(this.width);
19894 this.outerWrap.dom.removeChild(this.el.dom);
19896 this.wrap.dom.appendChild(this.el.dom);
19897 this.outerWrap.dom.removeChild(this.combo.trigger.dom);
19898 this.combo.wrap.dom.appendChild(this.combo.trigger.dom);
19900 this.combo.trigger.setStyle('position','relative');
19901 this.combo.trigger.setStyle('left', '0px');
19902 this.combo.trigger.setStyle('top', '2px');
19904 this.combo.el.setStyle('vertical-align', 'text-bottom');
19906 //this.trigger.setStyle('vertical-align', 'top');
19908 // this should use the code from combo really... on('add' ....)
19912 this.adder = this.outerWrap.createChild(
19913 {tag: 'img', src: Roo.BLANK_IMAGE_URL, cls: 'x-form-adder', style: 'margin-left:2px'});
19915 this.adder.on('click', function(e) {
19916 _t.fireEvent('adderclick', this, e);
19920 //this.adder.on('click', this.onAddClick, _t);
19923 this.combo.on('select', function(cb, rec, ix) {
19924 this.addItem(rec.data);
19927 cb.el.dom.value = '';
19928 //cb.lastData = rec.data;
19937 getName: function()
19939 // returns hidden if it's set..
19940 if (!this.rendered) {return ''};
19941 return this.hiddenName ? this.hiddenName : this.name;
19946 onResize: function(w, h){
19949 // not sure if this is needed..
19950 //this.combo.onResize(w,h);
19952 if(typeof w != 'number'){
19953 // we do not handle it!?!?
19956 var tw = this.combo.trigger.getWidth();
19957 tw += this.addicon ? this.addicon.getWidth() : 0;
19958 tw += this.editicon ? this.editicon.getWidth() : 0;
19960 this.combo.el.setWidth( this.combo.adjustWidth('input', x));
19962 this.combo.trigger.setStyle('left', '0px');
19964 if(this.list && this.listWidth === undefined){
19965 var lw = Math.max(x + this.combo.trigger.getWidth(), this.combo.minListWidth);
19966 this.list.setWidth(lw);
19967 this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
19974 addItem: function(rec)
19976 var valueField = this.combo.valueField;
19977 var displayField = this.combo.displayField;
19979 if (this.items.indexOfKey(rec[valueField]) > -1) {
19980 //console.log("GOT " + rec.data.id);
19984 var x = new Roo.form.ComboBoxArray.Item({
19985 //id : rec[this.idField],
19987 displayField : displayField ,
19988 tipField : displayField ,
19992 this.items.add(rec[valueField],x);
19993 // add it before the element..
19994 this.updateHiddenEl();
19995 x.render(this.outerWrap, this.wrap.dom);
19996 // add the image handler..
19999 updateHiddenEl : function()
20002 if (!this.hiddenEl) {
20006 var idField = this.combo.valueField;
20008 this.items.each(function(f) {
20009 ar.push(f.data[idField]);
20011 this.hiddenEl.dom.value = ar.join(',');
20017 this.items.clear();
20019 Roo.each(this.outerWrap.select('.x-cbarray-item', true).elements, function(el){
20023 this.el.dom.value = '';
20024 if (this.hiddenEl) {
20025 this.hiddenEl.dom.value = '';
20029 getValue: function()
20031 return this.hiddenEl ? this.hiddenEl.dom.value : '';
20033 setValue: function(v) // not a valid action - must use addItems..
20038 if (this.store.isLocal && (typeof(v) == 'string')) {
20039 // then we can use the store to find the values..
20040 // comma seperated at present.. this needs to allow JSON based encoding..
20041 this.hiddenEl.value = v;
20043 Roo.each(v.split(','), function(k) {
20044 Roo.log("CHECK " + this.valueField + ',' + k);
20045 var li = this.store.query(this.valueField, k);
20050 add[this.valueField] = k;
20051 add[this.displayField] = li.item(0).data[this.displayField];
20057 if (typeof(v) == 'object' ) {
20058 // then let's assume it's an array of objects..
20059 Roo.each(v, function(l) {
20067 setFromData: function(v)
20069 // this recieves an object, if setValues is called.
20071 this.el.dom.value = v[this.displayField];
20072 this.hiddenEl.dom.value = v[this.valueField];
20073 if (typeof(v[this.valueField]) != 'string' || !v[this.valueField].length) {
20076 var kv = v[this.valueField];
20077 var dv = v[this.displayField];
20078 kv = typeof(kv) != 'string' ? '' : kv;
20079 dv = typeof(dv) != 'string' ? '' : dv;
20082 var keys = kv.split(',');
20083 var display = dv.split(',');
20084 for (var i = 0 ; i < keys.length; i++) {
20087 add[this.valueField] = keys[i];
20088 add[this.displayField] = display[i];
20096 * Validates the combox array value
20097 * @return {Boolean} True if the value is valid, else false
20099 validate : function(){
20100 if(this.disabled || this.validateValue(this.processValue(this.getValue()))){
20101 this.clearInvalid();
20107 validateValue : function(value){
20108 return Roo.form.ComboBoxArray.superclass.validateValue.call(this, this.getValue());
20116 isDirty : function() {
20117 if(this.disabled) {
20122 var d = Roo.decode(String(this.originalValue));
20124 return String(this.getValue()) !== String(this.originalValue);
20127 var originalValue = [];
20129 for (var i = 0; i < d.length; i++){
20130 originalValue.push(d[i][this.valueField]);
20133 return String(this.getValue()) !== String(originalValue.join(','));
20142 * @class Roo.form.ComboBoxArray.Item
20143 * @extends Roo.BoxComponent
20144 * A selected item in the list
20145 * Fred [x] Brian [x] [Pick another |v]
20148 * Create a new item.
20149 * @param {Object} config Configuration options
20152 Roo.form.ComboBoxArray.Item = function(config) {
20153 config.id = Roo.id();
20154 Roo.form.ComboBoxArray.Item.superclass.constructor.call(this, config);
20157 Roo.extend(Roo.form.ComboBoxArray.Item, Roo.BoxComponent, {
20160 displayField : false,
20164 defaultAutoCreate : {
20166 cls: 'x-cbarray-item',
20173 src : Roo.BLANK_IMAGE_URL ,
20181 onRender : function(ct, position)
20183 Roo.form.Field.superclass.onRender.call(this, ct, position);
20186 var cfg = this.getAutoCreate();
20187 this.el = ct.createChild(cfg, position);
20190 this.el.child('img').dom.setAttribute('src', Roo.BLANK_IMAGE_URL);
20192 this.el.child('div').dom.innerHTML = this.cb.renderer ?
20193 this.cb.renderer(this.data) :
20194 String.format('{0}',this.data[this.displayField]);
20197 this.el.child('div').dom.setAttribute('qtip',
20198 String.format('{0}',this.data[this.tipField])
20201 this.el.child('img').on('click', this.remove, this);
20205 remove : function()
20207 if(this.cb.disabled){
20211 if(false !== this.cb.fireEvent('beforeremove', this.cb, this)){
20212 this.cb.items.remove(this);
20213 this.el.child('img').un('click', this.remove, this);
20215 this.cb.updateHiddenEl();
20217 this.cb.fireEvent('remove', this.cb, this);
20222 * RooJS Library 1.1.1
20223 * Copyright(c) 2008-2011 Alan Knowles
20230 * @class Roo.form.ComboNested
20231 * @extends Roo.form.ComboBox
20232 * A combobox for that allows selection of nested items in a list,
20247 * Create a new ComboNested
20248 * @param {Object} config Configuration options
20250 Roo.form.ComboNested = function(config){
20251 Roo.form.ComboCheck.superclass.constructor.call(this, config);
20252 // should verify some data...
20254 // hiddenName = required..
20255 // displayField = required
20256 // valudField == required
20257 var req= [ 'hiddenName', 'displayField', 'valueField' ];
20259 Roo.each(req, function(e) {
20260 if ((typeof(_t[e]) == 'undefined' ) || !_t[e].length) {
20261 throw "Roo.form.ComboNested : missing value for: " + e;
20268 Roo.extend(Roo.form.ComboNested, Roo.form.ComboBox, {
20271 * @config {Number} max Number of columns to show
20276 list : null, // the outermost div..
20277 innerLists : null, // the
20281 onRender : function(ct, position)
20283 Roo.form.ComboBox.superclass.onRender.call(this, ct, position); // skip parent call - got to above..
20285 if(this.hiddenName){
20286 this.hiddenField = this.el.insertSibling({tag:'input', type:'hidden', name: this.hiddenName, id: (this.hiddenId||this.hiddenName)},
20288 this.hiddenField.value =
20289 this.hiddenValue !== undefined ? this.hiddenValue :
20290 this.value !== undefined ? this.value : '';
20292 // prevent input submission
20293 this.el.dom.removeAttribute('name');
20299 this.el.dom.setAttribute('autocomplete', 'off');
20302 var cls = 'x-combo-list';
20304 this.list = new Roo.Layer({
20305 shadow: this.shadow, cls: [cls, this.listClass].join(' '), constrain:false
20308 var lw = this.listWidth || Math.max(this.wrap.getWidth(), this.minListWidth);
20309 this.list.setWidth(lw);
20310 this.list.swallowEvent('mousewheel');
20311 this.assetHeight = 0;
20314 this.header = this.list.createChild({cls:cls+'-hd', html: this.title});
20315 this.assetHeight += this.header.getHeight();
20317 this.innerLists = [];
20320 for (var i =0 ; i < this.maxColumns; i++) {
20321 this.onRenderList( cls, i);
20324 // always needs footer, as we are going to have an 'OK' button.
20325 this.footer = this.list.createChild({cls:cls+'-ft'});
20326 this.pageTb = new Roo.Toolbar(this.footer);
20331 handler: function()
20337 if ( this.allowBlank && !this.disableClear) {
20339 this.pageTb.add(new Roo.Toolbar.Fill(), {
20340 cls: 'x-btn-icon x-btn-clear',
20342 handler: function()
20345 _this.clearValue();
20346 _this.onSelect(false, -1);
20351 this.assetHeight += this.footer.getHeight();
20355 onRenderList : function ( cls, i)
20358 var lw = Math.floor(
20359 ((this.listWidth * this.maxColumns || Math.max(this.wrap.getWidth(), this.minListWidth)) - this.list.getFrameWidth('lr')) / this.maxColumns
20362 this.list.setWidth(lw); // default to '1'
20364 var il = this.innerLists[i] = this.list.createChild({cls:cls+'-inner'});
20365 //il.on('mouseover', this.onViewOver, this, { list: i });
20366 //il.on('mousemove', this.onViewMove, this, { list: i });
20368 il.setStyle({ 'overflow-x' : 'hidden'});
20371 this.tpl = new Roo.Template({
20372 html : '<div class="'+cls+'-item '+cls+'-item-{cn:this.isEmpty}">{' + this.displayField + '}</div>',
20373 isEmpty: function (value, allValues) {
20375 var dl = typeof(value.data) != 'undefined' ? value.data.length : value.length; ///json is a nested response..
20376 return dl ? 'has-children' : 'no-children'
20381 var store = this.store;
20383 store = new Roo.data.SimpleStore({
20384 //fields : this.store.reader.meta.fields,
20385 reader : this.store.reader,
20389 this.stores[i] = store;
20391 var view = this.views[i] = new Roo.View(
20397 selectedClass: this.selectedClass
20400 view.getEl().setWidth(lw);
20401 view.getEl().setStyle({
20402 position: i < 1 ? 'relative' : 'absolute',
20404 left: (i * lw ) + 'px',
20405 display : i > 0 ? 'none' : 'block'
20407 view.on('selectionchange', this.onSelectChange, this, {list : i });
20408 view.on('dblclick', this.onDoubleClick, this, {list : i });
20409 //view.on('click', this.onViewClick, this, { list : i });
20411 store.on('beforeload', this.onBeforeLoad, this);
20412 store.on('load', this.onLoad, this, { list : i});
20413 store.on('loadexception', this.onLoadException, this);
20415 // hide the other vies..
20420 onResize : function() {},
20422 restrictHeight : function()
20425 Roo.each(this.innerLists, function(il,i) {
20426 var el = this.views[i].getEl();
20427 el.dom.style.height = '';
20428 var inner = el.dom;
20429 var h = Math.max(inner.clientHeight, inner.offsetHeight, inner.scrollHeight);
20430 // only adjust heights on other ones..
20433 el.setHeight(h < this.maxHeight ? 'auto' : this.maxHeight);
20434 il.setHeight(h < this.maxHeight ? 'auto' : this.maxHeight);
20435 mh = Math.max(el.getHeight(), mh);
20441 this.list.beginUpdate();
20442 this.list.setHeight(mh+this.list.getFrameWidth('tb')+this.assetHeight);
20443 this.list.alignTo(this.el, this.listAlign);
20444 this.list.endUpdate();
20449 // -- store handlers..
20451 onBeforeLoad : function()
20453 if(!this.hasFocus){
20456 this.innerLists[0].update(this.loadingText ?
20457 '<div class="loading-indicator">'+this.loadingText+'</div>' : '');
20458 this.restrictHeight();
20459 this.selectedIndex = -1;
20462 onLoad : function(a,b,c,d)
20465 if(!this.hasFocus){
20469 if(this.store.getCount() > 0) {
20471 this.restrictHeight();
20473 this.onEmptyResults();
20476 this.stores[1].loadData([]);
20477 this.stores[2].loadData([]);
20486 onLoadException : function()
20489 Roo.log(this.store.reader.jsonData);
20490 if (this.store && typeof(this.store.reader.jsonData.errorMsg) != 'undefined') {
20491 Roo.MessageBox.alert("Error loading",this.store.reader.jsonData.errorMsg);
20499 onSelectChange : function (view, sels, opts )
20501 var ix = view.getSelectedIndexes();
20503 if (opts.list > this.maxColumns - 2) {
20504 this.setFromData(ix.length ? view.store.getAt(ix[0]).data : {});
20509 this.setFromData({});
20510 var str = this.stores[opts.list+1];
20515 var rec = view.store.getAt(ix[0]);
20517 this.setFromData(rec.data);
20521 var lw = Math.floor(
20522 ((this.listWidth * this.maxColumns || Math.max(this.wrap.getWidth(), this.minListWidth)) - this.list.getFrameWidth('lr')) / this.maxColumns
20525 this.stores[opts.list+1].loadDataFromChildren( rec );
20526 var dl = this.stores[opts.list+1]. getTotalCount();
20527 this.views[opts.list+1].getEl().setHeight( this.innerLists[0].getHeight());
20528 this.views[opts.list+1].getEl().setStyle({ display : dl ? 'block' : 'none' });
20529 this.innerLists[opts.list+1].setHeight( this.innerLists[0].getHeight());
20530 this.list.setWidth(lw * (opts.list + (dl ? 2 : 1)));
20532 if (this.isLoading) {
20533 // this.selectActive(opts.list);
20537 onDoubleClick : function()
20539 this.collapse(); //??
20547 recordToStores : function(store, prop, value, stack)
20549 var cstore = new Roo.data.SimpleStore({
20550 //fields : this.store.reader.meta.fields, // we need array reader.. for
20551 reader : this.store.reader,
20555 var record = false;
20557 if(store.getCount() < 1){
20560 store.each(function(r){
20561 if(r.data[prop] == value){
20566 if (r.data.cn && r.data.cn.length) {
20567 cstore.loadDataFromChildren( r);
20568 var cret = _this.recordToStores(cstore, prop, value, stack);
20569 if (cret !== false) {
20578 if (record == false) {
20581 stack.unshift(srec);
20586 * find the stack of stores that match our value.
20591 selectActive : function ()
20593 // if store is not loaded, then we will need to wait for that to happen first.
20595 this.findRecordInStore(this.store, this.hiddenName, this.getValue(), stack);
20607 * Ext JS Library 1.1.1
20608 * Copyright(c) 2006-2007, Ext JS, LLC.
20610 * Originally Released Under LGPL - original licence link has changed is not relivant.
20613 * <script type="text/javascript">
20616 * @class Roo.form.Checkbox
20617 * @extends Roo.form.Field
20618 * Single checkbox field. Can be used as a direct replacement for traditional checkbox fields.
20620 * Creates a new Checkbox
20621 * @param {Object} config Configuration options
20623 Roo.form.Checkbox = function(config){
20624 Roo.form.Checkbox.superclass.constructor.call(this, config);
20628 * Fires when the checkbox is checked or unchecked.
20629 * @param {Roo.form.Checkbox} this This checkbox
20630 * @param {Boolean} checked The new checked value
20636 Roo.extend(Roo.form.Checkbox, Roo.form.Field, {
20638 * @cfg {String} focusClass The CSS class to use when the checkbox receives focus (defaults to undefined)
20640 focusClass : undefined,
20642 * @cfg {String} fieldClass The default CSS class for the checkbox (defaults to "x-form-field")
20644 fieldClass: "x-form-field",
20646 * @cfg {Boolean} checked True if the the checkbox should render already checked (defaults to false)
20650 * @cfg {String/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to
20651 * {tag: "input", type: "checkbox", autocomplete: "off"})
20653 defaultAutoCreate : { tag: "input", type: 'hidden', autocomplete: "off"},
20655 * @cfg {String} boxLabel The text that appears beside the checkbox
20659 * @cfg {String} inputValue The value that should go into the generated input element's value attribute
20663 * @cfg {String} valueOff The value that should go into the generated input element's value when unchecked.
20665 valueOff: '0', // value when not checked..
20667 actionMode : 'viewEl',
20670 itemCls : 'x-menu-check-item x-form-item',
20671 groupClass : 'x-menu-group-item',
20672 inputType : 'hidden',
20675 inSetChecked: false, // check that we are not calling self...
20677 inputElement: false, // real input element?
20678 basedOn: false, // ????
20680 isFormField: true, // not sure where this is needed!!!!
20682 onResize : function(){
20683 Roo.form.Checkbox.superclass.onResize.apply(this, arguments);
20684 if(!this.boxLabel){
20685 this.el.alignTo(this.wrap, 'c-c');
20689 initEvents : function(){
20690 Roo.form.Checkbox.superclass.initEvents.call(this);
20691 this.el.on("click", this.onClick, this);
20692 this.el.on("change", this.onClick, this);
20696 getResizeEl : function(){
20700 getPositionEl : function(){
20705 onRender : function(ct, position){
20706 Roo.form.Checkbox.superclass.onRender.call(this, ct, position);
20708 if(this.inputValue !== undefined){
20709 this.el.dom.value = this.inputValue;
20712 //this.wrap = this.el.wrap({cls: "x-form-check-wrap"});
20713 this.wrap = this.el.wrap({cls: 'x-menu-check-item '});
20714 var viewEl = this.wrap.createChild({
20715 tag: 'img', cls: 'x-menu-item-icon', style: 'margin: 0px;' ,src : Roo.BLANK_IMAGE_URL });
20716 this.viewEl = viewEl;
20717 this.wrap.on('click', this.onClick, this);
20719 this.el.on('DOMAttrModified', this.setFromHidden, this); //ff
20720 this.el.on('propertychange', this.setFromHidden, this); //ie
20725 this.wrap.createChild({tag: 'label', htmlFor: this.el.id, cls: 'x-form-cb-label', html: this.boxLabel});
20726 // viewEl.on('click', this.onClick, this);
20728 //if(this.checked){
20729 this.setChecked(this.checked);
20731 //this.checked = this.el.dom;
20737 initValue : Roo.emptyFn,
20740 * Returns the checked state of the checkbox.
20741 * @return {Boolean} True if checked, else false
20743 getValue : function(){
20745 return String(this.el.dom.value) == String(this.inputValue ) ? this.inputValue : this.valueOff;
20747 return this.valueOff;
20752 onClick : function(){
20753 if (this.disabled) {
20756 this.setChecked(!this.checked);
20758 //if(this.el.dom.checked != this.checked){
20759 // this.setValue(this.el.dom.checked);
20764 * Sets the checked state of the checkbox.
20765 * On is always based on a string comparison between inputValue and the param.
20766 * @param {Boolean/String} value - the value to set
20767 * @param {Boolean/String} suppressEvent - whether to suppress the checkchange event.
20769 setValue : function(v,suppressEvent){
20772 //this.checked = (v === true || v === 'true' || v == '1' || String(v).toLowerCase() == 'on');
20773 //if(this.el && this.el.dom){
20774 // this.el.dom.checked = this.checked;
20775 // this.el.dom.defaultChecked = this.checked;
20777 this.setChecked(String(v) === String(this.inputValue), suppressEvent);
20778 //this.fireEvent("check", this, this.checked);
20781 setChecked : function(state,suppressEvent)
20783 if (this.inSetChecked) {
20784 this.checked = state;
20790 this.wrap[state ? 'addClass' : 'removeClass']('x-menu-item-checked');
20792 this.checked = state;
20793 if(suppressEvent !== true){
20794 this.fireEvent('check', this, state);
20796 this.inSetChecked = true;
20797 this.el.dom.value = state ? this.inputValue : this.valueOff;
20798 this.inSetChecked = false;
20801 // handle setting of hidden value by some other method!!?!?
20802 setFromHidden: function()
20807 //console.log("SET FROM HIDDEN");
20808 //alert('setFrom hidden');
20809 this.setValue(this.el.dom.value);
20812 onDestroy : function()
20815 Roo.get(this.viewEl).remove();
20818 Roo.form.Checkbox.superclass.onDestroy.call(this);
20821 setBoxLabel : function(str)
20823 this.wrap.select('.x-form-cb-label', true).first().dom.innerHTML = str;
20828 * Ext JS Library 1.1.1
20829 * Copyright(c) 2006-2007, Ext JS, LLC.
20831 * Originally Released Under LGPL - original licence link has changed is not relivant.
20834 * <script type="text/javascript">
20838 * @class Roo.form.Radio
20839 * @extends Roo.form.Checkbox
20840 * Single radio field. Same as Checkbox, but provided as a convenience for automatically setting the input type.
20841 * Radio grouping is handled automatically by the browser if you give each radio in a group the same name.
20843 * Creates a new Radio
20844 * @param {Object} config Configuration options
20846 Roo.form.Radio = function(){
20847 Roo.form.Radio.superclass.constructor.apply(this, arguments);
20849 Roo.extend(Roo.form.Radio, Roo.form.Checkbox, {
20850 inputType: 'radio',
20853 * If this radio is part of a group, it will return the selected value
20856 getGroupValue : function(){
20857 return this.el.up('form').child('input[name='+this.el.dom.name+']:checked', true).value;
20861 onRender : function(ct, position){
20862 Roo.form.Checkbox.superclass.onRender.call(this, ct, position);
20864 if(this.inputValue !== undefined){
20865 this.el.dom.value = this.inputValue;
20868 this.wrap = this.el.wrap({cls: "x-form-check-wrap"});
20869 //this.wrap = this.el.wrap({cls: 'x-menu-check-item '});
20870 //var viewEl = this.wrap.createChild({
20871 // tag: 'img', cls: 'x-menu-item-icon', style: 'margin: 0px;' ,src : Roo.BLANK_IMAGE_URL });
20872 //this.viewEl = viewEl;
20873 //this.wrap.on('click', this.onClick, this);
20875 //this.el.on('DOMAttrModified', this.setFromHidden, this); //ff
20876 //this.el.on('propertychange', this.setFromHidden, this); //ie
20881 this.wrap.createChild({tag: 'label', htmlFor: this.el.id, cls: 'x-form-cb-label', html: this.boxLabel});
20882 // viewEl.on('click', this.onClick, this);
20885 this.el.dom.checked = 'checked' ;
20891 });//<script type="text/javascript">
20894 * Based Ext JS Library 1.1.1
20895 * Copyright(c) 2006-2007, Ext JS, LLC.
20901 * @class Roo.HtmlEditorCore
20902 * @extends Roo.Component
20903 * Provides a the editing component for the HTML editors in Roo. (bootstrap and Roo.form)
20905 * any element that has display set to 'none' can cause problems in Safari and Firefox.<br/><br/>
20908 Roo.HtmlEditorCore = function(config){
20911 Roo.HtmlEditorCore.superclass.constructor.call(this, config);
20916 * @event initialize
20917 * Fires when the editor is fully initialized (including the iframe)
20918 * @param {Roo.HtmlEditorCore} this
20923 * Fires when the editor is first receives the focus. Any insertion must wait
20924 * until after this event.
20925 * @param {Roo.HtmlEditorCore} this
20929 * @event beforesync
20930 * Fires before the textarea is updated with content from the editor iframe. Return false
20931 * to cancel the sync.
20932 * @param {Roo.HtmlEditorCore} this
20933 * @param {String} html
20937 * @event beforepush
20938 * Fires before the iframe editor is updated with content from the textarea. Return false
20939 * to cancel the push.
20940 * @param {Roo.HtmlEditorCore} this
20941 * @param {String} html
20946 * Fires when the textarea is updated with content from the editor iframe.
20947 * @param {Roo.HtmlEditorCore} this
20948 * @param {String} html
20953 * Fires when the iframe editor is updated with content from the textarea.
20954 * @param {Roo.HtmlEditorCore} this
20955 * @param {String} html
20960 * @event editorevent
20961 * Fires when on any editor (mouse up/down cursor movement etc.) - used for toolbar hooks.
20962 * @param {Roo.HtmlEditorCore} this
20968 // at this point this.owner is set, so we can start working out the whitelisted / blacklisted elements
20970 // defaults : white / black...
20971 this.applyBlacklists();
20978 Roo.extend(Roo.HtmlEditorCore, Roo.Component, {
20982 * @cfg {Roo.form.HtmlEditor|Roo.bootstrap.HtmlEditor} the owner field
20988 * @cfg {String} resizable 's' or 'se' or 'e' - wrapps the element in a
20993 * @cfg {Number} height (in pixels)
20997 * @cfg {Number} width (in pixels)
21002 * @cfg {Array} stylesheets url of stylesheets. set to [] to disable stylesheets.
21005 stylesheets: false,
21010 // private properties
21011 validationEvent : false,
21013 initialized : false,
21015 sourceEditMode : false,
21016 onFocus : Roo.emptyFn,
21018 hideMode:'offsets',
21022 // blacklist + whitelisted elements..
21029 * Protected method that will not generally be called directly. It
21030 * is called when the editor initializes the iframe with HTML contents. Override this method if you
21031 * want to change the initialization markup of the iframe (e.g. to add stylesheets).
21033 getDocMarkup : function(){
21037 // inherit styels from page...??
21038 if (this.stylesheets === false) {
21040 Roo.get(document.head).select('style').each(function(node) {
21041 st += node.dom.outerHTML || new XMLSerializer().serializeToString(node.dom);
21044 Roo.get(document.head).select('link').each(function(node) {
21045 st += node.dom.outerHTML || new XMLSerializer().serializeToString(node.dom);
21048 } else if (!this.stylesheets.length) {
21050 st = '<style type="text/css">' +
21051 'body{border:0;margin:0;padding:3px;height:98%;cursor:text;}' +
21054 st = '<style type="text/css">' +
21059 st += '<style type="text/css">' +
21060 'IMG { cursor: pointer } ' +
21063 var cls = 'roo-htmleditor-body';
21065 if(this.bodyCls.length){
21066 cls += ' ' + this.bodyCls;
21069 return '<html><head>' + st +
21070 //<style type="text/css">' +
21071 //'body{border:0;margin:0;padding:3px;height:98%;cursor:text;}' +
21073 ' </head><body class="' + cls + '"></body></html>';
21077 onRender : function(ct, position)
21080 //Roo.HtmlEditorCore.superclass.onRender.call(this, ct, position);
21081 this.el = this.owner.inputEl ? this.owner.inputEl() : this.owner.el;
21084 this.el.dom.style.border = '0 none';
21085 this.el.dom.setAttribute('tabIndex', -1);
21086 this.el.addClass('x-hidden hide');
21090 if(Roo.isIE){ // fix IE 1px bogus margin
21091 this.el.applyStyles('margin-top:-1px;margin-bottom:-1px;')
21095 this.frameId = Roo.id();
21099 var iframe = this.owner.wrap.createChild({
21101 cls: 'form-control', // bootstrap..
21103 name: this.frameId,
21104 frameBorder : 'no',
21105 'src' : Roo.SSL_SECURE_URL ? Roo.SSL_SECURE_URL : "javascript:false"
21110 this.iframe = iframe.dom;
21112 this.assignDocWin();
21114 this.doc.designMode = 'on';
21117 this.doc.write(this.getDocMarkup());
21121 var task = { // must defer to wait for browser to be ready
21123 //console.log("run task?" + this.doc.readyState);
21124 this.assignDocWin();
21125 if(this.doc.body || this.doc.readyState == 'complete'){
21127 this.doc.designMode="on";
21131 Roo.TaskMgr.stop(task);
21132 this.initEditor.defer(10, this);
21139 Roo.TaskMgr.start(task);
21144 onResize : function(w, h)
21146 Roo.log('resize: ' +w + ',' + h );
21147 //Roo.HtmlEditorCore.superclass.onResize.apply(this, arguments);
21151 if(typeof w == 'number'){
21153 this.iframe.style.width = w + 'px';
21155 if(typeof h == 'number'){
21157 this.iframe.style.height = h + 'px';
21159 (this.doc.body || this.doc.documentElement).style.height = (h - (this.iframePad*2)) + 'px';
21166 * Toggles the editor between standard and source edit mode.
21167 * @param {Boolean} sourceEdit (optional) True for source edit, false for standard
21169 toggleSourceEdit : function(sourceEditMode){
21171 this.sourceEditMode = sourceEditMode === true;
21173 if(this.sourceEditMode){
21175 Roo.get(this.iframe).addClass(['x-hidden','hide']); //FIXME - what's the BS styles for these
21178 Roo.get(this.iframe).removeClass(['x-hidden','hide']);
21179 //this.iframe.className = '';
21182 //this.setSize(this.owner.wrap.getSize());
21183 //this.fireEvent('editmodechange', this, this.sourceEditMode);
21190 * Protected method that will not generally be called directly. If you need/want
21191 * custom HTML cleanup, this is the method you should override.
21192 * @param {String} html The HTML to be cleaned
21193 * return {String} The cleaned HTML
21195 cleanHtml : function(html){
21196 html = String(html);
21197 if(html.length > 5){
21198 if(Roo.isSafari){ // strip safari nonsense
21199 html = html.replace(/\sclass="(?:Apple-style-span|khtml-block-placeholder)"/gi, '');
21202 if(html == ' '){
21209 * HTML Editor -> Textarea
21210 * Protected method that will not generally be called directly. Syncs the contents
21211 * of the editor iframe with the textarea.
21213 syncValue : function(){
21214 if(this.initialized){
21215 var bd = (this.doc.body || this.doc.documentElement);
21216 //this.cleanUpPaste(); -- this is done else where and causes havoc..
21217 var html = bd.innerHTML;
21219 var bs = bd.getAttribute('style'); // Safari puts text-align styles on the body element!
21220 var m = bs ? bs.match(/text-align:(.*?);/i) : false;
21222 html = '<div style="'+m[0]+'">' + html + '</div>';
21225 html = this.cleanHtml(html);
21226 // fix up the special chars.. normaly like back quotes in word...
21227 // however we do not want to do this with chinese..
21228 html = html.replace(/[\uD800-\uDBFF][\uDC00-\uDFFF]|[\u0080-\uFFFF]/g, function(match) {
21230 var cc = match.charCodeAt();
21232 // Get the character value, handling surrogate pairs
21233 if (match.length == 2) {
21234 // It's a surrogate pair, calculate the Unicode code point
21235 var high = match.charCodeAt(0) - 0xD800;
21236 var low = match.charCodeAt(1) - 0xDC00;
21237 cc = (high * 0x400) + low + 0x10000;
21239 (cc >= 0x4E00 && cc < 0xA000 ) ||
21240 (cc >= 0x3400 && cc < 0x4E00 ) ||
21241 (cc >= 0xf900 && cc < 0xfb00 )
21246 // No, use a numeric entity. Here we brazenly (and possibly mistakenly)
21247 return "&#" + cc + ";";
21254 if(this.owner.fireEvent('beforesync', this, html) !== false){
21255 this.el.dom.value = html;
21256 this.owner.fireEvent('sync', this, html);
21262 * Protected method that will not generally be called directly. Pushes the value of the textarea
21263 * into the iframe editor.
21265 pushValue : function(){
21266 if(this.initialized){
21267 var v = this.el.dom.value.trim();
21269 // if(v.length < 1){
21273 if(this.owner.fireEvent('beforepush', this, v) !== false){
21274 var d = (this.doc.body || this.doc.documentElement);
21276 this.cleanUpPaste();
21277 this.el.dom.value = d.innerHTML;
21278 this.owner.fireEvent('push', this, v);
21284 deferFocus : function(){
21285 this.focus.defer(10, this);
21289 focus : function(){
21290 if(this.win && !this.sourceEditMode){
21297 assignDocWin: function()
21299 var iframe = this.iframe;
21302 this.doc = iframe.contentWindow.document;
21303 this.win = iframe.contentWindow;
21305 // if (!Roo.get(this.frameId)) {
21308 // this.doc = (iframe.contentDocument || Roo.get(this.frameId).dom.document);
21309 // this.win = Roo.get(this.frameId).dom.contentWindow;
21311 if (!Roo.get(this.frameId) && !iframe.contentDocument) {
21315 this.doc = (iframe.contentDocument || Roo.get(this.frameId).dom.document);
21316 this.win = (iframe.contentWindow || Roo.get(this.frameId).dom.contentWindow);
21321 initEditor : function(){
21322 //console.log("INIT EDITOR");
21323 this.assignDocWin();
21327 this.doc.designMode="on";
21329 this.doc.write(this.getDocMarkup());
21332 var dbody = (this.doc.body || this.doc.documentElement);
21333 //var ss = this.el.getStyles('font-size', 'font-family', 'background-image', 'background-repeat');
21334 // this copies styles from the containing element into thsi one..
21335 // not sure why we need all of this..
21336 //var ss = this.el.getStyles('font-size', 'background-image', 'background-repeat');
21338 //var ss = this.el.getStyles( 'background-image', 'background-repeat');
21339 //ss['background-attachment'] = 'fixed'; // w3c
21340 dbody.bgProperties = 'fixed'; // ie
21341 //Roo.DomHelper.applyStyles(dbody, ss);
21342 Roo.EventManager.on(this.doc, {
21343 //'mousedown': this.onEditorEvent,
21344 'mouseup': this.onEditorEvent,
21345 'dblclick': this.onEditorEvent,
21346 'click': this.onEditorEvent,
21347 'keyup': this.onEditorEvent,
21352 Roo.EventManager.on(this.doc, 'keypress', this.mozKeyPress, this);
21354 if(Roo.isIE || Roo.isSafari || Roo.isOpera){
21355 Roo.EventManager.on(this.doc, 'keydown', this.fixKeys, this);
21357 this.initialized = true;
21359 this.owner.fireEvent('initialize', this);
21364 onDestroy : function(){
21370 //for (var i =0; i < this.toolbars.length;i++) {
21371 // // fixme - ask toolbars for heights?
21372 // this.toolbars[i].onDestroy();
21375 //this.wrap.dom.innerHTML = '';
21376 //this.wrap.remove();
21381 onFirstFocus : function(){
21383 this.assignDocWin();
21386 this.activated = true;
21389 if(Roo.isGecko){ // prevent silly gecko errors
21391 var s = this.win.getSelection();
21392 if(!s.focusNode || s.focusNode.nodeType != 3){
21393 var r = s.getRangeAt(0);
21394 r.selectNodeContents((this.doc.body || this.doc.documentElement));
21399 this.execCmd('useCSS', true);
21400 this.execCmd('styleWithCSS', false);
21403 this.owner.fireEvent('activate', this);
21407 adjustFont: function(btn){
21408 var adjust = btn.cmd == 'increasefontsize' ? 1 : -1;
21409 //if(Roo.isSafari){ // safari
21412 var v = parseInt(this.doc.queryCommandValue('FontSize')|| 3, 10);
21413 if(Roo.isSafari){ // safari
21414 var sm = { 10 : 1, 13: 2, 16:3, 18:4, 24: 5, 32:6, 48: 7 };
21415 v = (v < 10) ? 10 : v;
21416 v = (v > 48) ? 48 : v;
21417 v = typeof(sm[v]) == 'undefined' ? 1 : sm[v];
21422 v = Math.max(1, v+adjust);
21424 this.execCmd('FontSize', v );
21427 onEditorEvent : function(e)
21429 this.owner.fireEvent('editorevent', this, e);
21430 // this.updateToolbar();
21431 this.syncValue(); //we can not sync so often.. sync cleans, so this breaks stuff
21434 insertTag : function(tg)
21436 // could be a bit smarter... -> wrap the current selected tRoo..
21437 if (tg.toLowerCase() == 'span' ||
21438 tg.toLowerCase() == 'code' ||
21439 tg.toLowerCase() == 'sup' ||
21440 tg.toLowerCase() == 'sub'
21443 range = this.createRange(this.getSelection());
21444 var wrappingNode = this.doc.createElement(tg.toLowerCase());
21445 wrappingNode.appendChild(range.extractContents());
21446 range.insertNode(wrappingNode);
21453 this.execCmd("formatblock", tg);
21457 insertText : function(txt)
21461 var range = this.createRange();
21462 range.deleteContents();
21463 //alert(Sender.getAttribute('label'));
21465 range.insertNode(this.doc.createTextNode(txt));
21471 * Executes a Midas editor command on the editor document and performs necessary focus and
21472 * toolbar updates. <b>This should only be called after the editor is initialized.</b>
21473 * @param {String} cmd The Midas command
21474 * @param {String/Boolean} value (optional) The value to pass to the command (defaults to null)
21476 relayCmd : function(cmd, value){
21478 this.execCmd(cmd, value);
21479 this.owner.fireEvent('editorevent', this);
21480 //this.updateToolbar();
21481 this.owner.deferFocus();
21485 * Executes a Midas editor command directly on the editor document.
21486 * For visual commands, you should use {@link #relayCmd} instead.
21487 * <b>This should only be called after the editor is initialized.</b>
21488 * @param {String} cmd The Midas command
21489 * @param {String/Boolean} value (optional) The value to pass to the command (defaults to null)
21491 execCmd : function(cmd, value){
21492 this.doc.execCommand(cmd, false, value === undefined ? null : value);
21499 * Inserts the passed text at the current cursor position. Note: the editor must be initialized and activated
21501 * @param {String} text | dom node..
21503 insertAtCursor : function(text)
21506 if(!this.activated){
21512 var r = this.doc.selection.createRange();
21523 if(Roo.isGecko || Roo.isOpera || Roo.isSafari){
21527 // from jquery ui (MIT licenced)
21529 var win = this.win;
21531 if (win.getSelection && win.getSelection().getRangeAt) {
21532 range = win.getSelection().getRangeAt(0);
21533 node = typeof(text) == 'string' ? range.createContextualFragment(text) : text;
21534 range.insertNode(node);
21535 } else if (win.document.selection && win.document.selection.createRange) {
21536 // no firefox support
21537 var txt = typeof(text) == 'string' ? text : text.outerHTML;
21538 win.document.selection.createRange().pasteHTML(txt);
21540 // no firefox support
21541 var txt = typeof(text) == 'string' ? text : text.outerHTML;
21542 this.execCmd('InsertHTML', txt);
21551 mozKeyPress : function(e){
21553 var c = e.getCharCode(), cmd;
21556 c = String.fromCharCode(c).toLowerCase();
21570 this.cleanUpPaste.defer(100, this);
21578 e.preventDefault();
21586 fixKeys : function(){ // load time branching for fastest keydown performance
21588 return function(e){
21589 var k = e.getKey(), r;
21592 r = this.doc.selection.createRange();
21595 r.pasteHTML('    ');
21602 r = this.doc.selection.createRange();
21604 var target = r.parentElement();
21605 if(!target || target.tagName.toLowerCase() != 'li'){
21607 r.pasteHTML('<br />');
21613 if (String.fromCharCode(k).toLowerCase() == 'v') { // paste
21614 this.cleanUpPaste.defer(100, this);
21620 }else if(Roo.isOpera){
21621 return function(e){
21622 var k = e.getKey();
21626 this.execCmd('InsertHTML','    ');
21629 if (String.fromCharCode(k).toLowerCase() == 'v') { // paste
21630 this.cleanUpPaste.defer(100, this);
21635 }else if(Roo.isSafari){
21636 return function(e){
21637 var k = e.getKey();
21641 this.execCmd('InsertText','\t');
21645 if (String.fromCharCode(k).toLowerCase() == 'v') { // paste
21646 this.cleanUpPaste.defer(100, this);
21654 getAllAncestors: function()
21656 var p = this.getSelectedNode();
21659 a.push(p); // push blank onto stack..
21660 p = this.getParentElement();
21664 while (p && (p.nodeType == 1) && (p.tagName.toLowerCase() != 'body')) {
21668 a.push(this.doc.body);
21672 lastSelNode : false,
21675 getSelection : function()
21677 this.assignDocWin();
21678 return Roo.isIE ? this.doc.selection : this.win.getSelection();
21681 getSelectedNode: function()
21683 // this may only work on Gecko!!!
21685 // should we cache this!!!!
21690 var range = this.createRange(this.getSelection()).cloneRange();
21693 var parent = range.parentElement();
21695 var testRange = range.duplicate();
21696 testRange.moveToElementText(parent);
21697 if (testRange.inRange(range)) {
21700 if ((parent.nodeType != 1) || (parent.tagName.toLowerCase() == 'body')) {
21703 parent = parent.parentElement;
21708 // is ancestor a text element.
21709 var ac = range.commonAncestorContainer;
21710 if (ac.nodeType == 3) {
21711 ac = ac.parentNode;
21714 var ar = ac.childNodes;
21717 var other_nodes = [];
21718 var has_other_nodes = false;
21719 for (var i=0;i<ar.length;i++) {
21720 if ((ar[i].nodeType == 3) && (!ar[i].data.length)) { // empty text ?
21723 // fullly contained node.
21725 if (this.rangeIntersectsNode(range,ar[i]) && this.rangeCompareNode(range,ar[i]) == 3) {
21730 // probably selected..
21731 if ((ar[i].nodeType == 1) && this.rangeIntersectsNode(range,ar[i]) && (this.rangeCompareNode(range,ar[i]) > 0)) {
21732 other_nodes.push(ar[i]);
21736 if (!this.rangeIntersectsNode(range,ar[i])|| (this.rangeCompareNode(range,ar[i]) == 0)) {
21741 has_other_nodes = true;
21743 if (!nodes.length && other_nodes.length) {
21744 nodes= other_nodes;
21746 if (has_other_nodes || !nodes.length || (nodes.length > 1)) {
21752 createRange: function(sel)
21754 // this has strange effects when using with
21755 // top toolbar - not sure if it's a great idea.
21756 //this.editor.contentWindow.focus();
21757 if (typeof sel != "undefined") {
21759 return sel.getRangeAt ? sel.getRangeAt(0) : sel.createRange();
21761 return this.doc.createRange();
21764 return this.doc.createRange();
21767 getParentElement: function()
21770 this.assignDocWin();
21771 var sel = Roo.isIE ? this.doc.selection : this.win.getSelection();
21773 var range = this.createRange(sel);
21776 var p = range.commonAncestorContainer;
21777 while (p.nodeType == 3) { // text node
21788 * Range intersection.. the hard stuff...
21792 * [ -- selected range --- ]
21796 * if end is before start or hits it. fail.
21797 * if start is after end or hits it fail.
21799 * if either hits (but other is outside. - then it's not
21805 // @see http://www.thismuchiknow.co.uk/?p=64.
21806 rangeIntersectsNode : function(range, node)
21808 var nodeRange = node.ownerDocument.createRange();
21810 nodeRange.selectNode(node);
21812 nodeRange.selectNodeContents(node);
21815 var rangeStartRange = range.cloneRange();
21816 rangeStartRange.collapse(true);
21818 var rangeEndRange = range.cloneRange();
21819 rangeEndRange.collapse(false);
21821 var nodeStartRange = nodeRange.cloneRange();
21822 nodeStartRange.collapse(true);
21824 var nodeEndRange = nodeRange.cloneRange();
21825 nodeEndRange.collapse(false);
21827 return rangeStartRange.compareBoundaryPoints(
21828 Range.START_TO_START, nodeEndRange) == -1 &&
21829 rangeEndRange.compareBoundaryPoints(
21830 Range.START_TO_START, nodeStartRange) == 1;
21834 rangeCompareNode : function(range, node)
21836 var nodeRange = node.ownerDocument.createRange();
21838 nodeRange.selectNode(node);
21840 nodeRange.selectNodeContents(node);
21844 range.collapse(true);
21846 nodeRange.collapse(true);
21848 var ss = range.compareBoundaryPoints( Range.START_TO_START, nodeRange);
21849 var ee = range.compareBoundaryPoints( Range.END_TO_END, nodeRange);
21851 //Roo.log(node.tagName + ': ss='+ss +', ee='+ee)
21853 var nodeIsBefore = ss == 1;
21854 var nodeIsAfter = ee == -1;
21856 if (nodeIsBefore && nodeIsAfter) {
21859 if (!nodeIsBefore && nodeIsAfter) {
21860 return 1; //right trailed.
21863 if (nodeIsBefore && !nodeIsAfter) {
21864 return 2; // left trailed.
21870 // private? - in a new class?
21871 cleanUpPaste : function()
21873 // cleans up the whole document..
21874 Roo.log('cleanuppaste');
21876 this.cleanUpChildren(this.doc.body);
21877 var clean = this.cleanWordChars(this.doc.body.innerHTML);
21878 if (clean != this.doc.body.innerHTML) {
21879 this.doc.body.innerHTML = clean;
21884 cleanWordChars : function(input) {// change the chars to hex code
21885 var he = Roo.HtmlEditorCore;
21887 var output = input;
21888 Roo.each(he.swapCodes, function(sw) {
21889 var swapper = new RegExp("\\u" + sw[0].toString(16), "g"); // hex codes
21891 output = output.replace(swapper, sw[1]);
21898 cleanUpChildren : function (n)
21900 if (!n.childNodes.length) {
21903 for (var i = n.childNodes.length-1; i > -1 ; i--) {
21904 this.cleanUpChild(n.childNodes[i]);
21911 cleanUpChild : function (node)
21914 //console.log(node);
21915 if (node.nodeName == "#text") {
21916 // clean up silly Windows -- stuff?
21919 if (node.nodeName == "#comment") {
21920 node.parentNode.removeChild(node);
21921 // clean up silly Windows -- stuff?
21924 var lcname = node.tagName.toLowerCase();
21925 // we ignore whitelists... ?? = not really the way to go, but we probably have not got a full
21926 // whitelist of tags..
21928 if (this.black.indexOf(lcname) > -1 && this.clearUp ) {
21930 node.parentNode.removeChild(node);
21935 var remove_keep_children= Roo.HtmlEditorCore.remove.indexOf(node.tagName.toLowerCase()) > -1;
21937 // spans with no attributes - just remove them..
21938 if ((!node.attributes || !node.attributes.length) && lcname == 'span') {
21939 remove_keep_children = true;
21942 // remove <a name=....> as rendering on yahoo mailer is borked with this.
21943 // this will have to be flaged elsewhere - perhaps ablack=name... on the mailer..
21945 //if (node.tagName.toLowerCase() == 'a' && !node.hasAttribute('href')) {
21946 // remove_keep_children = true;
21949 if (remove_keep_children) {
21950 this.cleanUpChildren(node);
21951 // inserts everything just before this node...
21952 while (node.childNodes.length) {
21953 var cn = node.childNodes[0];
21954 node.removeChild(cn);
21955 node.parentNode.insertBefore(cn, node);
21957 node.parentNode.removeChild(node);
21961 if (!node.attributes || !node.attributes.length) {
21966 this.cleanUpChildren(node);
21970 function cleanAttr(n,v)
21973 if (v.match(/^\./) || v.match(/^\//)) {
21976 if (v.match(/^(http|https):\/\//) || v.match(/^mailto:/) || v.match(/^ftp:/)) {
21979 if (v.match(/^#/)) {
21982 // Roo.log("(REMOVE TAG)"+ node.tagName +'.' + n + '=' + v);
21983 node.removeAttribute(n);
21987 var cwhite = this.cwhite;
21988 var cblack = this.cblack;
21990 function cleanStyle(n,v)
21992 if (v.match(/expression/)) { //XSS?? should we even bother..
21993 node.removeAttribute(n);
21997 var parts = v.split(/;/);
22000 Roo.each(parts, function(p) {
22001 p = p.replace(/^\s+/g,'').replace(/\s+$/g,'');
22005 var l = p.split(':').shift().replace(/\s+/g,'');
22006 l = l.replace(/^\s+/g,'').replace(/\s+$/g,'');
22008 if ( cwhite.length && cblack.indexOf(l) > -1) {
22009 // Roo.log('(REMOVE CSS)' + node.tagName +'.' + n + ':'+l + '=' + v);
22010 //node.removeAttribute(n);
22014 // only allow 'c whitelisted system attributes'
22015 if ( cwhite.length && cwhite.indexOf(l) < 0) {
22016 // Roo.log('(REMOVE CSS)' + node.tagName +'.' + n + ':'+l + '=' + v);
22017 //node.removeAttribute(n);
22027 if (clean.length) {
22028 node.setAttribute(n, clean.join(';'));
22030 node.removeAttribute(n);
22036 for (var i = node.attributes.length-1; i > -1 ; i--) {
22037 var a = node.attributes[i];
22040 if (a.name.toLowerCase().substr(0,2)=='on') {
22041 node.removeAttribute(a.name);
22044 if (Roo.HtmlEditorCore.ablack.indexOf(a.name.toLowerCase()) > -1) {
22045 node.removeAttribute(a.name);
22048 if (Roo.HtmlEditorCore.aclean.indexOf(a.name.toLowerCase()) > -1) {
22049 cleanAttr(a.name,a.value); // fixme..
22052 if (a.name == 'style') {
22053 cleanStyle(a.name,a.value);
22056 /// clean up MS crap..
22057 // tecnically this should be a list of valid class'es..
22060 if (a.name == 'class') {
22061 if (a.value.match(/^Mso/)) {
22062 node.removeAttribute('class');
22065 if (a.value.match(/^body$/)) {
22066 node.removeAttribute('class');
22077 this.cleanUpChildren(node);
22083 * Clean up MS wordisms...
22085 cleanWord : function(node)
22088 this.cleanWord(this.doc.body);
22093 node.nodeName == 'SPAN' &&
22094 !node.hasAttributes() &&
22095 node.childNodes.length == 1 &&
22096 node.firstChild.nodeName == "#text"
22098 var textNode = node.firstChild;
22099 node.removeChild(textNode);
22100 if (node.getAttribute('lang') != 'zh-CN') { // do not space pad on chinese characters..
22101 node.parentNode.insertBefore(node.ownerDocument.createTextNode(" "), node);
22103 node.parentNode.insertBefore(textNode, node);
22104 if (node.getAttribute('lang') != 'zh-CN') { // do not space pad on chinese characters..
22105 node.parentNode.insertBefore(node.ownerDocument.createTextNode(" ") , node);
22107 node.parentNode.removeChild(node);
22110 if (node.nodeName == "#text") {
22111 // clean up silly Windows -- stuff?
22114 if (node.nodeName == "#comment") {
22115 node.parentNode.removeChild(node);
22116 // clean up silly Windows -- stuff?
22120 if (node.tagName.toLowerCase().match(/^(style|script|applet|embed|noframes|noscript)$/)) {
22121 node.parentNode.removeChild(node);
22124 //Roo.log(node.tagName);
22125 // remove - but keep children..
22126 if (node.tagName.toLowerCase().match(/^(meta|link|\\?xml:|st1:|o:|v:|font)/)) {
22127 //Roo.log('-- removed');
22128 while (node.childNodes.length) {
22129 var cn = node.childNodes[0];
22130 node.removeChild(cn);
22131 node.parentNode.insertBefore(cn, node);
22132 // move node to parent - and clean it..
22133 this.cleanWord(cn);
22135 node.parentNode.removeChild(node);
22136 /// no need to iterate chidlren = it's got none..
22137 //this.iterateChildren(node, this.cleanWord);
22141 if (node.className.length) {
22143 var cn = node.className.split(/\W+/);
22145 Roo.each(cn, function(cls) {
22146 if (cls.match(/Mso[a-zA-Z]+/)) {
22151 node.className = cna.length ? cna.join(' ') : '';
22153 node.removeAttribute("class");
22157 if (node.hasAttribute("lang")) {
22158 node.removeAttribute("lang");
22161 if (node.hasAttribute("style")) {
22163 var styles = node.getAttribute("style").split(";");
22165 Roo.each(styles, function(s) {
22166 if (!s.match(/:/)) {
22169 var kv = s.split(":");
22170 if (kv[0].match(/^(mso-|line|font|background|margin|padding|color)/)) {
22173 // what ever is left... we allow.
22176 node.setAttribute("style", nstyle.length ? nstyle.join(';') : '');
22177 if (!nstyle.length) {
22178 node.removeAttribute('style');
22181 this.iterateChildren(node, this.cleanWord);
22187 * iterateChildren of a Node, calling fn each time, using this as the scole..
22188 * @param {DomNode} node node to iterate children of.
22189 * @param {Function} fn method of this class to call on each item.
22191 iterateChildren : function(node, fn)
22193 if (!node.childNodes.length) {
22196 for (var i = node.childNodes.length-1; i > -1 ; i--) {
22197 fn.call(this, node.childNodes[i])
22203 * cleanTableWidths.
22205 * Quite often pasting from word etc.. results in tables with column and widths.
22206 * This does not work well on fluid HTML layouts - like emails. - so this code should hunt an destroy them..
22209 cleanTableWidths : function(node)
22214 this.cleanTableWidths(this.doc.body);
22219 if (node.nodeName == "#text" || node.nodeName == "#comment") {
22222 Roo.log(node.tagName);
22223 if (!node.tagName.toLowerCase().match(/^(table|td|tr)$/)) {
22224 this.iterateChildren(node, this.cleanTableWidths);
22227 if (node.hasAttribute('width')) {
22228 node.removeAttribute('width');
22232 if (node.hasAttribute("style")) {
22235 var styles = node.getAttribute("style").split(";");
22237 Roo.each(styles, function(s) {
22238 if (!s.match(/:/)) {
22241 var kv = s.split(":");
22242 if (kv[0].match(/^\s*(width|min-width)\s*$/)) {
22245 // what ever is left... we allow.
22248 node.setAttribute("style", nstyle.length ? nstyle.join(';') : '');
22249 if (!nstyle.length) {
22250 node.removeAttribute('style');
22254 this.iterateChildren(node, this.cleanTableWidths);
22262 domToHTML : function(currentElement, depth, nopadtext) {
22264 depth = depth || 0;
22265 nopadtext = nopadtext || false;
22267 if (!currentElement) {
22268 return this.domToHTML(this.doc.body);
22271 //Roo.log(currentElement);
22273 var allText = false;
22274 var nodeName = currentElement.nodeName;
22275 var tagName = Roo.util.Format.htmlEncode(currentElement.tagName);
22277 if (nodeName == '#text') {
22279 return nopadtext ? currentElement.nodeValue : currentElement.nodeValue.trim();
22284 if (nodeName != 'BODY') {
22287 // Prints the node tagName, such as <A>, <IMG>, etc
22290 for(i = 0; i < currentElement.attributes.length;i++) {
22292 var aname = currentElement.attributes.item(i).name;
22293 if (!currentElement.attributes.item(i).value.length) {
22296 attr.push(aname + '="' + Roo.util.Format.htmlEncode(currentElement.attributes.item(i).value) + '"' );
22299 ret = "<"+currentElement.tagName+ ( attr.length ? (' ' + attr.join(' ') ) : '') + ">";
22308 if (['IMG', 'BR', 'HR', 'INPUT'].indexOf(tagName) > -1) {
22311 if (['PRE', 'TEXTAREA', 'TD', 'A', 'SPAN'].indexOf(tagName) > -1) { // or code?
22316 // Traverse the tree
22318 var currentElementChild = currentElement.childNodes.item(i);
22319 var allText = true;
22320 var innerHTML = '';
22322 while (currentElementChild) {
22323 // Formatting code (indent the tree so it looks nice on the screen)
22324 var nopad = nopadtext;
22325 if (lastnode == 'SPAN') {
22329 if (currentElementChild.nodeName == '#text') {
22330 var toadd = Roo.util.Format.htmlEncode(currentElementChild.nodeValue);
22331 toadd = nopadtext ? toadd : toadd.trim();
22332 if (!nopad && toadd.length > 80) {
22333 innerHTML += "\n" + (new Array( depth + 1 )).join( " " );
22335 innerHTML += toadd;
22338 currentElementChild = currentElement.childNodes.item(i);
22344 innerHTML += nopad ? '' : "\n" + (new Array( depth + 1 )).join( " " );
22346 // Recursively traverse the tree structure of the child node
22347 innerHTML += this.domToHTML(currentElementChild, depth+1, nopadtext);
22348 lastnode = currentElementChild.nodeName;
22350 currentElementChild=currentElement.childNodes.item(i);
22356 // The remaining code is mostly for formatting the tree
22357 ret+= nopadtext ? '' : "\n" + (new Array( depth )).join( " " );
22362 ret+= "</"+tagName+">";
22368 applyBlacklists : function()
22370 var w = typeof(this.owner.white) != 'undefined' && this.owner.white ? this.owner.white : [];
22371 var b = typeof(this.owner.black) != 'undefined' && this.owner.black ? this.owner.black : [];
22375 Roo.each(Roo.HtmlEditorCore.white, function(tag) {
22376 if (b.indexOf(tag) > -1) {
22379 this.white.push(tag);
22383 Roo.each(w, function(tag) {
22384 if (b.indexOf(tag) > -1) {
22387 if (this.white.indexOf(tag) > -1) {
22390 this.white.push(tag);
22395 Roo.each(Roo.HtmlEditorCore.black, function(tag) {
22396 if (w.indexOf(tag) > -1) {
22399 this.black.push(tag);
22403 Roo.each(b, function(tag) {
22404 if (w.indexOf(tag) > -1) {
22407 if (this.black.indexOf(tag) > -1) {
22410 this.black.push(tag);
22415 w = typeof(this.owner.cwhite) != 'undefined' && this.owner.cwhite ? this.owner.cwhite : [];
22416 b = typeof(this.owner.cblack) != 'undefined' && this.owner.cblack ? this.owner.cblack : [];
22420 Roo.each(Roo.HtmlEditorCore.cwhite, function(tag) {
22421 if (b.indexOf(tag) > -1) {
22424 this.cwhite.push(tag);
22428 Roo.each(w, function(tag) {
22429 if (b.indexOf(tag) > -1) {
22432 if (this.cwhite.indexOf(tag) > -1) {
22435 this.cwhite.push(tag);
22440 Roo.each(Roo.HtmlEditorCore.cblack, function(tag) {
22441 if (w.indexOf(tag) > -1) {
22444 this.cblack.push(tag);
22448 Roo.each(b, function(tag) {
22449 if (w.indexOf(tag) > -1) {
22452 if (this.cblack.indexOf(tag) > -1) {
22455 this.cblack.push(tag);
22460 setStylesheets : function(stylesheets)
22462 if(typeof(stylesheets) == 'string'){
22463 Roo.get(this.iframe.contentDocument.head).createChild({
22465 rel : 'stylesheet',
22474 Roo.each(stylesheets, function(s) {
22479 Roo.get(_this.iframe.contentDocument.head).createChild({
22481 rel : 'stylesheet',
22490 removeStylesheets : function()
22494 Roo.each(Roo.get(_this.iframe.contentDocument.head).select('link[rel=stylesheet]', true).elements, function(s){
22499 setStyle : function(style)
22501 Roo.get(this.iframe.contentDocument.head).createChild({
22510 // hide stuff that is not compatible
22524 * @event specialkey
22528 * @cfg {String} fieldClass @hide
22531 * @cfg {String} focusClass @hide
22534 * @cfg {String} autoCreate @hide
22537 * @cfg {String} inputType @hide
22540 * @cfg {String} invalidClass @hide
22543 * @cfg {String} invalidText @hide
22546 * @cfg {String} msgFx @hide
22549 * @cfg {String} validateOnBlur @hide
22553 Roo.HtmlEditorCore.white = [
22554 'area', 'br', 'img', 'input', 'hr', 'wbr',
22556 'address', 'blockquote', 'center', 'dd', 'dir', 'div',
22557 'dl', 'dt', 'h1', 'h2', 'h3', 'h4',
22558 'h5', 'h6', 'hr', 'isindex', 'listing', 'marquee',
22559 'menu', 'multicol', 'ol', 'p', 'plaintext', 'pre',
22560 'table', 'ul', 'xmp',
22562 'caption', 'col', 'colgroup', 'tbody', 'td', 'tfoot', 'th',
22565 'dir', 'menu', 'ol', 'ul', 'dl',
22571 Roo.HtmlEditorCore.black = [
22572 // 'embed', 'object', // enable - backend responsiblity to clean thiese
22574 'base', 'basefont', 'bgsound', 'blink', 'body',
22575 'frame', 'frameset', 'head', 'html', 'ilayer',
22576 'iframe', 'layer', 'link', 'meta', 'object',
22577 'script', 'style' ,'title', 'xml' // clean later..
22579 Roo.HtmlEditorCore.clean = [
22580 'script', 'style', 'title', 'xml'
22582 Roo.HtmlEditorCore.remove = [
22587 Roo.HtmlEditorCore.ablack = [
22591 Roo.HtmlEditorCore.aclean = [
22592 'action', 'background', 'codebase', 'dynsrc', 'href', 'lowsrc'
22596 Roo.HtmlEditorCore.pwhite= [
22597 'http', 'https', 'mailto'
22600 // white listed style attributes.
22601 Roo.HtmlEditorCore.cwhite= [
22602 // 'text-align', /// default is to allow most things..
22608 // black listed style attributes.
22609 Roo.HtmlEditorCore.cblack= [
22610 // 'font-size' -- this can be set by the project
22614 Roo.HtmlEditorCore.swapCodes =[
22625 //<script type="text/javascript">
22628 * Ext JS Library 1.1.1
22629 * Copyright(c) 2006-2007, Ext JS, LLC.
22635 Roo.form.HtmlEditor = function(config){
22639 Roo.form.HtmlEditor.superclass.constructor.call(this, config);
22641 if (!this.toolbars) {
22642 this.toolbars = [];
22644 this.editorcore = new Roo.HtmlEditorCore(Roo.apply({ owner : this} , config));
22650 * @class Roo.form.HtmlEditor
22651 * @extends Roo.form.Field
22652 * Provides a lightweight HTML Editor component.
22654 * This has been tested on Fireforx / Chrome.. IE may not be so great..
22656 * <br><br><b>Note: The focus/blur and validation marking functionality inherited from Ext.form.Field is NOT
22657 * supported by this editor.</b><br/><br/>
22658 * An Editor is a sensitive component that can't be used in all spots standard fields can be used. Putting an Editor within
22659 * any element that has display set to 'none' can cause problems in Safari and Firefox.<br/><br/>
22661 Roo.extend(Roo.form.HtmlEditor, Roo.form.Field, {
22663 * @cfg {Boolean} clearUp
22667 * @cfg {Array} toolbars Array of toolbars. - defaults to just the Standard one
22672 * @cfg {String} resizable 's' or 'se' or 'e' - wrapps the element in a
22677 * @cfg {Number} height (in pixels)
22681 * @cfg {Number} width (in pixels)
22686 * @cfg {Array} stylesheets url of stylesheets. set to [] to disable stylesheets.
22689 stylesheets: false,
22693 * @cfg {Array} blacklist of css styles style attributes (blacklist overrides whitelist)
22698 * @cfg {Array} whitelist of css styles style attributes (blacklist overrides whitelist)
22704 * @cfg {Array} blacklist of html tags - in addition to standard blacklist.
22709 * @cfg {Array} whitelist of html tags - in addition to statndard whitelist
22717 // private properties
22718 validationEvent : false,
22720 initialized : false,
22723 onFocus : Roo.emptyFn,
22725 hideMode:'offsets',
22727 actionMode : 'container', // defaults to hiding it...
22729 defaultAutoCreate : { // modified by initCompnoent..
22731 style:"width:500px;height:300px;",
22732 autocomplete: "new-password"
22736 initComponent : function(){
22739 * @event initialize
22740 * Fires when the editor is fully initialized (including the iframe)
22741 * @param {HtmlEditor} this
22746 * Fires when the editor is first receives the focus. Any insertion must wait
22747 * until after this event.
22748 * @param {HtmlEditor} this
22752 * @event beforesync
22753 * Fires before the textarea is updated with content from the editor iframe. Return false
22754 * to cancel the sync.
22755 * @param {HtmlEditor} this
22756 * @param {String} html
22760 * @event beforepush
22761 * Fires before the iframe editor is updated with content from the textarea. Return false
22762 * to cancel the push.
22763 * @param {HtmlEditor} this
22764 * @param {String} html
22769 * Fires when the textarea is updated with content from the editor iframe.
22770 * @param {HtmlEditor} this
22771 * @param {String} html
22776 * Fires when the iframe editor is updated with content from the textarea.
22777 * @param {HtmlEditor} this
22778 * @param {String} html
22782 * @event editmodechange
22783 * Fires when the editor switches edit modes
22784 * @param {HtmlEditor} this
22785 * @param {Boolean} sourceEdit True if source edit, false if standard editing.
22787 editmodechange: true,
22789 * @event editorevent
22790 * Fires when on any editor (mouse up/down cursor movement etc.) - used for toolbar hooks.
22791 * @param {HtmlEditor} this
22795 * @event firstfocus
22796 * Fires when on first focus - needed by toolbars..
22797 * @param {HtmlEditor} this
22802 * Auto save the htmlEditor value as a file into Events
22803 * @param {HtmlEditor} this
22807 * @event savedpreview
22808 * preview the saved version of htmlEditor
22809 * @param {HtmlEditor} this
22811 savedpreview: true,
22814 * @event stylesheetsclick
22815 * Fires when press the Sytlesheets button
22816 * @param {Roo.HtmlEditorCore} this
22818 stylesheetsclick: true
22820 this.defaultAutoCreate = {
22822 style:'width: ' + this.width + 'px;height: ' + this.height + 'px;',
22823 autocomplete: "new-password"
22828 * Protected method that will not generally be called directly. It
22829 * is called when the editor creates its toolbar. Override this method if you need to
22830 * add custom toolbar buttons.
22831 * @param {HtmlEditor} editor
22833 createToolbar : function(editor){
22834 Roo.log("create toolbars");
22835 if (!editor.toolbars || !editor.toolbars.length) {
22836 editor.toolbars = [ new Roo.form.HtmlEditor.ToolbarStandard() ]; // can be empty?
22839 for (var i =0 ; i < editor.toolbars.length;i++) {
22840 editor.toolbars[i] = Roo.factory(
22841 typeof(editor.toolbars[i]) == 'string' ?
22842 { xtype: editor.toolbars[i]} : editor.toolbars[i],
22843 Roo.form.HtmlEditor);
22844 editor.toolbars[i].init(editor);
22852 onRender : function(ct, position)
22855 Roo.form.HtmlEditor.superclass.onRender.call(this, ct, position);
22857 this.wrap = this.el.wrap({
22858 cls:'x-html-editor-wrap', cn:{cls:'x-html-editor-tb'}
22861 this.editorcore.onRender(ct, position);
22863 if (this.resizable) {
22864 this.resizeEl = new Roo.Resizable(this.wrap, {
22868 minHeight : this.height,
22869 height: this.height,
22870 handles : this.resizable,
22873 resize : function(r, w, h) {
22874 _t.onResize(w,h); // -something
22880 this.createToolbar(this);
22884 this.setSize(this.wrap.getSize());
22886 if (this.resizeEl) {
22887 this.resizeEl.resizeTo.defer(100, this.resizeEl,[ this.width,this.height ] );
22888 // should trigger onReize..
22891 this.keyNav = new Roo.KeyNav(this.el, {
22893 "tab" : function(e){
22894 e.preventDefault();
22896 var value = this.getValue();
22898 var start = this.el.dom.selectionStart;
22899 var end = this.el.dom.selectionEnd;
22903 this.setValue(value.substring(0, start) + "\t" + value.substring(end));
22904 this.el.dom.setSelectionRange(end + 1, end + 1);
22908 var f = value.substring(0, start).split("\t");
22910 if(f.pop().length != 0){
22914 this.setValue(f.join("\t") + value.substring(end));
22915 this.el.dom.setSelectionRange(start - 1, start - 1);
22919 "home" : function(e){
22920 e.preventDefault();
22922 var curr = this.el.dom.selectionStart;
22923 var lines = this.getValue().split("\n");
22930 this.el.dom.setSelectionRange(0, 0);
22936 for (var i = 0; i < lines.length;i++) {
22937 pos += lines[i].length;
22947 pos -= lines[i].length;
22953 this.el.dom.setSelectionRange(pos, pos);
22957 this.el.dom.selectionStart = pos;
22958 this.el.dom.selectionEnd = curr;
22961 "end" : function(e){
22962 e.preventDefault();
22964 var curr = this.el.dom.selectionStart;
22965 var lines = this.getValue().split("\n");
22972 this.el.dom.setSelectionRange(this.getValue().length, this.getValue().length);
22978 for (var i = 0; i < lines.length;i++) {
22980 pos += lines[i].length;
22994 this.el.dom.setSelectionRange(pos, pos);
22998 this.el.dom.selectionStart = curr;
22999 this.el.dom.selectionEnd = pos;
23004 doRelay : function(foo, bar, hname){
23005 return Roo.KeyNav.prototype.doRelay.apply(this, arguments);
23011 // if(this.autosave && this.w){
23012 // this.autoSaveFn = setInterval(this.autosave, 1000);
23017 onResize : function(w, h)
23019 Roo.form.HtmlEditor.superclass.onResize.apply(this, arguments);
23024 if(typeof w == 'number'){
23025 var aw = w - this.wrap.getFrameWidth('lr');
23026 this.el.setWidth(this.adjustWidth('textarea', aw));
23029 if(typeof h == 'number'){
23031 for (var i =0; i < this.toolbars.length;i++) {
23032 // fixme - ask toolbars for heights?
23033 tbh += this.toolbars[i].tb.el.getHeight();
23034 if (this.toolbars[i].footer) {
23035 tbh += this.toolbars[i].footer.el.getHeight();
23042 var ah = h - this.wrap.getFrameWidth('tb') - tbh;// this.tb.el.getHeight();
23043 ah -= 5; // knock a few pixes off for look..
23045 this.el.setHeight(this.adjustWidth('textarea', ah));
23049 Roo.log('onResize:' + [w,h,ew,eh].join(',') );
23050 this.editorcore.onResize(ew,eh);
23055 * Toggles the editor between standard and source edit mode.
23056 * @param {Boolean} sourceEdit (optional) True for source edit, false for standard
23058 toggleSourceEdit : function(sourceEditMode)
23060 this.editorcore.toggleSourceEdit(sourceEditMode);
23062 if(this.editorcore.sourceEditMode){
23063 Roo.log('editor - showing textarea');
23066 // Roo.log(this.syncValue());
23067 this.editorcore.syncValue();
23068 this.el.removeClass('x-hidden');
23069 this.el.dom.removeAttribute('tabIndex');
23072 for (var i = 0; i < this.toolbars.length; i++) {
23073 if(this.toolbars[i] instanceof Roo.form.HtmlEditor.ToolbarContext){
23074 this.toolbars[i].tb.hide();
23075 this.toolbars[i].footer.hide();
23080 Roo.log('editor - hiding textarea');
23082 // Roo.log(this.pushValue());
23083 this.editorcore.pushValue();
23085 this.el.addClass('x-hidden');
23086 this.el.dom.setAttribute('tabIndex', -1);
23088 for (var i = 0; i < this.toolbars.length; i++) {
23089 if(this.toolbars[i] instanceof Roo.form.HtmlEditor.ToolbarContext){
23090 this.toolbars[i].tb.show();
23091 this.toolbars[i].footer.show();
23095 //this.deferFocus();
23098 this.setSize(this.wrap.getSize());
23099 this.onResize(this.wrap.getSize().width, this.wrap.getSize().height);
23101 this.fireEvent('editmodechange', this, this.editorcore.sourceEditMode);
23104 // private (for BoxComponent)
23105 adjustSize : Roo.BoxComponent.prototype.adjustSize,
23107 // private (for BoxComponent)
23108 getResizeEl : function(){
23112 // private (for BoxComponent)
23113 getPositionEl : function(){
23118 initEvents : function(){
23119 this.originalValue = this.getValue();
23123 * Overridden and disabled. The editor element does not support standard valid/invalid marking. @hide
23126 markInvalid : Roo.emptyFn,
23128 * Overridden and disabled. The editor element does not support standard valid/invalid marking. @hide
23131 clearInvalid : Roo.emptyFn,
23133 setValue : function(v){
23134 Roo.form.HtmlEditor.superclass.setValue.call(this, v);
23135 this.editorcore.pushValue();
23140 deferFocus : function(){
23141 this.focus.defer(10, this);
23145 focus : function(){
23146 this.editorcore.focus();
23152 onDestroy : function(){
23158 for (var i =0; i < this.toolbars.length;i++) {
23159 // fixme - ask toolbars for heights?
23160 this.toolbars[i].onDestroy();
23163 this.wrap.dom.innerHTML = '';
23164 this.wrap.remove();
23169 onFirstFocus : function(){
23170 //Roo.log("onFirstFocus");
23171 this.editorcore.onFirstFocus();
23172 for (var i =0; i < this.toolbars.length;i++) {
23173 this.toolbars[i].onFirstFocus();
23179 syncValue : function()
23181 this.editorcore.syncValue();
23184 pushValue : function()
23186 this.editorcore.pushValue();
23189 setStylesheets : function(stylesheets)
23191 this.editorcore.setStylesheets(stylesheets);
23194 removeStylesheets : function()
23196 this.editorcore.removeStylesheets();
23200 // hide stuff that is not compatible
23214 * @event specialkey
23218 * @cfg {String} fieldClass @hide
23221 * @cfg {String} focusClass @hide
23224 * @cfg {String} autoCreate @hide
23227 * @cfg {String} inputType @hide
23230 * @cfg {String} invalidClass @hide
23233 * @cfg {String} invalidText @hide
23236 * @cfg {String} msgFx @hide
23239 * @cfg {String} validateOnBlur @hide
23243 // <script type="text/javascript">
23246 * Ext JS Library 1.1.1
23247 * Copyright(c) 2006-2007, Ext JS, LLC.
23253 * @class Roo.form.HtmlEditorToolbar1
23258 new Roo.form.HtmlEditor({
23261 new Roo.form.HtmlEditorToolbar1({
23262 disable : { fonts: 1 , format: 1, ..., ... , ...],
23268 * @cfg {Object} disable List of elements to disable..
23269 * @cfg {Array} btns List of additional buttons.
23273 * .x-html-editor-tb .x-edit-none .x-btn-text { background: none; }
23276 Roo.form.HtmlEditor.ToolbarStandard = function(config)
23279 Roo.apply(this, config);
23281 // default disabled, based on 'good practice'..
23282 this.disable = this.disable || {};
23283 Roo.applyIf(this.disable, {
23286 specialElements : true
23290 //Roo.form.HtmlEditorToolbar1.superclass.constructor.call(this, editor.wrap.dom.firstChild, [], config);
23291 // dont call parent... till later.
23294 Roo.apply(Roo.form.HtmlEditor.ToolbarStandard.prototype, {
23301 editorcore : false,
23303 * @cfg {Object} disable List of toolbar elements to disable
23310 * @cfg {String} createLinkText The default text for the create link prompt
23312 createLinkText : 'Please enter the URL for the link:',
23314 * @cfg {String} defaultLinkValue The default value for the create link prompt (defaults to http:/ /)
23316 defaultLinkValue : 'http:/'+'/',
23320 * @cfg {Array} fontFamilies An array of available font families
23338 // "á" , ?? a acute?
23343 "°" // , // degrees
23345 // "é" , // e ecute
23346 // "ú" , // u ecute?
23349 specialElements : [
23351 text: "Insert Table",
23354 ihtml : '<table><tr><td>Cell</td></tr></table>'
23358 text: "Insert Image",
23361 ihtml : '<img src="about:blank"/>'
23370 "form", "input:text", "input:hidden", "input:checkbox", "input:radio", "input:password",
23371 "input:submit", "input:button", "select", "textarea", "label" ],
23374 ["h1"],["h2"],["h3"],["h4"],["h5"],["h6"],
23376 ["abbr"],[ "acronym"],[ "address"],[ "cite"],[ "samp"],[ "var"],
23385 * @cfg {String} defaultFont default font to use.
23387 defaultFont: 'tahoma',
23389 fontSelect : false,
23392 formatCombo : false,
23394 init : function(editor)
23396 this.editor = editor;
23397 this.editorcore = editor.editorcore ? editor.editorcore : editor;
23398 var editorcore = this.editorcore;
23402 var fid = editorcore.frameId;
23404 function btn(id, toggle, handler){
23405 var xid = fid + '-'+ id ;
23409 cls : 'x-btn-icon x-edit-'+id,
23410 enableToggle:toggle !== false,
23411 scope: _t, // was editor...
23412 handler:handler||_t.relayBtnCmd,
23413 clickEvent:'mousedown',
23414 tooltip: etb.buttonTips[id] || undefined, ///tips ???
23421 var tb = new Roo.Toolbar(editor.wrap.dom.firstChild);
23423 // stop form submits
23424 tb.el.on('click', function(e){
23425 e.preventDefault(); // what does this do?
23428 if(!this.disable.font) { // && !Roo.isSafari){
23429 /* why no safari for fonts
23430 editor.fontSelect = tb.el.createChild({
23433 cls:'x-font-select',
23434 html: this.createFontOptions()
23437 editor.fontSelect.on('change', function(){
23438 var font = editor.fontSelect.dom.value;
23439 editor.relayCmd('fontname', font);
23440 editor.deferFocus();
23444 editor.fontSelect.dom,
23450 if(!this.disable.formats){
23451 this.formatCombo = new Roo.form.ComboBox({
23452 store: new Roo.data.SimpleStore({
23455 data : this.formats // from states.js
23459 //autoCreate : {tag: "div", size: "20"},
23460 displayField:'tag',
23464 triggerAction: 'all',
23465 emptyText:'Add tag',
23466 selectOnFocus:true,
23469 'select': function(c, r, i) {
23470 editorcore.insertTag(r.get('tag'));
23476 tb.addField(this.formatCombo);
23480 if(!this.disable.format){
23485 btn('strikethrough')
23488 if(!this.disable.fontSize){
23493 btn('increasefontsize', false, editorcore.adjustFont),
23494 btn('decreasefontsize', false, editorcore.adjustFont)
23499 if(!this.disable.colors){
23502 id:editorcore.frameId +'-forecolor',
23503 cls:'x-btn-icon x-edit-forecolor',
23504 clickEvent:'mousedown',
23505 tooltip: this.buttonTips['forecolor'] || undefined,
23507 menu : new Roo.menu.ColorMenu({
23508 allowReselect: true,
23509 focus: Roo.emptyFn,
23512 selectHandler: function(cp, color){
23513 editorcore.execCmd('forecolor', Roo.isSafari || Roo.isIE ? '#'+color : color);
23514 editor.deferFocus();
23517 clickEvent:'mousedown'
23520 id:editorcore.frameId +'backcolor',
23521 cls:'x-btn-icon x-edit-backcolor',
23522 clickEvent:'mousedown',
23523 tooltip: this.buttonTips['backcolor'] || undefined,
23525 menu : new Roo.menu.ColorMenu({
23526 focus: Roo.emptyFn,
23529 allowReselect: true,
23530 selectHandler: function(cp, color){
23532 editorcore.execCmd('useCSS', false);
23533 editorcore.execCmd('hilitecolor', color);
23534 editorcore.execCmd('useCSS', true);
23535 editor.deferFocus();
23537 editorcore.execCmd(Roo.isOpera ? 'hilitecolor' : 'backcolor',
23538 Roo.isSafari || Roo.isIE ? '#'+color : color);
23539 editor.deferFocus();
23543 clickEvent:'mousedown'
23548 // now add all the items...
23551 if(!this.disable.alignments){
23554 btn('justifyleft'),
23555 btn('justifycenter'),
23556 btn('justifyright')
23560 //if(!Roo.isSafari){
23561 if(!this.disable.links){
23564 btn('createlink', false, this.createLink) /// MOVE TO HERE?!!?!?!?!
23568 if(!this.disable.lists){
23571 btn('insertorderedlist'),
23572 btn('insertunorderedlist')
23575 if(!this.disable.sourceEdit){
23578 btn('sourceedit', true, function(btn){
23579 this.toggleSourceEdit(btn.pressed);
23586 // special menu.. - needs to be tidied up..
23587 if (!this.disable.special) {
23590 cls: 'x-edit-none',
23596 for (var i =0; i < this.specialChars.length; i++) {
23597 smenu.menu.items.push({
23599 html: this.specialChars[i],
23600 handler: function(a,b) {
23601 editorcore.insertAtCursor(String.fromCharCode(a.html.replace('&#','').replace(';', '')));
23602 //editor.insertAtCursor(a.html);
23616 if (!this.disable.cleanStyles) {
23618 cls: 'x-btn-icon x-btn-clear',
23624 for (var i =0; i < this.cleanStyles.length; i++) {
23625 cmenu.menu.items.push({
23626 actiontype : this.cleanStyles[i],
23627 html: 'Remove ' + this.cleanStyles[i],
23628 handler: function(a,b) {
23631 var c = Roo.get(editorcore.doc.body);
23632 c.select('[style]').each(function(s) {
23633 s.dom.style.removeProperty(a.actiontype);
23635 editorcore.syncValue();
23640 cmenu.menu.items.push({
23641 actiontype : 'tablewidths',
23642 html: 'Remove Table Widths',
23643 handler: function(a,b) {
23644 editorcore.cleanTableWidths();
23645 editorcore.syncValue();
23649 cmenu.menu.items.push({
23650 actiontype : 'word',
23651 html: 'Remove MS Word Formating',
23652 handler: function(a,b) {
23653 editorcore.cleanWord();
23654 editorcore.syncValue();
23659 cmenu.menu.items.push({
23660 actiontype : 'all',
23661 html: 'Remove All Styles',
23662 handler: function(a,b) {
23664 var c = Roo.get(editorcore.doc.body);
23665 c.select('[style]').each(function(s) {
23666 s.dom.removeAttribute('style');
23668 editorcore.syncValue();
23673 cmenu.menu.items.push({
23674 actiontype : 'all',
23675 html: 'Remove All CSS Classes',
23676 handler: function(a,b) {
23678 var c = Roo.get(editorcore.doc.body);
23679 c.select('[class]').each(function(s) {
23680 s.dom.removeAttribute('class');
23682 editorcore.cleanWord();
23683 editorcore.syncValue();
23688 cmenu.menu.items.push({
23689 actiontype : 'tidy',
23690 html: 'Tidy HTML Source',
23691 handler: function(a,b) {
23692 editorcore.doc.body.innerHTML = editorcore.domToHTML();
23693 editorcore.syncValue();
23702 if (!this.disable.specialElements) {
23705 cls: 'x-edit-none',
23710 for (var i =0; i < this.specialElements.length; i++) {
23711 semenu.menu.items.push(
23713 handler: function(a,b) {
23714 editor.insertAtCursor(this.ihtml);
23716 }, this.specialElements[i])
23728 for(var i =0; i< this.btns.length;i++) {
23729 var b = Roo.factory(this.btns[i],Roo.form);
23730 b.cls = 'x-edit-none';
23732 if(typeof(this.btns[i].cls) != 'undefined' && this.btns[i].cls.indexOf('x-init-enable') !== -1){
23733 b.cls += ' x-init-enable';
23736 b.scope = editorcore;
23744 // disable everything...
23746 this.tb.items.each(function(item){
23749 item.id != editorcore.frameId+ '-sourceedit' &&
23750 (typeof(item.cls) != 'undefined' && item.cls.indexOf('x-init-enable') === -1)
23756 this.rendered = true;
23758 // the all the btns;
23759 editor.on('editorevent', this.updateToolbar, this);
23760 // other toolbars need to implement this..
23761 //editor.on('editmodechange', this.updateToolbar, this);
23765 relayBtnCmd : function(btn) {
23766 this.editorcore.relayCmd(btn.cmd);
23768 // private used internally
23769 createLink : function(){
23770 Roo.log("create link?");
23771 var url = prompt(this.createLinkText, this.defaultLinkValue);
23772 if(url && url != 'http:/'+'/'){
23773 this.editorcore.relayCmd('createlink', url);
23779 * Protected method that will not generally be called directly. It triggers
23780 * a toolbar update by reading the markup state of the current selection in the editor.
23782 updateToolbar: function(){
23784 if(!this.editorcore.activated){
23785 this.editor.onFirstFocus();
23789 var btns = this.tb.items.map,
23790 doc = this.editorcore.doc,
23791 frameId = this.editorcore.frameId;
23793 if(!this.disable.font && !Roo.isSafari){
23795 var name = (doc.queryCommandValue('FontName')||this.editor.defaultFont).toLowerCase();
23796 if(name != this.fontSelect.dom.value){
23797 this.fontSelect.dom.value = name;
23801 if(!this.disable.format){
23802 btns[frameId + '-bold'].toggle(doc.queryCommandState('bold'));
23803 btns[frameId + '-italic'].toggle(doc.queryCommandState('italic'));
23804 btns[frameId + '-underline'].toggle(doc.queryCommandState('underline'));
23805 btns[frameId + '-strikethrough'].toggle(doc.queryCommandState('strikethrough'));
23807 if(!this.disable.alignments){
23808 btns[frameId + '-justifyleft'].toggle(doc.queryCommandState('justifyleft'));
23809 btns[frameId + '-justifycenter'].toggle(doc.queryCommandState('justifycenter'));
23810 btns[frameId + '-justifyright'].toggle(doc.queryCommandState('justifyright'));
23812 if(!Roo.isSafari && !this.disable.lists){
23813 btns[frameId + '-insertorderedlist'].toggle(doc.queryCommandState('insertorderedlist'));
23814 btns[frameId + '-insertunorderedlist'].toggle(doc.queryCommandState('insertunorderedlist'));
23817 var ans = this.editorcore.getAllAncestors();
23818 if (this.formatCombo) {
23821 var store = this.formatCombo.store;
23822 this.formatCombo.setValue("");
23823 for (var i =0; i < ans.length;i++) {
23824 if (ans[i] && store.query('tag',ans[i].tagName.toLowerCase(), false).length) {
23826 this.formatCombo.setValue(ans[i].tagName.toLowerCase());
23834 // hides menus... - so this cant be on a menu...
23835 Roo.menu.MenuMgr.hideAll();
23837 //this.editorsyncValue();
23841 createFontOptions : function(){
23842 var buf = [], fs = this.fontFamilies, ff, lc;
23846 for(var i = 0, len = fs.length; i< len; i++){
23848 lc = ff.toLowerCase();
23850 '<option value="',lc,'" style="font-family:',ff,';"',
23851 (this.defaultFont == lc ? ' selected="true">' : '>'),
23856 return buf.join('');
23859 toggleSourceEdit : function(sourceEditMode){
23861 Roo.log("toolbar toogle");
23862 if(sourceEditMode === undefined){
23863 sourceEditMode = !this.sourceEditMode;
23865 this.sourceEditMode = sourceEditMode === true;
23866 var btn = this.tb.items.get(this.editorcore.frameId +'-sourceedit');
23867 // just toggle the button?
23868 if(btn.pressed !== this.sourceEditMode){
23869 btn.toggle(this.sourceEditMode);
23873 if(sourceEditMode){
23874 Roo.log("disabling buttons");
23875 this.tb.items.each(function(item){
23876 if(item.cmd != 'sourceedit' && (typeof(item.cls) != 'undefined' && item.cls.indexOf('x-init-enable') === -1)){
23882 Roo.log("enabling buttons");
23883 if(this.editorcore.initialized){
23884 this.tb.items.each(function(item){
23890 Roo.log("calling toggole on editor");
23891 // tell the editor that it's been pressed..
23892 this.editor.toggleSourceEdit(sourceEditMode);
23896 * Object collection of toolbar tooltips for the buttons in the editor. The key
23897 * is the command id associated with that button and the value is a valid QuickTips object.
23902 title: 'Bold (Ctrl+B)',
23903 text: 'Make the selected text bold.',
23904 cls: 'x-html-editor-tip'
23907 title: 'Italic (Ctrl+I)',
23908 text: 'Make the selected text italic.',
23909 cls: 'x-html-editor-tip'
23917 title: 'Bold (Ctrl+B)',
23918 text: 'Make the selected text bold.',
23919 cls: 'x-html-editor-tip'
23922 title: 'Italic (Ctrl+I)',
23923 text: 'Make the selected text italic.',
23924 cls: 'x-html-editor-tip'
23927 title: 'Underline (Ctrl+U)',
23928 text: 'Underline the selected text.',
23929 cls: 'x-html-editor-tip'
23932 title: 'Strikethrough',
23933 text: 'Strikethrough the selected text.',
23934 cls: 'x-html-editor-tip'
23936 increasefontsize : {
23937 title: 'Grow Text',
23938 text: 'Increase the font size.',
23939 cls: 'x-html-editor-tip'
23941 decreasefontsize : {
23942 title: 'Shrink Text',
23943 text: 'Decrease the font size.',
23944 cls: 'x-html-editor-tip'
23947 title: 'Text Highlight Color',
23948 text: 'Change the background color of the selected text.',
23949 cls: 'x-html-editor-tip'
23952 title: 'Font Color',
23953 text: 'Change the color of the selected text.',
23954 cls: 'x-html-editor-tip'
23957 title: 'Align Text Left',
23958 text: 'Align text to the left.',
23959 cls: 'x-html-editor-tip'
23962 title: 'Center Text',
23963 text: 'Center text in the editor.',
23964 cls: 'x-html-editor-tip'
23967 title: 'Align Text Right',
23968 text: 'Align text to the right.',
23969 cls: 'x-html-editor-tip'
23971 insertunorderedlist : {
23972 title: 'Bullet List',
23973 text: 'Start a bulleted list.',
23974 cls: 'x-html-editor-tip'
23976 insertorderedlist : {
23977 title: 'Numbered List',
23978 text: 'Start a numbered list.',
23979 cls: 'x-html-editor-tip'
23982 title: 'Hyperlink',
23983 text: 'Make the selected text a hyperlink.',
23984 cls: 'x-html-editor-tip'
23987 title: 'Source Edit',
23988 text: 'Switch to source editing mode.',
23989 cls: 'x-html-editor-tip'
23993 onDestroy : function(){
23996 this.tb.items.each(function(item){
23998 item.menu.removeAll();
24000 item.menu.el.destroy();
24008 onFirstFocus: function() {
24009 this.tb.items.each(function(item){
24018 // <script type="text/javascript">
24021 * Ext JS Library 1.1.1
24022 * Copyright(c) 2006-2007, Ext JS, LLC.
24029 * @class Roo.form.HtmlEditor.ToolbarContext
24034 new Roo.form.HtmlEditor({
24037 { xtype: 'ToolbarStandard', styles : {} }
24038 { xtype: 'ToolbarContext', disable : {} }
24044 * @config : {Object} disable List of elements to disable.. (not done yet.)
24045 * @config : {Object} styles Map of styles available.
24049 Roo.form.HtmlEditor.ToolbarContext = function(config)
24052 Roo.apply(this, config);
24053 //Roo.form.HtmlEditorToolbar1.superclass.constructor.call(this, editor.wrap.dom.firstChild, [], config);
24054 // dont call parent... till later.
24055 this.styles = this.styles || {};
24060 Roo.form.HtmlEditor.ToolbarContext.types = {
24072 opts : [ [""],[ "left"],[ "right"],[ "center"],[ "top"]],
24138 opts : [[""],[ "left"],[ "center"],[ "right"],[ "justify"],[ "char"]],
24143 opts : [[""],[ "top"],[ "middle"],[ "bottom"],[ "baseline"]],
24153 style : 'fontFamily',
24154 displayField: 'display',
24155 optname : 'font-family',
24204 // should we really allow this??
24205 // should this just be
24216 style : 'fontFamily',
24217 displayField: 'display',
24218 optname : 'font-family',
24225 style : 'fontFamily',
24226 displayField: 'display',
24227 optname : 'font-family',
24234 style : 'fontFamily',
24235 displayField: 'display',
24236 optname : 'font-family',
24247 // this should be configurable.. - you can either set it up using stores, or modify options somehwere..
24248 Roo.form.HtmlEditor.ToolbarContext.stores = false;
24250 Roo.form.HtmlEditor.ToolbarContext.options = {
24252 [ 'Helvetica,Arial,sans-serif', 'Helvetica'],
24253 [ 'Courier New', 'Courier New'],
24254 [ 'Tahoma', 'Tahoma'],
24255 [ 'Times New Roman,serif', 'Times'],
24256 [ 'Verdana','Verdana' ]
24260 // fixme - these need to be configurable..
24263 //Roo.form.HtmlEditor.ToolbarContext.types
24266 Roo.apply(Roo.form.HtmlEditor.ToolbarContext.prototype, {
24273 editorcore : false,
24275 * @cfg {Object} disable List of toolbar elements to disable
24280 * @cfg {Object} styles List of styles
24281 * eg. { '*' : [ 'headline' ] , 'TD' : [ 'underline', 'double-underline' ] }
24283 * These must be defined in the page, so they get rendered correctly..
24294 init : function(editor)
24296 this.editor = editor;
24297 this.editorcore = editor.editorcore ? editor.editorcore : editor;
24298 var editorcore = this.editorcore;
24300 var fid = editorcore.frameId;
24302 function btn(id, toggle, handler){
24303 var xid = fid + '-'+ id ;
24307 cls : 'x-btn-icon x-edit-'+id,
24308 enableToggle:toggle !== false,
24309 scope: editorcore, // was editor...
24310 handler:handler||editorcore.relayBtnCmd,
24311 clickEvent:'mousedown',
24312 tooltip: etb.buttonTips[id] || undefined, ///tips ???
24316 // create a new element.
24317 var wdiv = editor.wrap.createChild({
24319 }, editor.wrap.dom.firstChild.nextSibling, true);
24321 // can we do this more than once??
24323 // stop form submits
24326 // disable everything...
24327 var ty= Roo.form.HtmlEditor.ToolbarContext.types;
24328 this.toolbars = {};
24330 for (var i in ty) {
24332 this.toolbars[i] = this.buildToolbar(ty[i],i);
24334 this.tb = this.toolbars.BODY;
24336 this.buildFooter();
24337 this.footer.show();
24338 editor.on('hide', function( ) { this.footer.hide() }, this);
24339 editor.on('show', function( ) { this.footer.show() }, this);
24342 this.rendered = true;
24344 // the all the btns;
24345 editor.on('editorevent', this.updateToolbar, this);
24346 // other toolbars need to implement this..
24347 //editor.on('editmodechange', this.updateToolbar, this);
24353 * Protected method that will not generally be called directly. It triggers
24354 * a toolbar update by reading the markup state of the current selection in the editor.
24356 * Note you can force an update by calling on('editorevent', scope, false)
24358 updateToolbar: function(editor,ev,sel){
24361 // capture mouse up - this is handy for selecting images..
24362 // perhaps should go somewhere else...
24363 if(!this.editorcore.activated){
24364 this.editor.onFirstFocus();
24370 // http://developer.yahoo.com/yui/docs/simple-editor.js.html
24371 // selectNode - might want to handle IE?
24373 (ev.type == 'mouseup' || ev.type == 'click' ) &&
24374 ev.target && ev.target.tagName == 'IMG') {
24375 // they have click on an image...
24376 // let's see if we can change the selection...
24379 var nodeRange = sel.ownerDocument.createRange();
24381 nodeRange.selectNode(sel);
24383 nodeRange.selectNodeContents(sel);
24385 //nodeRange.collapse(true);
24386 var s = this.editorcore.win.getSelection();
24387 s.removeAllRanges();
24388 s.addRange(nodeRange);
24392 var updateFooter = sel ? false : true;
24395 var ans = this.editorcore.getAllAncestors();
24398 var ty= Roo.form.HtmlEditor.ToolbarContext.types;
24401 sel = ans.length ? (ans[0] ? ans[0] : ans[1]) : this.editorcore.doc.body;
24402 sel = sel ? sel : this.editorcore.doc.body;
24403 sel = sel.tagName.length ? sel : this.editorcore.doc.body;
24406 // pick a menu that exists..
24407 var tn = sel.tagName.toUpperCase();
24408 //sel = typeof(ty[tn]) != 'undefined' ? sel : this.editor.doc.body;
24410 tn = sel.tagName.toUpperCase();
24412 var lastSel = this.tb.selectedNode;
24414 this.tb.selectedNode = sel;
24416 // if current menu does not match..
24418 if ((this.tb.name != tn) || (lastSel != this.tb.selectedNode) || ev === false) {
24421 ///console.log("show: " + tn);
24422 this.tb = typeof(ty[tn]) != 'undefined' ? this.toolbars[tn] : this.toolbars['*'];
24425 this.tb.items.first().el.innerHTML = tn + ': ';
24428 // update attributes
24429 if (this.tb.fields) {
24430 this.tb.fields.each(function(e) {
24432 e.setValue(sel.style[e.stylename]);
24435 e.setValue(sel.getAttribute(e.attrname));
24439 var hasStyles = false;
24440 for(var i in this.styles) {
24447 var st = this.tb.fields.item(0);
24449 st.store.removeAll();
24452 var cn = sel.className.split(/\s+/);
24455 if (this.styles['*']) {
24457 Roo.each(this.styles['*'], function(v) {
24458 avs.push( [ v , cn.indexOf(v) > -1 ? 1 : 0 ] );
24461 if (this.styles[tn]) {
24462 Roo.each(this.styles[tn], function(v) {
24463 avs.push( [ v , cn.indexOf(v) > -1 ? 1 : 0 ] );
24467 st.store.loadData(avs);
24471 // flag our selected Node.
24472 this.tb.selectedNode = sel;
24475 Roo.menu.MenuMgr.hideAll();
24479 if (!updateFooter) {
24480 //this.footDisp.dom.innerHTML = '';
24483 // update the footer
24487 this.footerEls = ans.reverse();
24488 Roo.each(this.footerEls, function(a,i) {
24489 if (!a) { return; }
24490 html += html.length ? ' > ' : '';
24492 html += '<span class="x-ed-loc-' + i + '">' + a.tagName + '</span>';
24497 var sz = this.footDisp.up('td').getSize();
24498 this.footDisp.dom.style.width = (sz.width -10) + 'px';
24499 this.footDisp.dom.style.marginLeft = '5px';
24501 this.footDisp.dom.style.overflow = 'hidden';
24503 this.footDisp.dom.innerHTML = html;
24505 //this.editorsyncValue();
24512 onDestroy : function(){
24515 this.tb.items.each(function(item){
24517 item.menu.removeAll();
24519 item.menu.el.destroy();
24527 onFirstFocus: function() {
24528 // need to do this for all the toolbars..
24529 this.tb.items.each(function(item){
24533 buildToolbar: function(tlist, nm)
24535 var editor = this.editor;
24536 var editorcore = this.editorcore;
24537 // create a new element.
24538 var wdiv = editor.wrap.createChild({
24540 }, editor.wrap.dom.firstChild.nextSibling, true);
24543 var tb = new Roo.Toolbar(wdiv);
24546 tb.add(nm+ ": ");
24549 for(var i in this.styles) {
24554 if (styles && styles.length) {
24556 // this needs a multi-select checkbox...
24557 tb.addField( new Roo.form.ComboBox({
24558 store: new Roo.data.SimpleStore({
24560 fields: ['val', 'selected'],
24563 name : '-roo-edit-className',
24564 attrname : 'className',
24565 displayField: 'val',
24569 triggerAction: 'all',
24570 emptyText:'Select Style',
24571 selectOnFocus:true,
24574 'select': function(c, r, i) {
24575 // initial support only for on class per el..
24576 tb.selectedNode.className = r ? r.get('val') : '';
24577 editorcore.syncValue();
24584 var tbc = Roo.form.HtmlEditor.ToolbarContext;
24585 var tbops = tbc.options;
24587 for (var i in tlist) {
24589 var item = tlist[i];
24590 tb.add(item.title + ": ");
24593 //optname == used so you can configure the options available..
24594 var opts = item.opts ? item.opts : false;
24595 if (item.optname) {
24596 opts = tbops[item.optname];
24601 // opts == pulldown..
24602 tb.addField( new Roo.form.ComboBox({
24603 store: typeof(tbc.stores[i]) != 'undefined' ? Roo.factory(tbc.stores[i],Roo.data) : new Roo.data.SimpleStore({
24605 fields: ['val', 'display'],
24608 name : '-roo-edit-' + i,
24610 stylename : item.style ? item.style : false,
24611 displayField: item.displayField ? item.displayField : 'val',
24612 valueField : 'val',
24614 mode: typeof(tbc.stores[i]) != 'undefined' ? 'remote' : 'local',
24616 triggerAction: 'all',
24617 emptyText:'Select',
24618 selectOnFocus:true,
24619 width: item.width ? item.width : 130,
24621 'select': function(c, r, i) {
24623 tb.selectedNode.style[c.stylename] = r.get('val');
24626 tb.selectedNode.setAttribute(c.attrname, r.get('val'));
24635 tb.addField( new Roo.form.TextField({
24638 //allowBlank:false,
24643 tb.addField( new Roo.form.TextField({
24644 name: '-roo-edit-' + i,
24651 'change' : function(f, nv, ov) {
24652 tb.selectedNode.setAttribute(f.attrname, nv);
24653 editorcore.syncValue();
24666 text: 'Stylesheets',
24669 click : function ()
24671 _this.editor.fireEvent('stylesheetsclick', _this.editor);
24679 text: 'Remove Tag',
24682 click : function ()
24685 // undo does not work.
24687 var sn = tb.selectedNode;
24689 var pn = sn.parentNode;
24691 var stn = sn.childNodes[0];
24692 var en = sn.childNodes[sn.childNodes.length - 1 ];
24693 while (sn.childNodes.length) {
24694 var node = sn.childNodes[0];
24695 sn.removeChild(node);
24697 pn.insertBefore(node, sn);
24700 pn.removeChild(sn);
24701 var range = editorcore.createRange();
24703 range.setStart(stn,0);
24704 range.setEnd(en,0); //????
24705 //range.selectNode(sel);
24708 var selection = editorcore.getSelection();
24709 selection.removeAllRanges();
24710 selection.addRange(range);
24714 //_this.updateToolbar(null, null, pn);
24715 _this.updateToolbar(null, null, null);
24716 _this.footDisp.dom.innerHTML = '';
24726 tb.el.on('click', function(e){
24727 e.preventDefault(); // what does this do?
24729 tb.el.setVisibilityMode( Roo.Element.DISPLAY);
24732 // dont need to disable them... as they will get hidden
24737 buildFooter : function()
24740 var fel = this.editor.wrap.createChild();
24741 this.footer = new Roo.Toolbar(fel);
24742 // toolbar has scrolly on left / right?
24743 var footDisp= new Roo.Toolbar.Fill();
24749 handler : function() {
24750 _t.footDisp.scrollTo('left',0,true)
24754 this.footer.add( footDisp );
24759 handler : function() {
24761 _t.footDisp.select('span').last().scrollIntoView(_t.footDisp,true);
24765 var fel = Roo.get(footDisp.el);
24766 fel.addClass('x-editor-context');
24767 this.footDispWrap = fel;
24768 this.footDispWrap.overflow = 'hidden';
24770 this.footDisp = fel.createChild();
24771 this.footDispWrap.on('click', this.onContextClick, this)
24775 onContextClick : function (ev,dom)
24777 ev.preventDefault();
24778 var cn = dom.className;
24780 if (!cn.match(/x-ed-loc-/)) {
24783 var n = cn.split('-').pop();
24784 var ans = this.footerEls;
24788 var range = this.editorcore.createRange();
24790 range.selectNodeContents(sel);
24791 //range.selectNode(sel);
24794 var selection = this.editorcore.getSelection();
24795 selection.removeAllRanges();
24796 selection.addRange(range);
24800 this.updateToolbar(null, null, sel);
24817 * Ext JS Library 1.1.1
24818 * Copyright(c) 2006-2007, Ext JS, LLC.
24820 * Originally Released Under LGPL - original licence link has changed is not relivant.
24823 * <script type="text/javascript">
24827 * @class Roo.form.BasicForm
24828 * @extends Roo.util.Observable
24829 * Supplies the functionality to do "actions" on forms and initialize Roo.form.Field types on existing markup.
24831 * @param {String/HTMLElement/Roo.Element} el The form element or its id
24832 * @param {Object} config Configuration options
24834 Roo.form.BasicForm = function(el, config){
24835 this.allItems = [];
24836 this.childForms = [];
24837 Roo.apply(this, config);
24839 * The Roo.form.Field items in this form.
24840 * @type MixedCollection
24844 this.items = new Roo.util.MixedCollection(false, function(o){
24845 return o.id || (o.id = Roo.id());
24849 * @event beforeaction
24850 * Fires before any action is performed. Return false to cancel the action.
24851 * @param {Form} this
24852 * @param {Action} action The action to be performed
24854 beforeaction: true,
24856 * @event actionfailed
24857 * Fires when an action fails.
24858 * @param {Form} this
24859 * @param {Action} action The action that failed
24861 actionfailed : true,
24863 * @event actioncomplete
24864 * Fires when an action is completed.
24865 * @param {Form} this
24866 * @param {Action} action The action that completed
24868 actioncomplete : true
24873 Roo.form.BasicForm.superclass.constructor.call(this);
24875 Roo.form.BasicForm.popover.apply();
24878 Roo.extend(Roo.form.BasicForm, Roo.util.Observable, {
24880 * @cfg {String} method
24881 * The request method to use (GET or POST) for form actions if one isn't supplied in the action options.
24884 * @cfg {DataReader} reader
24885 * An Roo.data.DataReader (e.g. {@link Roo.data.XmlReader}) to be used to read data when executing "load" actions.
24886 * This is optional as there is built-in support for processing JSON.
24889 * @cfg {DataReader} errorReader
24890 * An Roo.data.DataReader (e.g. {@link Roo.data.XmlReader}) to be used to read data when reading validation errors on "submit" actions.
24891 * This is completely optional as there is built-in support for processing JSON.
24894 * @cfg {String} url
24895 * The URL to use for form actions if one isn't supplied in the action options.
24898 * @cfg {Boolean} fileUpload
24899 * Set to true if this form is a file upload.
24903 * @cfg {Object} baseParams
24904 * Parameters to pass with all requests. e.g. baseParams: {id: '123', foo: 'bar'}.
24909 * @cfg {Number} timeout Timeout for form actions in seconds (default is 30 seconds).
24914 activeAction : null,
24917 * @cfg {Boolean} trackResetOnLoad If set to true, form.reset() resets to the last loaded
24918 * or setValues() data instead of when the form was first created.
24920 trackResetOnLoad : false,
24924 * childForms - used for multi-tab forms
24927 childForms : false,
24930 * allItems - full list of fields.
24936 * By default wait messages are displayed with Roo.MessageBox.wait. You can target a specific
24937 * element by passing it or its id or mask the form itself by passing in true.
24940 waitMsgTarget : false,
24945 disableMask : false,
24948 * @cfg {Boolean} errorMask (true|false) default false
24953 * @cfg {Number} maskOffset Default 100
24958 initEl : function(el){
24959 this.el = Roo.get(el);
24960 this.id = this.el.id || Roo.id();
24961 this.el.on('submit', this.onSubmit, this);
24962 this.el.addClass('x-form');
24966 onSubmit : function(e){
24971 * Returns true if client-side validation on the form is successful.
24974 isValid : function(){
24976 var target = false;
24977 this.items.each(function(f){
24984 if(!target && f.el.isVisible(true)){
24989 if(this.errorMask && !valid){
24990 Roo.form.BasicForm.popover.mask(this, target);
24997 * DEPRICATED Returns true if any fields in this form have changed since their original load.
25000 isDirty : function(){
25002 this.items.each(function(f){
25012 * Returns true if any fields in this form have changed since their original load. (New version)
25016 hasChanged : function()
25019 this.items.each(function(f){
25020 if(f.hasChanged()){
25029 * Resets all hasChanged to 'false' -
25030 * The old 'isDirty' used 'original value..' however this breaks reset() and a few other things.
25031 * So hasChanged storage is only to be used for this purpose
25034 resetHasChanged : function()
25036 this.items.each(function(f){
25037 f.resetHasChanged();
25044 * Performs a predefined action (submit or load) or custom actions you define on this form.
25045 * @param {String} actionName The name of the action type
25046 * @param {Object} options (optional) The options to pass to the action. All of the config options listed
25047 * below are supported by both the submit and load actions unless otherwise noted (custom actions could also
25048 * accept other config options):
25050 Property Type Description
25051 ---------------- --------------- ----------------------------------------------------------------------------------
25052 url String The url for the action (defaults to the form's url)
25053 method String The form method to use (defaults to the form's method, or POST if not defined)
25054 params String/Object The params to pass (defaults to the form's baseParams, or none if not defined)
25055 clientValidation Boolean Applies to submit only. Pass true to call form.isValid() prior to posting to
25056 validate the form on the client (defaults to false)
25058 * @return {BasicForm} this
25060 doAction : function(action, options){
25061 if(typeof action == 'string'){
25062 action = new Roo.form.Action.ACTION_TYPES[action](this, options);
25064 if(this.fireEvent('beforeaction', this, action) !== false){
25065 this.beforeAction(action);
25066 action.run.defer(100, action);
25072 * Shortcut to do a submit action.
25073 * @param {Object} options The options to pass to the action (see {@link #doAction} for details)
25074 * @return {BasicForm} this
25076 submit : function(options){
25077 this.doAction('submit', options);
25082 * Shortcut to do a load action.
25083 * @param {Object} options The options to pass to the action (see {@link #doAction} for details)
25084 * @return {BasicForm} this
25086 load : function(options){
25087 this.doAction('load', options);
25092 * Persists the values in this form into the passed Roo.data.Record object in a beginEdit/endEdit block.
25093 * @param {Record} record The record to edit
25094 * @return {BasicForm} this
25096 updateRecord : function(record){
25097 record.beginEdit();
25098 var fs = record.fields;
25099 fs.each(function(f){
25100 var field = this.findField(f.name);
25102 record.set(f.name, field.getValue());
25110 * Loads an Roo.data.Record into this form.
25111 * @param {Record} record The record to load
25112 * @return {BasicForm} this
25114 loadRecord : function(record){
25115 this.setValues(record.data);
25120 beforeAction : function(action){
25121 var o = action.options;
25123 if(!this.disableMask) {
25124 if(this.waitMsgTarget === true){
25125 this.el.mask(o.waitMsg || "Sending", 'x-mask-loading');
25126 }else if(this.waitMsgTarget){
25127 this.waitMsgTarget = Roo.get(this.waitMsgTarget);
25128 this.waitMsgTarget.mask(o.waitMsg || "Sending", 'x-mask-loading');
25130 Roo.MessageBox.wait(o.waitMsg || "Sending", o.waitTitle || this.waitTitle || 'Please Wait...');
25138 afterAction : function(action, success){
25139 this.activeAction = null;
25140 var o = action.options;
25142 if(!this.disableMask) {
25143 if(this.waitMsgTarget === true){
25145 }else if(this.waitMsgTarget){
25146 this.waitMsgTarget.unmask();
25148 Roo.MessageBox.updateProgress(1);
25149 Roo.MessageBox.hide();
25157 Roo.callback(o.success, o.scope, [this, action]);
25158 this.fireEvent('actioncomplete', this, action);
25162 // failure condition..
25163 // we have a scenario where updates need confirming.
25164 // eg. if a locking scenario exists..
25165 // we look for { errors : { needs_confirm : true }} in the response.
25167 (typeof(action.result) != 'undefined') &&
25168 (typeof(action.result.errors) != 'undefined') &&
25169 (typeof(action.result.errors.needs_confirm) != 'undefined')
25172 Roo.MessageBox.confirm(
25173 "Change requires confirmation",
25174 action.result.errorMsg,
25179 _t.doAction('submit', { params : { _submit_confirmed : 1 } } );
25189 Roo.callback(o.failure, o.scope, [this, action]);
25190 // show an error message if no failed handler is set..
25191 if (!this.hasListener('actionfailed')) {
25192 Roo.MessageBox.alert("Error",
25193 (typeof(action.result) != 'undefined' && typeof(action.result.errorMsg) != 'undefined') ?
25194 action.result.errorMsg :
25195 "Saving Failed, please check your entries or try again"
25199 this.fireEvent('actionfailed', this, action);
25205 * Find a Roo.form.Field in this form by id, dataIndex, name or hiddenName
25206 * @param {String} id The value to search for
25209 findField : function(id){
25210 var field = this.items.get(id);
25212 this.items.each(function(f){
25213 if(f.isFormField && (f.dataIndex == id || f.id == id || f.getName() == id)){
25219 return field || null;
25223 * Add a secondary form to this one,
25224 * Used to provide tabbed forms. One form is primary, with hidden values
25225 * which mirror the elements from the other forms.
25227 * @param {Roo.form.Form} form to add.
25230 addForm : function(form)
25233 if (this.childForms.indexOf(form) > -1) {
25237 this.childForms.push(form);
25239 Roo.each(form.allItems, function (fe) {
25241 n = typeof(fe.getName) == 'undefined' ? fe.name : fe.getName();
25242 if (this.findField(n)) { // already added..
25245 var add = new Roo.form.Hidden({
25248 add.render(this.el);
25255 * Mark fields in this form invalid in bulk.
25256 * @param {Array/Object} errors Either an array in the form [{id:'fieldId', msg:'The message'},...] or an object hash of {id: msg, id2: msg2}
25257 * @return {BasicForm} this
25259 markInvalid : function(errors){
25260 if(errors instanceof Array){
25261 for(var i = 0, len = errors.length; i < len; i++){
25262 var fieldError = errors[i];
25263 var f = this.findField(fieldError.id);
25265 f.markInvalid(fieldError.msg);
25271 if(typeof errors[id] != 'function' && (field = this.findField(id))){
25272 field.markInvalid(errors[id]);
25276 Roo.each(this.childForms || [], function (f) {
25277 f.markInvalid(errors);
25284 * Set values for fields in this form in bulk.
25285 * @param {Array/Object} values Either an array in the form [{id:'fieldId', value:'foo'},...] or an object hash of {id: value, id2: value2}
25286 * @return {BasicForm} this
25288 setValues : function(values){
25289 if(values instanceof Array){ // array of objects
25290 for(var i = 0, len = values.length; i < len; i++){
25292 var f = this.findField(v.id);
25294 f.setValue(v.value);
25295 if(this.trackResetOnLoad){
25296 f.originalValue = f.getValue();
25300 }else{ // object hash
25303 if(typeof values[id] != 'function' && (field = this.findField(id))){
25305 if (field.setFromData &&
25306 field.valueField &&
25307 field.displayField &&
25308 // combos' with local stores can
25309 // be queried via setValue()
25310 // to set their value..
25311 (field.store && !field.store.isLocal)
25315 sd[field.valueField] = typeof(values[field.hiddenName]) == 'undefined' ? '' : values[field.hiddenName];
25316 sd[field.displayField] = typeof(values[field.name]) == 'undefined' ? '' : values[field.name];
25317 field.setFromData(sd);
25320 field.setValue(values[id]);
25324 if(this.trackResetOnLoad){
25325 field.originalValue = field.getValue();
25330 this.resetHasChanged();
25333 Roo.each(this.childForms || [], function (f) {
25334 f.setValues(values);
25335 f.resetHasChanged();
25342 * Returns the fields in this form as an object with key/value pairs. If multiple fields exist with the same name
25343 * they are returned as an array.
25344 * @param {Boolean} asString
25347 getValues : function(asString){
25348 if (this.childForms) {
25349 // copy values from the child forms
25350 Roo.each(this.childForms, function (f) {
25351 this.setValues(f.getValues());
25356 if (typeof(FormData) != 'undefined' && asString !== true) {
25357 var fd = (new FormData(this.el.dom)).entries();
25359 var ent = fd.next();
25360 while (!ent.done) {
25361 ret[ent.value[0]] = ent.value[1]; // not sure how this will handle duplicates..
25368 var fs = Roo.lib.Ajax.serializeForm(this.el.dom);
25369 if(asString === true){
25372 return Roo.urlDecode(fs);
25376 * Returns the fields in this form as an object with key/value pairs.
25377 * This differs from getValues as it calls getValue on each child item, rather than using dom data.
25380 getFieldValues : function(with_hidden)
25382 if (this.childForms) {
25383 // copy values from the child forms
25384 // should this call getFieldValues - probably not as we do not currently copy
25385 // hidden fields when we generate..
25386 Roo.each(this.childForms, function (f) {
25387 this.setValues(f.getValues());
25392 this.items.each(function(f){
25393 if (!f.getName()) {
25396 var v = f.getValue();
25397 if (f.inputType =='radio') {
25398 if (typeof(ret[f.getName()]) == 'undefined') {
25399 ret[f.getName()] = ''; // empty..
25402 if (!f.el.dom.checked) {
25406 v = f.el.dom.value;
25410 // not sure if this supported any more..
25411 if ((typeof(v) == 'object') && f.getRawValue) {
25412 v = f.getRawValue() ; // dates..
25414 // combo boxes where name != hiddenName...
25415 if (f.name != f.getName()) {
25416 ret[f.name] = f.getRawValue();
25418 ret[f.getName()] = v;
25425 * Clears all invalid messages in this form.
25426 * @return {BasicForm} this
25428 clearInvalid : function(){
25429 this.items.each(function(f){
25433 Roo.each(this.childForms || [], function (f) {
25442 * Resets this form.
25443 * @return {BasicForm} this
25445 reset : function(){
25446 this.items.each(function(f){
25450 Roo.each(this.childForms || [], function (f) {
25453 this.resetHasChanged();
25459 * Add Roo.form components to this form.
25460 * @param {Field} field1
25461 * @param {Field} field2 (optional)
25462 * @param {Field} etc (optional)
25463 * @return {BasicForm} this
25466 this.items.addAll(Array.prototype.slice.call(arguments, 0));
25472 * Removes a field from the items collection (does NOT remove its markup).
25473 * @param {Field} field
25474 * @return {BasicForm} this
25476 remove : function(field){
25477 this.items.remove(field);
25482 * Looks at the fields in this form, checks them for an id attribute,
25483 * and calls applyTo on the existing dom element with that id.
25484 * @return {BasicForm} this
25486 render : function(){
25487 this.items.each(function(f){
25488 if(f.isFormField && !f.rendered && document.getElementById(f.id)){ // if the element exists
25496 * Calls {@link Ext#apply} for all fields in this form with the passed object.
25497 * @param {Object} values
25498 * @return {BasicForm} this
25500 applyToFields : function(o){
25501 this.items.each(function(f){
25508 * Calls {@link Ext#applyIf} for all field in this form with the passed object.
25509 * @param {Object} values
25510 * @return {BasicForm} this
25512 applyIfToFields : function(o){
25513 this.items.each(function(f){
25521 Roo.BasicForm = Roo.form.BasicForm;
25523 Roo.apply(Roo.form.BasicForm, {
25537 intervalID : false,
25543 if(this.isApplied){
25548 top : Roo.DomHelper.append(Roo.get(document.body), { tag: "div", cls:"x-dlg-mask roo-form-top-mask" }, true),
25549 left : Roo.DomHelper.append(Roo.get(document.body), { tag: "div", cls:"x-dlg-mask roo-form-left-mask" }, true),
25550 bottom : Roo.DomHelper.append(Roo.get(document.body), { tag: "div", cls:"x-dlg-mask roo-form-bottom-mask" }, true),
25551 right : Roo.DomHelper.append(Roo.get(document.body), { tag: "div", cls:"x-dlg-mask roo-form-right-mask" }, true)
25554 this.maskEl.top.enableDisplayMode("block");
25555 this.maskEl.left.enableDisplayMode("block");
25556 this.maskEl.bottom.enableDisplayMode("block");
25557 this.maskEl.right.enableDisplayMode("block");
25559 Roo.get(document.body).on('click', function(){
25563 Roo.get(document.body).on('touchstart', function(){
25567 this.isApplied = true
25570 mask : function(form, target)
25574 this.target = target;
25576 if(!this.form.errorMask || !target.el){
25580 var scrollable = this.target.el.findScrollableParent() || this.target.el.findParent('div.x-layout-active-content', 100, true) || Roo.get(document.body);
25582 var ot = this.target.el.calcOffsetsTo(scrollable);
25584 var scrollTo = ot[1] - this.form.maskOffset;
25586 scrollTo = Math.min(scrollTo, scrollable.dom.scrollHeight);
25588 scrollable.scrollTo('top', scrollTo);
25590 var el = this.target.wrap || this.target.el;
25592 var box = el.getBox();
25594 this.maskEl.top.setStyle('position', 'absolute');
25595 this.maskEl.top.setStyle('z-index', 10000);
25596 this.maskEl.top.setSize(Roo.lib.Dom.getDocumentWidth(), box.y - this.padding);
25597 this.maskEl.top.setLeft(0);
25598 this.maskEl.top.setTop(0);
25599 this.maskEl.top.show();
25601 this.maskEl.left.setStyle('position', 'absolute');
25602 this.maskEl.left.setStyle('z-index', 10000);
25603 this.maskEl.left.setSize(box.x - this.padding, box.height + this.padding * 2);
25604 this.maskEl.left.setLeft(0);
25605 this.maskEl.left.setTop(box.y - this.padding);
25606 this.maskEl.left.show();
25608 this.maskEl.bottom.setStyle('position', 'absolute');
25609 this.maskEl.bottom.setStyle('z-index', 10000);
25610 this.maskEl.bottom.setSize(Roo.lib.Dom.getDocumentWidth(), Roo.lib.Dom.getDocumentHeight() - box.bottom - this.padding);
25611 this.maskEl.bottom.setLeft(0);
25612 this.maskEl.bottom.setTop(box.bottom + this.padding);
25613 this.maskEl.bottom.show();
25615 this.maskEl.right.setStyle('position', 'absolute');
25616 this.maskEl.right.setStyle('z-index', 10000);
25617 this.maskEl.right.setSize(Roo.lib.Dom.getDocumentWidth() - box.right - this.padding, box.height + this.padding * 2);
25618 this.maskEl.right.setLeft(box.right + this.padding);
25619 this.maskEl.right.setTop(box.y - this.padding);
25620 this.maskEl.right.show();
25622 this.intervalID = window.setInterval(function() {
25623 Roo.form.BasicForm.popover.unmask();
25626 window.onwheel = function(){ return false;};
25628 (function(){ this.isMasked = true; }).defer(500, this);
25632 unmask : function()
25634 if(!this.isApplied || !this.isMasked || !this.form || !this.target || !this.form.errorMask){
25638 this.maskEl.top.setStyle('position', 'absolute');
25639 this.maskEl.top.setSize(0, 0).setXY([0, 0]);
25640 this.maskEl.top.hide();
25642 this.maskEl.left.setStyle('position', 'absolute');
25643 this.maskEl.left.setSize(0, 0).setXY([0, 0]);
25644 this.maskEl.left.hide();
25646 this.maskEl.bottom.setStyle('position', 'absolute');
25647 this.maskEl.bottom.setSize(0, 0).setXY([0, 0]);
25648 this.maskEl.bottom.hide();
25650 this.maskEl.right.setStyle('position', 'absolute');
25651 this.maskEl.right.setSize(0, 0).setXY([0, 0]);
25652 this.maskEl.right.hide();
25654 window.onwheel = function(){ return true;};
25656 if(this.intervalID){
25657 window.clearInterval(this.intervalID);
25658 this.intervalID = false;
25661 this.isMasked = false;
25669 * Ext JS Library 1.1.1
25670 * Copyright(c) 2006-2007, Ext JS, LLC.
25672 * Originally Released Under LGPL - original licence link has changed is not relivant.
25675 * <script type="text/javascript">
25679 * @class Roo.form.Form
25680 * @extends Roo.form.BasicForm
25681 * Adds the ability to dynamically render forms with JavaScript to {@link Roo.form.BasicForm}.
25683 * @param {Object} config Configuration options
25685 Roo.form.Form = function(config){
25687 if (config.items) {
25688 xitems = config.items;
25689 delete config.items;
25693 Roo.form.Form.superclass.constructor.call(this, null, config);
25694 this.url = this.url || this.action;
25696 this.root = new Roo.form.Layout(Roo.applyIf({
25700 this.active = this.root;
25702 * Array of all the buttons that have been added to this form via {@link addButton}
25706 this.allItems = [];
25709 * @event clientvalidation
25710 * If the monitorValid config option is true, this event fires repetitively to notify of valid state
25711 * @param {Form} this
25712 * @param {Boolean} valid true if the form has passed client-side validation
25714 clientvalidation: true,
25717 * Fires when the form is rendered
25718 * @param {Roo.form.Form} form
25723 if (this.progressUrl) {
25724 // push a hidden field onto the list of fields..
25728 name : 'UPLOAD_IDENTIFIER'
25733 Roo.each(xitems, this.addxtype, this);
25737 Roo.extend(Roo.form.Form, Roo.form.BasicForm, {
25739 * @cfg {Number} labelWidth The width of labels. This property cascades to child containers.
25742 * @cfg {String} itemCls A css class to apply to the x-form-item of fields. This property cascades to child containers.
25745 * @cfg {String} buttonAlign Valid values are "left," "center" and "right" (defaults to "center")
25747 buttonAlign:'center',
25750 * @cfg {Number} minButtonWidth Minimum width of all buttons in pixels (defaults to 75)
25755 * @cfg {String} labelAlign Valid values are "left," "top" and "right" (defaults to "left").
25756 * This property cascades to child containers if not set.
25761 * @cfg {Boolean} monitorValid If true the form monitors its valid state <b>client-side</b> and
25762 * fires a looping event with that state. This is required to bind buttons to the valid
25763 * state using the config value formBind:true on the button.
25765 monitorValid : false,
25768 * @cfg {Number} monitorPoll The milliseconds to poll valid state, ignored if monitorValid is not true (defaults to 200)
25773 * @cfg {String} progressUrl - Url to return progress data
25776 progressUrl : false,
25778 * @cfg {boolean|FormData} formData - true to use new 'FormData' post, or set to a new FormData({dom form}) Object, if
25779 * sending a formdata with extra parameters - eg uploaded elements.
25785 * Opens a new {@link Roo.form.Column} container in the layout stack. If fields are passed after the config, the
25786 * fields are added and the column is closed. If no fields are passed the column remains open
25787 * until end() is called.
25788 * @param {Object} config The config to pass to the column
25789 * @param {Field} field1 (optional)
25790 * @param {Field} field2 (optional)
25791 * @param {Field} etc (optional)
25792 * @return Column The column container object
25794 column : function(c){
25795 var col = new Roo.form.Column(c);
25797 if(arguments.length > 1){ // duplicate code required because of Opera
25798 this.add.apply(this, Array.prototype.slice.call(arguments, 1));
25805 * Opens a new {@link Roo.form.FieldSet} container in the layout stack. If fields are passed after the config, the
25806 * fields are added and the fieldset is closed. If no fields are passed the fieldset remains open
25807 * until end() is called.
25808 * @param {Object} config The config to pass to the fieldset
25809 * @param {Field} field1 (optional)
25810 * @param {Field} field2 (optional)
25811 * @param {Field} etc (optional)
25812 * @return FieldSet The fieldset container object
25814 fieldset : function(c){
25815 var fs = new Roo.form.FieldSet(c);
25817 if(arguments.length > 1){ // duplicate code required because of Opera
25818 this.add.apply(this, Array.prototype.slice.call(arguments, 1));
25825 * Opens a new {@link Roo.form.Layout} container in the layout stack. If fields are passed after the config, the
25826 * fields are added and the container is closed. If no fields are passed the container remains open
25827 * until end() is called.
25828 * @param {Object} config The config to pass to the Layout
25829 * @param {Field} field1 (optional)
25830 * @param {Field} field2 (optional)
25831 * @param {Field} etc (optional)
25832 * @return Layout The container object
25834 container : function(c){
25835 var l = new Roo.form.Layout(c);
25837 if(arguments.length > 1){ // duplicate code required because of Opera
25838 this.add.apply(this, Array.prototype.slice.call(arguments, 1));
25845 * Opens the passed container in the layout stack. The container can be any {@link Roo.form.Layout} or subclass.
25846 * @param {Object} container A Roo.form.Layout or subclass of Layout
25847 * @return {Form} this
25849 start : function(c){
25850 // cascade label info
25851 Roo.applyIf(c, {'labelAlign': this.active.labelAlign, 'labelWidth': this.active.labelWidth, 'itemCls': this.active.itemCls});
25852 this.active.stack.push(c);
25853 c.ownerCt = this.active;
25859 * Closes the current open container
25860 * @return {Form} this
25863 if(this.active == this.root){
25866 this.active = this.active.ownerCt;
25871 * Add Roo.form components to the current open container (e.g. column, fieldset, etc.). Fields added via this method
25872 * can also be passed with an additional property of fieldLabel, which if supplied, will provide the text to display
25873 * as the label of the field.
25874 * @param {Field} field1
25875 * @param {Field} field2 (optional)
25876 * @param {Field} etc. (optional)
25877 * @return {Form} this
25880 this.active.stack.push.apply(this.active.stack, arguments);
25881 this.allItems.push.apply(this.allItems,arguments);
25883 for(var i = 0, a = arguments, len = a.length; i < len; i++) {
25884 if(a[i].isFormField){
25889 Roo.form.Form.superclass.add.apply(this, r);
25899 * Find any element that has been added to a form, using it's ID or name
25900 * This can include framesets, columns etc. along with regular fields..
25901 * @param {String} id - id or name to find.
25903 * @return {Element} e - or false if nothing found.
25905 findbyId : function(id)
25911 Roo.each(this.allItems, function(f){
25912 if (f.id == id || f.name == id ){
25923 * Render this form into the passed container. This should only be called once!
25924 * @param {String/HTMLElement/Element} container The element this component should be rendered into
25925 * @return {Form} this
25927 render : function(ct)
25933 var o = this.autoCreate || {
25935 method : this.method || 'POST',
25936 id : this.id || Roo.id()
25938 this.initEl(ct.createChild(o));
25940 this.root.render(this.el);
25944 this.items.each(function(f){
25945 f.render('x-form-el-'+f.id);
25948 if(this.buttons.length > 0){
25949 // tables are required to maintain order and for correct IE layout
25950 var tb = this.el.createChild({cls:'x-form-btns-ct', cn: {
25951 cls:"x-form-btns x-form-btns-"+this.buttonAlign,
25952 html:'<table cellspacing="0"><tbody><tr></tr></tbody></table><div class="x-clear"></div>'
25954 var tr = tb.getElementsByTagName('tr')[0];
25955 for(var i = 0, len = this.buttons.length; i < len; i++) {
25956 var b = this.buttons[i];
25957 var td = document.createElement('td');
25958 td.className = 'x-form-btn-td';
25959 b.render(tr.appendChild(td));
25962 if(this.monitorValid){ // initialize after render
25963 this.startMonitoring();
25965 this.fireEvent('rendered', this);
25970 * Adds a button to the footer of the form - this <b>must</b> be called before the form is rendered.
25971 * @param {String/Object} config A string becomes the button text, an object can either be a Button config
25972 * object or a valid Roo.DomHelper element config
25973 * @param {Function} handler The function called when the button is clicked
25974 * @param {Object} scope (optional) The scope of the handler function
25975 * @return {Roo.Button}
25977 addButton : function(config, handler, scope){
25981 minWidth: this.minButtonWidth,
25984 if(typeof config == "string"){
25987 Roo.apply(bc, config);
25989 var btn = new Roo.Button(null, bc);
25990 this.buttons.push(btn);
25995 * Adds a series of form elements (using the xtype property as the factory method.
25996 * Valid xtypes are: TextField, TextArea .... Button, Layout, FieldSet, Column, (and 'end' to close a block)
25997 * @param {Object} config
26000 addxtype : function()
26002 var ar = Array.prototype.slice.call(arguments, 0);
26004 for(var i = 0; i < ar.length; i++) {
26006 continue; // skip -- if this happends something invalid got sent, we
26007 // should ignore it, as basically that interface element will not show up
26008 // and that should be pretty obvious!!
26011 if (Roo.form[ar[i].xtype]) {
26013 var fe = Roo.factory(ar[i], Roo.form);
26019 fe.store.form = this;
26024 this.allItems.push(fe);
26025 if (fe.items && fe.addxtype) {
26026 fe.addxtype.apply(fe, fe.items);
26036 // console.log('adding ' + ar[i].xtype);
26038 if (ar[i].xtype == 'Button') {
26039 //console.log('adding button');
26040 //console.log(ar[i]);
26041 this.addButton(ar[i]);
26042 this.allItems.push(fe);
26046 if (ar[i].xtype == 'end') { // so we can add fieldsets... / layout etc.
26047 alert('end is not supported on xtype any more, use items');
26049 // //console.log('adding end');
26057 * Starts monitoring of the valid state of this form. Usually this is done by passing the config
26058 * option "monitorValid"
26060 startMonitoring : function(){
26063 Roo.TaskMgr.start({
26064 run : this.bindHandler,
26065 interval : this.monitorPoll || 200,
26072 * Stops monitoring of the valid state of this form
26074 stopMonitoring : function(){
26075 this.bound = false;
26079 bindHandler : function(){
26081 return false; // stops binding
26084 this.items.each(function(f){
26085 if(!f.isValid(true)){
26090 for(var i = 0, len = this.buttons.length; i < len; i++){
26091 var btn = this.buttons[i];
26092 if(btn.formBind === true && btn.disabled === valid){
26093 btn.setDisabled(!valid);
26096 this.fireEvent('clientvalidation', this, valid);
26110 Roo.Form = Roo.form.Form;
26113 * Ext JS Library 1.1.1
26114 * Copyright(c) 2006-2007, Ext JS, LLC.
26116 * Originally Released Under LGPL - original licence link has changed is not relivant.
26119 * <script type="text/javascript">
26122 // as we use this in bootstrap.
26123 Roo.namespace('Roo.form');
26125 * @class Roo.form.Action
26126 * Internal Class used to handle form actions
26128 * @param {Roo.form.BasicForm} el The form element or its id
26129 * @param {Object} config Configuration options
26134 // define the action interface
26135 Roo.form.Action = function(form, options){
26137 this.options = options || {};
26140 * Client Validation Failed
26143 Roo.form.Action.CLIENT_INVALID = 'client';
26145 * Server Validation Failed
26148 Roo.form.Action.SERVER_INVALID = 'server';
26150 * Connect to Server Failed
26153 Roo.form.Action.CONNECT_FAILURE = 'connect';
26155 * Reading Data from Server Failed
26158 Roo.form.Action.LOAD_FAILURE = 'load';
26160 Roo.form.Action.prototype = {
26162 failureType : undefined,
26163 response : undefined,
26164 result : undefined,
26166 // interface method
26167 run : function(options){
26171 // interface method
26172 success : function(response){
26176 // interface method
26177 handleResponse : function(response){
26181 // default connection failure
26182 failure : function(response){
26184 this.response = response;
26185 this.failureType = Roo.form.Action.CONNECT_FAILURE;
26186 this.form.afterAction(this, false);
26189 processResponse : function(response){
26190 this.response = response;
26191 if(!response.responseText){
26194 this.result = this.handleResponse(response);
26195 return this.result;
26198 // utility functions used internally
26199 getUrl : function(appendParams){
26200 var url = this.options.url || this.form.url || this.form.el.dom.action;
26202 var p = this.getParams();
26204 url += (url.indexOf('?') != -1 ? '&' : '?') + p;
26210 getMethod : function(){
26211 return (this.options.method || this.form.method || this.form.el.dom.method || 'POST').toUpperCase();
26214 getParams : function(){
26215 var bp = this.form.baseParams;
26216 var p = this.options.params;
26218 if(typeof p == "object"){
26219 p = Roo.urlEncode(Roo.applyIf(p, bp));
26220 }else if(typeof p == 'string' && bp){
26221 p += '&' + Roo.urlEncode(bp);
26224 p = Roo.urlEncode(bp);
26229 createCallback : function(){
26231 success: this.success,
26232 failure: this.failure,
26234 timeout: (this.form.timeout*1000),
26235 upload: this.form.fileUpload ? this.success : undefined
26240 Roo.form.Action.Submit = function(form, options){
26241 Roo.form.Action.Submit.superclass.constructor.call(this, form, options);
26244 Roo.extend(Roo.form.Action.Submit, Roo.form.Action, {
26247 haveProgress : false,
26248 uploadComplete : false,
26250 // uploadProgress indicator.
26251 uploadProgress : function()
26253 if (!this.form.progressUrl) {
26257 if (!this.haveProgress) {
26258 Roo.MessageBox.progress("Uploading", "Uploading");
26260 if (this.uploadComplete) {
26261 Roo.MessageBox.hide();
26265 this.haveProgress = true;
26267 var uid = this.form.findField('UPLOAD_IDENTIFIER').getValue();
26269 var c = new Roo.data.Connection();
26271 url : this.form.progressUrl,
26276 success : function(req){
26277 //console.log(data);
26281 rdata = Roo.decode(req.responseText)
26283 Roo.log("Invalid data from server..");
26287 if (!rdata || !rdata.success) {
26289 Roo.MessageBox.alert(Roo.encode(rdata));
26292 var data = rdata.data;
26294 if (this.uploadComplete) {
26295 Roo.MessageBox.hide();
26300 Roo.MessageBox.updateProgress(data.bytes_uploaded/data.bytes_total,
26301 Math.floor((data.bytes_total - data.bytes_uploaded)/1000) + 'k remaining'
26304 this.uploadProgress.defer(2000,this);
26307 failure: function(data) {
26308 Roo.log('progress url failed ');
26319 // run get Values on the form, so it syncs any secondary forms.
26320 this.form.getValues();
26322 var o = this.options;
26323 var method = this.getMethod();
26324 var isPost = method == 'POST';
26325 if(o.clientValidation === false || this.form.isValid()){
26327 if (this.form.progressUrl) {
26328 this.form.findField('UPLOAD_IDENTIFIER').setValue(
26329 (new Date() * 1) + '' + Math.random());
26334 Roo.Ajax.request(Roo.apply(this.createCallback(), {
26335 form:this.form.el.dom,
26336 url:this.getUrl(!isPost),
26338 params:isPost ? this.getParams() : null,
26339 isUpload: this.form.fileUpload,
26340 formData : this.form.formData
26343 this.uploadProgress();
26345 }else if (o.clientValidation !== false){ // client validation failed
26346 this.failureType = Roo.form.Action.CLIENT_INVALID;
26347 this.form.afterAction(this, false);
26351 success : function(response)
26353 this.uploadComplete= true;
26354 if (this.haveProgress) {
26355 Roo.MessageBox.hide();
26359 var result = this.processResponse(response);
26360 if(result === true || result.success){
26361 this.form.afterAction(this, true);
26365 this.form.markInvalid(result.errors);
26366 this.failureType = Roo.form.Action.SERVER_INVALID;
26368 this.form.afterAction(this, false);
26370 failure : function(response)
26372 this.uploadComplete= true;
26373 if (this.haveProgress) {
26374 Roo.MessageBox.hide();
26377 this.response = response;
26378 this.failureType = Roo.form.Action.CONNECT_FAILURE;
26379 this.form.afterAction(this, false);
26382 handleResponse : function(response){
26383 if(this.form.errorReader){
26384 var rs = this.form.errorReader.read(response);
26387 for(var i = 0, len = rs.records.length; i < len; i++) {
26388 var r = rs.records[i];
26389 errors[i] = r.data;
26392 if(errors.length < 1){
26396 success : rs.success,
26402 ret = Roo.decode(response.responseText);
26406 errorMsg: "Failed to read server message: " + (response ? response.responseText : ' - no message'),
26416 Roo.form.Action.Load = function(form, options){
26417 Roo.form.Action.Load.superclass.constructor.call(this, form, options);
26418 this.reader = this.form.reader;
26421 Roo.extend(Roo.form.Action.Load, Roo.form.Action, {
26426 Roo.Ajax.request(Roo.apply(
26427 this.createCallback(), {
26428 method:this.getMethod(),
26429 url:this.getUrl(false),
26430 params:this.getParams()
26434 success : function(response){
26436 var result = this.processResponse(response);
26437 if(result === true || !result.success || !result.data){
26438 this.failureType = Roo.form.Action.LOAD_FAILURE;
26439 this.form.afterAction(this, false);
26442 this.form.clearInvalid();
26443 this.form.setValues(result.data);
26444 this.form.afterAction(this, true);
26447 handleResponse : function(response){
26448 if(this.form.reader){
26449 var rs = this.form.reader.read(response);
26450 var data = rs.records && rs.records[0] ? rs.records[0].data : null;
26452 success : rs.success,
26456 return Roo.decode(response.responseText);
26460 Roo.form.Action.ACTION_TYPES = {
26461 'load' : Roo.form.Action.Load,
26462 'submit' : Roo.form.Action.Submit
26465 * Ext JS Library 1.1.1
26466 * Copyright(c) 2006-2007, Ext JS, LLC.
26468 * Originally Released Under LGPL - original licence link has changed is not relivant.
26471 * <script type="text/javascript">
26475 * @class Roo.form.Layout
26476 * @extends Roo.Component
26477 * Creates a container for layout and rendering of fields in an {@link Roo.form.Form}.
26479 * @param {Object} config Configuration options
26481 Roo.form.Layout = function(config){
26483 if (config.items) {
26484 xitems = config.items;
26485 delete config.items;
26487 Roo.form.Layout.superclass.constructor.call(this, config);
26489 Roo.each(xitems, this.addxtype, this);
26493 Roo.extend(Roo.form.Layout, Roo.Component, {
26495 * @cfg {String/Object} autoCreate
26496 * A DomHelper element spec used to autocreate the layout (defaults to {tag: 'div', cls: 'x-form-ct'})
26499 * @cfg {String/Object/Function} style
26500 * A style specification string, e.g. "width:100px", or object in the form {width:"100px"}, or
26501 * a function which returns such a specification.
26504 * @cfg {String} labelAlign
26505 * Valid values are "left," "top" and "right" (defaults to "left")
26508 * @cfg {Number} labelWidth
26509 * Fixed width in pixels of all field labels (defaults to undefined)
26512 * @cfg {Boolean} clear
26513 * True to add a clearing element at the end of this layout, equivalent to CSS clear: both (defaults to true)
26517 * @cfg {String} labelSeparator
26518 * The separator to use after field labels (defaults to ':')
26520 labelSeparator : ':',
26522 * @cfg {Boolean} hideLabels
26523 * True to suppress the display of field labels in this layout (defaults to false)
26525 hideLabels : false,
26528 defaultAutoCreate : {tag: 'div', cls: 'x-form-ct'},
26533 onRender : function(ct, position){
26534 if(this.el){ // from markup
26535 this.el = Roo.get(this.el);
26536 }else { // generate
26537 var cfg = this.getAutoCreate();
26538 this.el = ct.createChild(cfg, position);
26541 this.el.applyStyles(this.style);
26543 if(this.labelAlign){
26544 this.el.addClass('x-form-label-'+this.labelAlign);
26546 if(this.hideLabels){
26547 this.labelStyle = "display:none";
26548 this.elementStyle = "padding-left:0;";
26550 if(typeof this.labelWidth == 'number'){
26551 this.labelStyle = "width:"+this.labelWidth+"px;";
26552 this.elementStyle = "padding-left:"+((this.labelWidth+(typeof this.labelPad == 'number' ? this.labelPad : 5))+'px')+";";
26554 if(this.labelAlign == 'top'){
26555 this.labelStyle = "width:auto;";
26556 this.elementStyle = "padding-left:0;";
26559 var stack = this.stack;
26560 var slen = stack.length;
26562 if(!this.fieldTpl){
26563 var t = new Roo.Template(
26564 '<div class="x-form-item {5}">',
26565 '<label for="{0}" style="{2}">{1}{4}</label>',
26566 '<div class="x-form-element" id="x-form-el-{0}" style="{3}">',
26568 '</div><div class="x-form-clear-left"></div>'
26570 t.disableFormats = true;
26572 Roo.form.Layout.prototype.fieldTpl = t;
26574 for(var i = 0; i < slen; i++) {
26575 if(stack[i].isFormField){
26576 this.renderField(stack[i]);
26578 this.renderComponent(stack[i]);
26583 this.el.createChild({cls:'x-form-clear'});
26588 renderField : function(f){
26589 f.fieldEl = Roo.get(this.fieldTpl.append(this.el, [
26592 f.labelStyle||this.labelStyle||'', //2
26593 this.elementStyle||'', //3
26594 typeof f.labelSeparator == 'undefined' ? this.labelSeparator : f.labelSeparator, //4
26595 f.itemCls||this.itemCls||'' //5
26596 ], true).getPrevSibling());
26600 renderComponent : function(c){
26601 c.render(c.isLayout ? this.el : this.el.createChild());
26604 * Adds a object form elements (using the xtype property as the factory method.)
26605 * Valid xtypes are: TextField, TextArea .... Button, Layout, FieldSet, Column
26606 * @param {Object} config
26608 addxtype : function(o)
26610 // create the lement.
26611 o.form = this.form;
26612 var fe = Roo.factory(o, Roo.form);
26613 this.form.allItems.push(fe);
26614 this.stack.push(fe);
26616 if (fe.isFormField) {
26617 this.form.items.add(fe);
26625 * @class Roo.form.Column
26626 * @extends Roo.form.Layout
26627 * Creates a column container for layout and rendering of fields in an {@link Roo.form.Form}.
26629 * @param {Object} config Configuration options
26631 Roo.form.Column = function(config){
26632 Roo.form.Column.superclass.constructor.call(this, config);
26635 Roo.extend(Roo.form.Column, Roo.form.Layout, {
26637 * @cfg {Number/String} width
26638 * The fixed width of the column in pixels or CSS value (defaults to "auto")
26641 * @cfg {String/Object} autoCreate
26642 * A DomHelper element spec used to autocreate the column (defaults to {tag: 'div', cls: 'x-form-ct x-form-column'})
26646 defaultAutoCreate : {tag: 'div', cls: 'x-form-ct x-form-column'},
26649 onRender : function(ct, position){
26650 Roo.form.Column.superclass.onRender.call(this, ct, position);
26652 this.el.setWidth(this.width);
26659 * @class Roo.form.Row
26660 * @extends Roo.form.Layout
26661 * Creates a row container for layout and rendering of fields in an {@link Roo.form.Form}.
26663 * @param {Object} config Configuration options
26667 Roo.form.Row = function(config){
26668 Roo.form.Row.superclass.constructor.call(this, config);
26671 Roo.extend(Roo.form.Row, Roo.form.Layout, {
26673 * @cfg {Number/String} width
26674 * The fixed width of the column in pixels or CSS value (defaults to "auto")
26677 * @cfg {Number/String} height
26678 * The fixed height of the column in pixels or CSS value (defaults to "auto")
26680 defaultAutoCreate : {tag: 'div', cls: 'x-form-ct x-form-row'},
26684 onRender : function(ct, position){
26685 //console.log('row render');
26687 var t = new Roo.Template(
26688 '<div class="x-form-item {5}" style="float:left;width:{6}px">',
26689 '<label for="{0}" style="{2}">{1}{4}</label>',
26690 '<div class="x-form-element" id="x-form-el-{0}" style="{3}">',
26694 t.disableFormats = true;
26696 Roo.form.Layout.prototype.rowTpl = t;
26698 this.fieldTpl = this.rowTpl;
26700 //console.log('lw' + this.labelWidth +', la:' + this.labelAlign);
26701 var labelWidth = 100;
26703 if ((this.labelAlign != 'top')) {
26704 if (typeof this.labelWidth == 'number') {
26705 labelWidth = this.labelWidth
26707 this.padWidth = 20 + labelWidth;
26711 Roo.form.Column.superclass.onRender.call(this, ct, position);
26713 this.el.setWidth(this.width);
26716 this.el.setHeight(this.height);
26721 renderField : function(f){
26722 f.fieldEl = this.fieldTpl.append(this.el, [
26723 f.id, f.fieldLabel,
26724 f.labelStyle||this.labelStyle||'',
26725 this.elementStyle||'',
26726 typeof f.labelSeparator == 'undefined' ? this.labelSeparator : f.labelSeparator,
26727 f.itemCls||this.itemCls||'',
26728 f.width ? f.width + this.padWidth : 160 + this.padWidth
26735 * @class Roo.form.FieldSet
26736 * @extends Roo.form.Layout
26737 * Creates a fieldset container for layout and rendering of fields in an {@link Roo.form.Form}.
26739 * @param {Object} config Configuration options
26741 Roo.form.FieldSet = function(config){
26742 Roo.form.FieldSet.superclass.constructor.call(this, config);
26745 Roo.extend(Roo.form.FieldSet, Roo.form.Layout, {
26747 * @cfg {String} legend
26748 * The text to display as the legend for the FieldSet (defaults to '')
26751 * @cfg {String/Object} autoCreate
26752 * A DomHelper element spec used to autocreate the fieldset (defaults to {tag: 'fieldset', cn: {tag:'legend'}})
26756 defaultAutoCreate : {tag: 'fieldset', cn: {tag:'legend'}},
26759 onRender : function(ct, position){
26760 Roo.form.FieldSet.superclass.onRender.call(this, ct, position);
26762 this.setLegend(this.legend);
26767 setLegend : function(text){
26769 this.el.child('legend').update(text);
26774 * Ext JS Library 1.1.1
26775 * Copyright(c) 2006-2007, Ext JS, LLC.
26777 * Originally Released Under LGPL - original licence link has changed is not relivant.
26780 * <script type="text/javascript">
26783 * @class Roo.form.VTypes
26784 * Overridable validation definitions. The validations provided are basic and intended to be easily customizable and extended.
26787 Roo.form.VTypes = function(){
26788 // closure these in so they are only created once.
26789 var alpha = /^[a-zA-Z_]+$/;
26790 var alphanum = /^[a-zA-Z0-9_]+$/;
26791 var email = /^([\w]+)(.[\w]+)*@([\w-]+\.){1,5}([A-Za-z]){2,24}$/;
26792 var url = /(((https?)|(ftp)):\/\/([\-\w]+\.)+\w{2,3}(\/[%\-\w]+(\.\w{2,})?)*(([\w\-\.\?\\\/+@&#;`~=%!]*)(\.\w{2,})?)*\/?)/i;
26794 // All these messages and functions are configurable
26797 * The function used to validate email addresses
26798 * @param {String} value The email address
26800 'email' : function(v){
26801 return email.test(v);
26804 * The error text to display when the email validation function returns false
26807 'emailText' : 'This field should be an e-mail address in the format "user@domain.com"',
26809 * The keystroke filter mask to be applied on email input
26812 'emailMask' : /[a-z0-9_\.\-@]/i,
26815 * The function used to validate URLs
26816 * @param {String} value The URL
26818 'url' : function(v){
26819 return url.test(v);
26822 * The error text to display when the url validation function returns false
26825 'urlText' : 'This field should be a URL in the format "http:/'+'/www.domain.com"',
26828 * The function used to validate alpha values
26829 * @param {String} value The value
26831 'alpha' : function(v){
26832 return alpha.test(v);
26835 * The error text to display when the alpha validation function returns false
26838 'alphaText' : 'This field should only contain letters and _',
26840 * The keystroke filter mask to be applied on alpha input
26843 'alphaMask' : /[a-z_]/i,
26846 * The function used to validate alphanumeric values
26847 * @param {String} value The value
26849 'alphanum' : function(v){
26850 return alphanum.test(v);
26853 * The error text to display when the alphanumeric validation function returns false
26856 'alphanumText' : 'This field should only contain letters, numbers and _',
26858 * The keystroke filter mask to be applied on alphanumeric input
26861 'alphanumMask' : /[a-z0-9_]/i
26863 }();//<script type="text/javascript">
26866 * @class Roo.form.FCKeditor
26867 * @extends Roo.form.TextArea
26868 * Wrapper around the FCKEditor http://www.fckeditor.net
26870 * Creates a new FCKeditor
26871 * @param {Object} config Configuration options
26873 Roo.form.FCKeditor = function(config){
26874 Roo.form.FCKeditor.superclass.constructor.call(this, config);
26877 * @event editorinit
26878 * Fired when the editor is initialized - you can add extra handlers here..
26879 * @param {FCKeditor} this
26880 * @param {Object} the FCK object.
26887 Roo.form.FCKeditor.editors = { };
26888 Roo.extend(Roo.form.FCKeditor, Roo.form.TextArea,
26890 //defaultAutoCreate : {
26891 // tag : "textarea",style : "width:100px;height:60px;" ,autocomplete : "off"
26895 * @cfg {Object} fck options - see fck manual for details.
26900 * @cfg {Object} fck toolbar set (Basic or Default)
26902 toolbarSet : 'Basic',
26904 * @cfg {Object} fck BasePath
26906 basePath : '/fckeditor/',
26914 onRender : function(ct, position)
26917 this.defaultAutoCreate = {
26919 style:"width:300px;height:60px;",
26920 autocomplete: "new-password"
26923 Roo.form.FCKeditor.superclass.onRender.call(this, ct, position);
26926 this.textSizeEl = Roo.DomHelper.append(document.body, {tag: "pre", cls: "x-form-grow-sizer"});
26927 if(this.preventScrollbars){
26928 this.el.setStyle("overflow", "hidden");
26930 this.el.setHeight(this.growMin);
26933 //console.log('onrender' + this.getId() );
26934 Roo.form.FCKeditor.editors[this.getId()] = this;
26937 this.replaceTextarea() ;
26941 getEditor : function() {
26942 return this.fckEditor;
26945 * Sets a data value into the field and validates it. To set the value directly without validation see {@link #setRawValue}.
26946 * @param {Mixed} value The value to set
26950 setValue : function(value)
26952 //console.log('setValue: ' + value);
26954 if(typeof(value) == 'undefined') { // not sure why this is happending...
26957 Roo.form.FCKeditor.superclass.setValue.apply(this,[value]);
26959 //if(!this.el || !this.getEditor()) {
26960 // this.value = value;
26961 //this.setValue.defer(100,this,[value]);
26965 if(!this.getEditor()) {
26969 this.getEditor().SetData(value);
26976 * Returns the normalized data value (undefined or emptyText will be returned as ''). To return the raw value see {@link #getRawValue}.
26977 * @return {Mixed} value The field value
26979 getValue : function()
26982 if (this.frame && this.frame.dom.style.display == 'none') {
26983 return Roo.form.FCKeditor.superclass.getValue.call(this);
26986 if(!this.el || !this.getEditor()) {
26988 // this.getValue.defer(100,this);
26993 var value=this.getEditor().GetData();
26994 Roo.form.FCKeditor.superclass.setValue.apply(this,[value]);
26995 return Roo.form.FCKeditor.superclass.getValue.call(this);
27001 * Returns the raw data value which may or may not be a valid, defined value. To return a normalized value see {@link #getValue}.
27002 * @return {Mixed} value The field value
27004 getRawValue : function()
27006 if (this.frame && this.frame.dom.style.display == 'none') {
27007 return Roo.form.FCKeditor.superclass.getRawValue.call(this);
27010 if(!this.el || !this.getEditor()) {
27011 //this.getRawValue.defer(100,this);
27018 var value=this.getEditor().GetData();
27019 Roo.form.FCKeditor.superclass.setRawValue.apply(this,[value]);
27020 return Roo.form.FCKeditor.superclass.getRawValue.call(this);
27024 setSize : function(w,h) {
27028 //if (this.frame && this.frame.dom.style.display == 'none') {
27029 // Roo.form.FCKeditor.superclass.setSize.apply(this, [w, h]);
27032 //if(!this.el || !this.getEditor()) {
27033 // this.setSize.defer(100,this, [w,h]);
27039 Roo.form.FCKeditor.superclass.setSize.apply(this, [w, h]);
27041 this.frame.dom.setAttribute('width', w);
27042 this.frame.dom.setAttribute('height', h);
27043 this.frame.setSize(w,h);
27047 toggleSourceEdit : function(value) {
27051 this.el.dom.style.display = value ? '' : 'none';
27052 this.frame.dom.style.display = value ? 'none' : '';
27057 focus: function(tag)
27059 if (this.frame.dom.style.display == 'none') {
27060 return Roo.form.FCKeditor.superclass.focus.call(this);
27062 if(!this.el || !this.getEditor()) {
27063 this.focus.defer(100,this, [tag]);
27070 var tgs = this.getEditor().EditorDocument.getElementsByTagName(tag);
27071 this.getEditor().Focus();
27073 if (!this.getEditor().Selection.GetSelection()) {
27074 this.focus.defer(100,this, [tag]);
27079 var r = this.getEditor().EditorDocument.createRange();
27080 r.setStart(tgs[0],0);
27081 r.setEnd(tgs[0],0);
27082 this.getEditor().Selection.GetSelection().removeAllRanges();
27083 this.getEditor().Selection.GetSelection().addRange(r);
27084 this.getEditor().Focus();
27091 replaceTextarea : function()
27093 if ( document.getElementById( this.getId() + '___Frame' ) ) {
27096 //if ( !this.checkBrowser || this._isCompatibleBrowser() )
27098 // We must check the elements firstly using the Id and then the name.
27099 var oTextarea = document.getElementById( this.getId() );
27101 var colElementsByName = document.getElementsByName( this.getId() ) ;
27103 oTextarea.style.display = 'none' ;
27105 if ( oTextarea.tabIndex ) {
27106 this.TabIndex = oTextarea.tabIndex ;
27109 this._insertHtmlBefore( this._getConfigHtml(), oTextarea ) ;
27110 this._insertHtmlBefore( this._getIFrameHtml(), oTextarea ) ;
27111 this.frame = Roo.get(this.getId() + '___Frame')
27114 _getConfigHtml : function()
27118 for ( var o in this.fckconfig ) {
27119 sConfig += sConfig.length > 0 ? '&' : '';
27120 sConfig += encodeURIComponent( o ) + '=' + encodeURIComponent( this.fckconfig[o] ) ;
27123 return '<input type="hidden" id="' + this.getId() + '___Config" value="' + sConfig + '" style="display:none" />' ;
27127 _getIFrameHtml : function()
27129 var sFile = 'fckeditor.html' ;
27130 /* no idea what this is about..
27133 if ( (/fcksource=true/i).test( window.top.location.search ) )
27134 sFile = 'fckeditor.original.html' ;
27139 var sLink = this.basePath + 'editor/' + sFile + '?InstanceName=' + encodeURIComponent( this.getId() ) ;
27140 sLink += this.toolbarSet ? ( '&Toolbar=' + this.toolbarSet) : '';
27143 var html = '<iframe id="' + this.getId() +
27144 '___Frame" src="' + sLink +
27145 '" width="' + this.width +
27146 '" height="' + this.height + '"' +
27147 (this.tabIndex ? ' tabindex="' + this.tabIndex + '"' :'' ) +
27148 ' frameborder="0" scrolling="no"></iframe>' ;
27153 _insertHtmlBefore : function( html, element )
27155 if ( element.insertAdjacentHTML ) {
27157 element.insertAdjacentHTML( 'beforeBegin', html ) ;
27159 var oRange = document.createRange() ;
27160 oRange.setStartBefore( element ) ;
27161 var oFragment = oRange.createContextualFragment( html );
27162 element.parentNode.insertBefore( oFragment, element ) ;
27175 //Roo.reg('fckeditor', Roo.form.FCKeditor);
27177 function FCKeditor_OnComplete(editorInstance){
27178 var f = Roo.form.FCKeditor.editors[editorInstance.Name];
27179 f.fckEditor = editorInstance;
27180 //console.log("loaded");
27181 f.fireEvent('editorinit', f, editorInstance);
27201 //<script type="text/javascript">
27203 * @class Roo.form.GridField
27204 * @extends Roo.form.Field
27205 * Embed a grid (or editable grid into a form)
27208 * This embeds a grid in a form, the value of the field should be the json encoded array of rows
27210 * xgrid.store = Roo.data.Store
27211 * xgrid.store.proxy = Roo.data.MemoryProxy (data = [] )
27212 * xgrid.store.reader = Roo.data.JsonReader
27216 * Creates a new GridField
27217 * @param {Object} config Configuration options
27219 Roo.form.GridField = function(config){
27220 Roo.form.GridField.superclass.constructor.call(this, config);
27224 Roo.extend(Roo.form.GridField, Roo.form.Field, {
27226 * @cfg {Number} width - used to restrict width of grid..
27230 * @cfg {Number} height - used to restrict height of grid..
27234 * @cfg {Object} xgrid (xtype'd description of grid) { xtype : 'Grid', dataSource: .... }
27240 * @cfg {String/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to
27241 * {tag: "input", type: "checkbox", autocomplete: "off"})
27243 // defaultAutoCreate : { tag: 'div' },
27244 defaultAutoCreate : { tag: 'input', type: 'hidden', autocomplete: 'new-password'},
27246 * @cfg {String} addTitle Text to include for adding a title.
27250 onResize : function(){
27251 Roo.form.Field.superclass.onResize.apply(this, arguments);
27254 initEvents : function(){
27255 // Roo.form.Checkbox.superclass.initEvents.call(this);
27256 // has no events...
27261 getResizeEl : function(){
27265 getPositionEl : function(){
27270 onRender : function(ct, position){
27272 this.style = this.style || 'overflow: hidden; border:1px solid #c3daf9;';
27273 var style = this.style;
27276 Roo.form.GridField.superclass.onRender.call(this, ct, position);
27277 this.wrap = this.el.wrap({cls: ''}); // not sure why ive done thsi...
27278 this.viewEl = this.wrap.createChild({ tag: 'div' });
27280 this.viewEl.applyStyles(style);
27283 this.viewEl.setWidth(this.width);
27286 this.viewEl.setHeight(this.height);
27288 //if(this.inputValue !== undefined){
27289 //this.setValue(this.value);
27292 this.grid = new Roo.grid[this.xgrid.xtype](this.viewEl, this.xgrid);
27295 this.grid.render();
27296 this.grid.getDataSource().on('remove', this.refreshValue, this);
27297 this.grid.getDataSource().on('update', this.refreshValue, this);
27298 this.grid.on('afteredit', this.refreshValue, this);
27304 * Sets the value of the item.
27305 * @param {String} either an object or a string..
27307 setValue : function(v){
27309 v = v || []; // empty set..
27310 // this does not seem smart - it really only affects memoryproxy grids..
27311 if (this.grid && this.grid.getDataSource() && typeof(v) != 'undefined') {
27312 var ds = this.grid.getDataSource();
27313 // assumes a json reader..
27315 data[ds.reader.meta.root ] = typeof(v) == 'string' ? Roo.decode(v) : v;
27316 ds.loadData( data);
27318 // clear selection so it does not get stale.
27319 if (this.grid.sm) {
27320 this.grid.sm.clearSelections();
27323 Roo.form.GridField.superclass.setValue.call(this, v);
27324 this.refreshValue();
27325 // should load data in the grid really....
27329 refreshValue: function() {
27331 this.grid.getDataSource().each(function(r) {
27334 this.el.dom.value = Roo.encode(val);
27342 * Ext JS Library 1.1.1
27343 * Copyright(c) 2006-2007, Ext JS, LLC.
27345 * Originally Released Under LGPL - original licence link has changed is not relivant.
27348 * <script type="text/javascript">
27351 * @class Roo.form.DisplayField
27352 * @extends Roo.form.Field
27353 * A generic Field to display non-editable data.
27354 * @cfg {Boolean} closable (true|false) default false
27356 * Creates a new Display Field item.
27357 * @param {Object} config Configuration options
27359 Roo.form.DisplayField = function(config){
27360 Roo.form.DisplayField.superclass.constructor.call(this, config);
27365 * Fires after the click the close btn
27366 * @param {Roo.form.DisplayField} this
27372 Roo.extend(Roo.form.DisplayField, Roo.form.TextField, {
27373 inputType: 'hidden',
27379 * @cfg {String} focusClass The CSS class to use when the checkbox receives focus (defaults to undefined)
27381 focusClass : undefined,
27383 * @cfg {String} fieldClass The default CSS class for the checkbox (defaults to "x-form-field")
27385 fieldClass: 'x-form-field',
27388 * @cfg {Function} valueRenderer The renderer for the field (so you can reformat output). should return raw HTML
27390 valueRenderer: undefined,
27394 * @cfg {String/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to
27395 * {tag: "input", type: "checkbox", autocomplete: "off"})
27398 // defaultAutoCreate : { tag: 'input', type: 'hidden', autocomplete: 'off'},
27402 onResize : function(){
27403 Roo.form.DisplayField.superclass.onResize.apply(this, arguments);
27407 initEvents : function(){
27408 // Roo.form.Checkbox.superclass.initEvents.call(this);
27409 // has no events...
27412 this.closeEl.on('click', this.onClose, this);
27418 getResizeEl : function(){
27422 getPositionEl : function(){
27427 onRender : function(ct, position){
27429 Roo.form.DisplayField.superclass.onRender.call(this, ct, position);
27430 //if(this.inputValue !== undefined){
27431 this.wrap = this.el.wrap();
27433 this.viewEl = this.wrap.createChild({ tag: 'div', cls: 'x-form-displayfield'});
27436 this.closeEl = this.wrap.createChild({ tag: 'div', cls: 'x-dlg-close'});
27439 if (this.bodyStyle) {
27440 this.viewEl.applyStyles(this.bodyStyle);
27442 //this.viewEl.setStyle('padding', '2px');
27444 this.setValue(this.value);
27449 initValue : Roo.emptyFn,
27454 onClick : function(){
27459 * Sets the checked state of the checkbox.
27460 * @param {Boolean/String} checked True, 'true', '1', or 'on' to check the checkbox, any other value will uncheck it.
27462 setValue : function(v){
27464 var html = this.valueRenderer ? this.valueRenderer(v) : String.format('{0}', v);
27465 // this might be called before we have a dom element..
27466 if (!this.viewEl) {
27469 this.viewEl.dom.innerHTML = html;
27470 Roo.form.DisplayField.superclass.setValue.call(this, v);
27474 onClose : function(e)
27476 e.preventDefault();
27478 this.fireEvent('close', this);
27487 * @class Roo.form.DayPicker
27488 * @extends Roo.form.Field
27489 * A Day picker show [M] [T] [W] ....
27491 * Creates a new Day Picker
27492 * @param {Object} config Configuration options
27494 Roo.form.DayPicker= function(config){
27495 Roo.form.DayPicker.superclass.constructor.call(this, config);
27499 Roo.extend(Roo.form.DayPicker, Roo.form.Field, {
27501 * @cfg {String} focusClass The CSS class to use when the checkbox receives focus (defaults to undefined)
27503 focusClass : undefined,
27505 * @cfg {String} fieldClass The default CSS class for the checkbox (defaults to "x-form-field")
27507 fieldClass: "x-form-field",
27510 * @cfg {String/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to
27511 * {tag: "input", type: "checkbox", autocomplete: "off"})
27513 defaultAutoCreate : { tag: "input", type: 'hidden', autocomplete: "new-password"},
27516 actionMode : 'viewEl',
27520 inputType : 'hidden',
27523 inputElement: false, // real input element?
27524 basedOn: false, // ????
27526 isFormField: true, // not sure where this is needed!!!!
27528 onResize : function(){
27529 Roo.form.Checkbox.superclass.onResize.apply(this, arguments);
27530 if(!this.boxLabel){
27531 this.el.alignTo(this.wrap, 'c-c');
27535 initEvents : function(){
27536 Roo.form.Checkbox.superclass.initEvents.call(this);
27537 this.el.on("click", this.onClick, this);
27538 this.el.on("change", this.onClick, this);
27542 getResizeEl : function(){
27546 getPositionEl : function(){
27552 onRender : function(ct, position){
27553 Roo.form.Checkbox.superclass.onRender.call(this, ct, position);
27555 this.wrap = this.el.wrap({cls: 'x-form-daypick-item '});
27557 var r1 = '<table><tr>';
27558 var r2 = '<tr class="x-form-daypick-icons">';
27559 for (var i=0; i < 7; i++) {
27560 r1+= '<td><div>' + Date.dayNames[i].substring(0,3) + '</div></td>';
27561 r2+= '<td><img class="x-menu-item-icon" src="' + Roo.BLANK_IMAGE_URL +'"></td>';
27564 var viewEl = this.wrap.createChild( r1 + '</tr>' + r2 + '</tr></table>');
27565 viewEl.select('img').on('click', this.onClick, this);
27566 this.viewEl = viewEl;
27569 // this will not work on Chrome!!!
27570 this.el.on('DOMAttrModified', this.setFromHidden, this); //ff
27571 this.el.on('propertychange', this.setFromHidden, this); //ie
27579 initValue : Roo.emptyFn,
27582 * Returns the checked state of the checkbox.
27583 * @return {Boolean} True if checked, else false
27585 getValue : function(){
27586 return this.el.dom.value;
27591 onClick : function(e){
27592 //this.setChecked(!this.checked);
27593 Roo.get(e.target).toggleClass('x-menu-item-checked');
27594 this.refreshValue();
27595 //if(this.el.dom.checked != this.checked){
27596 // this.setValue(this.el.dom.checked);
27601 refreshValue : function()
27604 this.viewEl.select('img',true).each(function(e,i,n) {
27605 val += e.is(".x-menu-item-checked") ? String(n) : '';
27607 this.setValue(val, true);
27611 * Sets the checked state of the checkbox.
27612 * On is always based on a string comparison between inputValue and the param.
27613 * @param {Boolean/String} value - the value to set
27614 * @param {Boolean/String} suppressEvent - whether to suppress the checkchange event.
27616 setValue : function(v,suppressEvent){
27617 if (!this.el.dom) {
27620 var old = this.el.dom.value ;
27621 this.el.dom.value = v;
27622 if (suppressEvent) {
27626 // update display..
27627 this.viewEl.select('img',true).each(function(e,i,n) {
27629 var on = e.is(".x-menu-item-checked");
27630 var newv = v.indexOf(String(n)) > -1;
27632 e.toggleClass('x-menu-item-checked');
27638 this.fireEvent('change', this, v, old);
27643 // handle setting of hidden value by some other method!!?!?
27644 setFromHidden: function()
27649 //console.log("SET FROM HIDDEN");
27650 //alert('setFrom hidden');
27651 this.setValue(this.el.dom.value);
27654 onDestroy : function()
27657 Roo.get(this.viewEl).remove();
27660 Roo.form.DayPicker.superclass.onDestroy.call(this);
27664 * RooJS Library 1.1.1
27665 * Copyright(c) 2008-2011 Alan Knowles
27672 * @class Roo.form.ComboCheck
27673 * @extends Roo.form.ComboBox
27674 * A combobox for multiple select items.
27676 * FIXME - could do with a reset button..
27679 * Create a new ComboCheck
27680 * @param {Object} config Configuration options
27682 Roo.form.ComboCheck = function(config){
27683 Roo.form.ComboCheck.superclass.constructor.call(this, config);
27684 // should verify some data...
27686 // hiddenName = required..
27687 // displayField = required
27688 // valudField == required
27689 var req= [ 'hiddenName', 'displayField', 'valueField' ];
27691 Roo.each(req, function(e) {
27692 if ((typeof(_t[e]) == 'undefined' ) || !_t[e].length) {
27693 throw "Roo.form.ComboCheck : missing value for: " + e;
27700 Roo.extend(Roo.form.ComboCheck, Roo.form.ComboBox, {
27705 selectedClass: 'x-menu-item-checked',
27708 onRender : function(ct, position){
27714 var cls = 'x-combo-list';
27717 this.tpl = new Roo.Template({
27718 html : '<div class="'+cls+'-item x-menu-check-item">' +
27719 '<img class="x-menu-item-icon" style="margin: 0px;" src="' + Roo.BLANK_IMAGE_URL + '">' +
27720 '<span>{' + this.displayField + '}</span>' +
27727 Roo.form.ComboCheck.superclass.onRender.call(this, ct, position);
27728 this.view.singleSelect = false;
27729 this.view.multiSelect = true;
27730 this.view.toggleSelect = true;
27731 this.pageTb.add(new Roo.Toolbar.Fill(), {
27734 handler: function()
27741 onViewOver : function(e, t){
27747 onViewClick : function(doFocus,index){
27751 select: function () {
27752 //Roo.log("SELECT CALLED");
27755 selectByValue : function(xv, scrollIntoView){
27756 var ar = this.getValueArray();
27759 Roo.each(ar, function(v) {
27760 if(v === undefined || v === null){
27763 var r = this.findRecord(this.valueField, v);
27765 sels.push(this.store.indexOf(r))
27769 this.view.select(sels);
27775 onSelect : function(record, index){
27776 // Roo.log("onselect Called");
27777 // this is only called by the clear button now..
27778 this.view.clearSelections();
27779 this.setValue('[]');
27780 if (this.value != this.valueBefore) {
27781 this.fireEvent('change', this, this.value, this.valueBefore);
27782 this.valueBefore = this.value;
27785 getValueArray : function()
27790 //Roo.log(this.value);
27791 if (typeof(this.value) == 'undefined') {
27794 var ar = Roo.decode(this.value);
27795 return ar instanceof Array ? ar : []; //?? valid?
27798 Roo.log(e + "\nRoo.form.ComboCheck:getValueArray invalid data:" + this.getValue());
27803 expand : function ()
27806 Roo.form.ComboCheck.superclass.expand.call(this);
27807 this.valueBefore = typeof(this.value) == 'undefined' ? '' : this.value;
27808 //this.valueBefore = typeof(this.valueBefore) == 'undefined' ? '' : this.valueBefore;
27813 collapse : function(){
27814 Roo.form.ComboCheck.superclass.collapse.call(this);
27815 var sl = this.view.getSelectedIndexes();
27816 var st = this.store;
27820 Roo.each(sl, function(i) {
27822 nv.push(r.get(this.valueField));
27824 this.setValue(Roo.encode(nv));
27825 if (this.value != this.valueBefore) {
27827 this.fireEvent('change', this, this.value, this.valueBefore);
27828 this.valueBefore = this.value;
27833 setValue : function(v){
27837 var vals = this.getValueArray();
27839 Roo.each(vals, function(k) {
27840 var r = this.findRecord(this.valueField, k);
27842 tv.push(r.data[this.displayField]);
27843 }else if(this.valueNotFoundText !== undefined){
27844 tv.push( this.valueNotFoundText );
27849 Roo.form.ComboBox.superclass.setValue.call(this, tv.join(', '));
27850 this.hiddenField.value = v;
27856 * Ext JS Library 1.1.1
27857 * Copyright(c) 2006-2007, Ext JS, LLC.
27859 * Originally Released Under LGPL - original licence link has changed is not relivant.
27862 * <script type="text/javascript">
27866 * @class Roo.form.Signature
27867 * @extends Roo.form.Field
27871 * @param {Object} config Configuration options
27874 Roo.form.Signature = function(config){
27875 Roo.form.Signature.superclass.constructor.call(this, config);
27877 this.addEvents({// not in used??
27880 * Fires when the 'confirm' icon is pressed (add a listener to enable add button)
27881 * @param {Roo.form.Signature} combo This combo box
27886 * Fires when the 'edit' icon is pressed (add a listener to enable add button)
27887 * @param {Roo.form.ComboBox} combo This combo box
27888 * @param {Roo.data.Record|false} record The data record returned from the underlying store (or false on nothing selected)
27894 Roo.extend(Roo.form.Signature, Roo.form.Field, {
27896 * @cfg {Object} labels Label to use when rendering a form.
27900 * confirm : "Confirm"
27905 confirm : "Confirm"
27908 * @cfg {Number} width The signature panel width (defaults to 300)
27912 * @cfg {Number} height The signature panel height (defaults to 100)
27916 * @cfg {Boolean} allowBlank False to validate that the value length > 0 (defaults to false)
27918 allowBlank : false,
27921 // {Object} signPanel The signature SVG panel element (defaults to {})
27923 // {Boolean} isMouseDown False to validate that the mouse down event (defaults to false)
27924 isMouseDown : false,
27925 // {Boolean} isConfirmed validate the signature is confirmed or not for submitting form (defaults to false)
27926 isConfirmed : false,
27927 // {String} signatureTmp SVG mapping string (defaults to empty string)
27931 defaultAutoCreate : { // modified by initCompnoent..
27937 onRender : function(ct, position){
27939 Roo.form.Signature.superclass.onRender.call(this, ct, position);
27941 this.wrap = this.el.wrap({
27942 cls:'x-form-signature-wrap', style : 'width: ' + this.width + 'px', cn:{cls:'x-form-signature'}
27945 this.createToolbar(this);
27946 this.signPanel = this.wrap.createChild({
27948 style: 'width: ' + this.width + 'px; height: ' + this.height + 'px; border: 0;'
27952 this.svgID = Roo.id();
27953 this.svgEl = this.signPanel.createChild({
27954 xmlns : 'http://www.w3.org/2000/svg',
27956 id : this.svgID + "-svg",
27958 height: this.height,
27959 viewBox: '0 0 '+this.width+' '+this.height,
27963 id: this.svgID + "-svg-r",
27965 height: this.height,
27970 id: this.svgID + "-svg-l",
27972 y1: (this.height*0.8), // start set the line in 80% of height
27973 x2: this.width, // end
27974 y2: (this.height*0.8), // end set the line in 80% of height
27976 'stroke-width': "1",
27977 'stroke-dasharray': "3",
27978 'shape-rendering': "crispEdges",
27979 'pointer-events': "none"
27983 id: this.svgID + "-svg-p",
27985 'stroke-width': "3",
27987 'pointer-events': 'none'
27992 this.svgBox = this.svgEl.dom.getScreenCTM();
27994 createSVG : function(){
27995 var svg = this.signPanel;
27996 var r = svg.select('#'+ this.svgID + '-svg-r', true).first().dom;
27999 r.addEventListener('mousedown', function(e) { return t.down(e); }, false);
28000 r.addEventListener('mousemove', function(e) { return t.move(e); }, false);
28001 r.addEventListener('mouseup', function(e) { return t.up(e); }, false);
28002 r.addEventListener('mouseout', function(e) { return t.up(e); }, false);
28003 r.addEventListener('touchstart', function(e) { return t.down(e); }, false);
28004 r.addEventListener('touchmove', function(e) { return t.move(e); }, false);
28005 r.addEventListener('touchend', function(e) { return t.up(e); }, false);
28008 isTouchEvent : function(e){
28009 return e.type.match(/^touch/);
28011 getCoords : function (e) {
28012 var pt = this.svgEl.dom.createSVGPoint();
28015 if (this.isTouchEvent(e)) {
28016 pt.x = e.targetTouches[0].clientX;
28017 pt.y = e.targetTouches[0].clientY;
28019 var a = this.svgEl.dom.getScreenCTM();
28020 var b = a.inverse();
28021 var mx = pt.matrixTransform(b);
28022 return mx.x + ',' + mx.y;
28024 //mouse event headler
28025 down : function (e) {
28026 this.signatureTmp += 'M' + this.getCoords(e) + ' ';
28027 this.signPanel.select('#'+ this.svgID + '-svg-p', true).first().attr('d', this.signatureTmp);
28029 this.isMouseDown = true;
28031 e.preventDefault();
28033 move : function (e) {
28034 if (this.isMouseDown) {
28035 this.signatureTmp += 'L' + this.getCoords(e) + ' ';
28036 this.signPanel.select('#'+ this.svgID + '-svg-p', true).first().attr( 'd', this.signatureTmp);
28039 e.preventDefault();
28041 up : function (e) {
28042 this.isMouseDown = false;
28043 var sp = this.signatureTmp.split(' ');
28046 if(!sp[sp.length-2].match(/^L/)){
28050 this.signatureTmp = sp.join(" ");
28053 if(this.getValue() != this.signatureTmp){
28054 this.signPanel.select('#'+ this.svgID + '-svg-r', true).first().attr('fill', '#ffa');
28055 this.isConfirmed = false;
28057 e.preventDefault();
28061 * Protected method that will not generally be called directly. It
28062 * is called when the editor creates its toolbar. Override this method if you need to
28063 * add custom toolbar buttons.
28064 * @param {HtmlEditor} editor
28066 createToolbar : function(editor){
28067 function btn(id, toggle, handler){
28068 var xid = fid + '-'+ id ;
28072 cls : 'x-btn-icon x-edit-'+id,
28073 enableToggle:toggle !== false,
28074 scope: editor, // was editor...
28075 handler:handler||editor.relayBtnCmd,
28076 clickEvent:'mousedown',
28077 tooltip: etb.buttonTips[id] || undefined, ///tips ???
28083 var tb = new Roo.Toolbar(editor.wrap.dom.firstChild);
28087 cls : ' x-signature-btn x-signature-'+id,
28088 scope: editor, // was editor...
28089 handler: this.reset,
28090 clickEvent:'mousedown',
28091 text: this.labels.clear
28098 cls : ' x-signature-btn x-signature-'+id,
28099 scope: editor, // was editor...
28100 handler: this.confirmHandler,
28101 clickEvent:'mousedown',
28102 text: this.labels.confirm
28109 * when user is clicked confirm then show this image.....
28111 * @return {String} Image Data URI
28113 getImageDataURI : function(){
28114 var svg = this.svgEl.dom.parentNode.innerHTML;
28115 var src = 'data:image/svg+xml;base64,'+window.btoa(svg);
28120 * @return {Boolean} this.isConfirmed
28122 getConfirmed : function(){
28123 return this.isConfirmed;
28127 * @return {Number} this.width
28129 getWidth : function(){
28134 * @return {Number} this.height
28136 getHeight : function(){
28137 return this.height;
28140 getSignature : function(){
28141 return this.signatureTmp;
28144 reset : function(){
28145 this.signatureTmp = '';
28146 this.signPanel.select('#'+ this.svgID + '-svg-r', true).first().attr('fill', '#ffa');
28147 this.signPanel.select('#'+ this.svgID + '-svg-p', true).first().attr( 'd', '');
28148 this.isConfirmed = false;
28149 Roo.form.Signature.superclass.reset.call(this);
28151 setSignature : function(s){
28152 this.signatureTmp = s;
28153 this.signPanel.select('#'+ this.svgID + '-svg-r', true).first().attr('fill', '#ffa');
28154 this.signPanel.select('#'+ this.svgID + '-svg-p', true).first().attr( 'd', s);
28156 this.isConfirmed = false;
28157 Roo.form.Signature.superclass.reset.call(this);
28160 // Roo.log(this.signPanel.dom.contentWindow.up())
28163 setConfirmed : function(){
28167 // Roo.log(Roo.get(this.signPanel.dom.contentWindow.r).attr('fill', '#cfc'));
28170 confirmHandler : function(){
28171 if(!this.getSignature()){
28175 this.signPanel.select('#'+ this.svgID + '-svg-r', true).first().attr('fill', '#cfc');
28176 this.setValue(this.getSignature());
28177 this.isConfirmed = true;
28179 this.fireEvent('confirm', this);
28182 // Subclasses should provide the validation implementation by overriding this
28183 validateValue : function(value){
28184 if(this.allowBlank){
28188 if(this.isConfirmed){
28195 * Ext JS Library 1.1.1
28196 * Copyright(c) 2006-2007, Ext JS, LLC.
28198 * Originally Released Under LGPL - original licence link has changed is not relivant.
28201 * <script type="text/javascript">
28206 * @class Roo.form.ComboBox
28207 * @extends Roo.form.TriggerField
28208 * A combobox control with support for autocomplete, remote-loading, paging and many other features.
28210 * Create a new ComboBox.
28211 * @param {Object} config Configuration options
28213 Roo.form.Select = function(config){
28214 Roo.form.Select.superclass.constructor.call(this, config);
28218 Roo.extend(Roo.form.Select , Roo.form.ComboBox, {
28220 * @cfg {String/HTMLElement/Element} transform The id, DOM node or element of an existing select to convert to a ComboBox
28223 * @cfg {Boolean} lazyRender True to prevent the ComboBox from rendering until requested (should always be used when
28224 * rendering into an Roo.Editor, defaults to false)
28227 * @cfg {Boolean/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to:
28228 * {tag: "input", type: "text", size: "24", autocomplete: "off"})
28231 * @cfg {Roo.data.Store} store The data store to which this combo is bound (defaults to undefined)
28234 * @cfg {String} title If supplied, a header element is created containing this text and added into the top of
28235 * the dropdown list (defaults to undefined, with no header element)
28239 * @cfg {String/Roo.Template} tpl The template to use to render the output
28243 defaultAutoCreate : {tag: "select" },
28245 * @cfg {Number} listWidth The width in pixels of the dropdown list (defaults to the width of the ComboBox field)
28247 listWidth: undefined,
28249 * @cfg {String} displayField The underlying data field name to bind to this CombBox (defaults to undefined if
28250 * mode = 'remote' or 'text' if mode = 'local')
28252 displayField: undefined,
28254 * @cfg {String} valueField The underlying data value name to bind to this CombBox (defaults to undefined if
28255 * mode = 'remote' or 'value' if mode = 'local').
28256 * Note: use of a valueField requires the user make a selection
28257 * in order for a value to be mapped.
28259 valueField: undefined,
28263 * @cfg {String} hiddenName If specified, a hidden form field with this name is dynamically generated to store the
28264 * field's data value (defaults to the underlying DOM element's name)
28266 hiddenName: undefined,
28268 * @cfg {String} listClass CSS class to apply to the dropdown list element (defaults to '')
28272 * @cfg {String} selectedClass CSS class to apply to the selected item in the dropdown list (defaults to 'x-combo-selected')
28274 selectedClass: 'x-combo-selected',
28276 * @cfg {String} triggerClass An additional CSS class used to style the trigger button. The trigger will always get the
28277 * class 'x-form-trigger' and triggerClass will be <b>appended</b> if specified (defaults to 'x-form-arrow-trigger'
28278 * which displays a downward arrow icon).
28280 triggerClass : 'x-form-arrow-trigger',
28282 * @cfg {Boolean/String} shadow True or "sides" for the default effect, "frame" for 4-way shadow, and "drop" for bottom-right
28286 * @cfg {String} listAlign A valid anchor position value. See {@link Roo.Element#alignTo} for details on supported
28287 * anchor positions (defaults to 'tl-bl')
28289 listAlign: 'tl-bl?',
28291 * @cfg {Number} maxHeight The maximum height in pixels of the dropdown list before scrollbars are shown (defaults to 300)
28295 * @cfg {String} triggerAction The action to execute when the trigger field is activated. Use 'all' to run the
28296 * query specified by the allQuery config option (defaults to 'query')
28298 triggerAction: 'query',
28300 * @cfg {Number} minChars The minimum number of characters the user must type before autocomplete and typeahead activate
28301 * (defaults to 4, does not apply if editable = false)
28305 * @cfg {Boolean} typeAhead True to populate and autoselect the remainder of the text being typed after a configurable
28306 * delay (typeAheadDelay) if it matches a known value (defaults to false)
28310 * @cfg {Number} queryDelay The length of time in milliseconds to delay between the start of typing and sending the
28311 * query to filter the dropdown list (defaults to 500 if mode = 'remote' or 10 if mode = 'local')
28315 * @cfg {Number} pageSize If greater than 0, a paging toolbar is displayed in the footer of the dropdown list and the
28316 * filter queries will execute with page start and limit parameters. Only applies when mode = 'remote' (defaults to 0)
28320 * @cfg {Boolean} selectOnFocus True to select any existing text in the field immediately on focus. Only applies
28321 * when editable = true (defaults to false)
28323 selectOnFocus:false,
28325 * @cfg {String} queryParam Name of the query as it will be passed on the querystring (defaults to 'query')
28327 queryParam: 'query',
28329 * @cfg {String} loadingText The text to display in the dropdown list while data is loading. Only applies
28330 * when mode = 'remote' (defaults to 'Loading...')
28332 loadingText: 'Loading...',
28334 * @cfg {Boolean} resizable True to add a resize handle to the bottom of the dropdown list (defaults to false)
28338 * @cfg {Number} handleHeight The height in pixels of the dropdown list resize handle if resizable = true (defaults to 8)
28342 * @cfg {Boolean} editable False to prevent the user from typing text directly into the field, just like a
28343 * traditional select (defaults to true)
28347 * @cfg {String} allQuery The text query to send to the server to return all records for the list with no filtering (defaults to '')
28351 * @cfg {String} mode Set to 'local' if the ComboBox loads local data (defaults to 'remote' which loads from the server)
28355 * @cfg {Number} minListWidth The minimum width of the dropdown list in pixels (defaults to 70, will be ignored if
28356 * listWidth has a higher value)
28360 * @cfg {Boolean} forceSelection True to restrict the selected value to one of the values in the list, false to
28361 * allow the user to set arbitrary text into the field (defaults to false)
28363 forceSelection:false,
28365 * @cfg {Number} typeAheadDelay The length of time in milliseconds to wait until the typeahead text is displayed
28366 * if typeAhead = true (defaults to 250)
28368 typeAheadDelay : 250,
28370 * @cfg {String} valueNotFoundText When using a name/value combo, if the value passed to setValue is not found in
28371 * the store, valueNotFoundText will be displayed as the field text if defined (defaults to undefined)
28373 valueNotFoundText : undefined,
28376 * @cfg {String} defaultValue The value displayed after loading the store.
28381 * @cfg {Boolean} blockFocus Prevents all focus calls, so it can work with things like HTML edtor bar
28383 blockFocus : false,
28386 * @cfg {Boolean} disableClear Disable showing of clear button.
28388 disableClear : false,
28390 * @cfg {Boolean} alwaysQuery Disable caching of results, and always send query
28392 alwaysQuery : false,
28398 // element that contains real text value.. (when hidden is used..)
28401 onRender : function(ct, position){
28402 Roo.form.Field.prototype.onRender.call(this, ct, position);
28405 this.store.on('beforeload', this.onBeforeLoad, this);
28406 this.store.on('load', this.onLoad, this);
28407 this.store.on('loadexception', this.onLoadException, this);
28408 this.store.load({});
28416 initEvents : function(){
28417 //Roo.form.ComboBox.superclass.initEvents.call(this);
28421 onDestroy : function(){
28424 this.store.un('beforeload', this.onBeforeLoad, this);
28425 this.store.un('load', this.onLoad, this);
28426 this.store.un('loadexception', this.onLoadException, this);
28428 //Roo.form.ComboBox.superclass.onDestroy.call(this);
28432 fireKey : function(e){
28433 if(e.isNavKeyPress() && !this.list.isVisible()){
28434 this.fireEvent("specialkey", this, e);
28439 onResize: function(w, h){
28447 * Allow or prevent the user from directly editing the field text. If false is passed,
28448 * the user will only be able to select from the items defined in the dropdown list. This method
28449 * is the runtime equivalent of setting the 'editable' config option at config time.
28450 * @param {Boolean} value True to allow the user to directly edit the field text
28452 setEditable : function(value){
28457 onBeforeLoad : function(){
28459 Roo.log("Select before load");
28462 this.innerList.update(this.loadingText ?
28463 '<div class="loading-indicator">'+this.loadingText+'</div>' : '');
28464 //this.restrictHeight();
28465 this.selectedIndex = -1;
28469 onLoad : function(){
28472 var dom = this.el.dom;
28473 dom.innerHTML = '';
28474 var od = dom.ownerDocument;
28476 if (this.emptyText) {
28477 var op = od.createElement('option');
28478 op.setAttribute('value', '');
28479 op.innerHTML = String.format('{0}', this.emptyText);
28480 dom.appendChild(op);
28482 if(this.store.getCount() > 0){
28484 var vf = this.valueField;
28485 var df = this.displayField;
28486 this.store.data.each(function(r) {
28487 // which colmsn to use... testing - cdoe / title..
28488 var op = od.createElement('option');
28489 op.setAttribute('value', r.data[vf]);
28490 op.innerHTML = String.format('{0}', r.data[df]);
28491 dom.appendChild(op);
28493 if (typeof(this.defaultValue != 'undefined')) {
28494 this.setValue(this.defaultValue);
28499 //this.onEmptyResults();
28504 onLoadException : function()
28506 dom.innerHTML = '';
28508 Roo.log("Select on load exception");
28512 Roo.log(this.store.reader.jsonData);
28513 if (this.store && typeof(this.store.reader.jsonData.errorMsg) != 'undefined') {
28514 Roo.MessageBox.alert("Error loading",this.store.reader.jsonData.errorMsg);
28520 onTypeAhead : function(){
28525 onSelect : function(record, index){
28526 Roo.log('on select?');
28528 if(this.fireEvent('beforeselect', this, record, index) !== false){
28529 this.setFromData(index > -1 ? record.data : false);
28531 this.fireEvent('select', this, record, index);
28536 * Returns the currently selected field value or empty string if no value is set.
28537 * @return {String} value The selected value
28539 getValue : function(){
28540 var dom = this.el.dom;
28541 this.value = dom.options[dom.selectedIndex].value;
28547 * Clears any text/value currently set in the field
28549 clearValue : function(){
28551 this.el.dom.selectedIndex = this.emptyText ? 0 : -1;
28556 * Sets the specified value into the field. If the value finds a match, the corresponding record text
28557 * will be displayed in the field. If the value does not match the data value of an existing item,
28558 * and the valueNotFoundText config option is defined, it will be displayed as the default field text.
28559 * Otherwise the field will be blank (although the value will still be set).
28560 * @param {String} value The value to match
28562 setValue : function(v){
28563 var d = this.el.dom;
28564 for (var i =0; i < d.options.length;i++) {
28565 if (v == d.options[i].value) {
28566 d.selectedIndex = i;
28574 * @property {Object} the last set data for the element
28579 * Sets the value of the field based on a object which is related to the record format for the store.
28580 * @param {Object} value the value to set as. or false on reset?
28582 setFromData : function(o){
28583 Roo.log('setfrom data?');
28589 reset : function(){
28593 findRecord : function(prop, value){
28598 if(this.store.getCount() > 0){
28599 this.store.each(function(r){
28600 if(r.data[prop] == value){
28610 getName: function()
28612 // returns hidden if it's set..
28613 if (!this.rendered) {return ''};
28614 return !this.hiddenName && this.el.dom.name ? this.el.dom.name : (this.hiddenName || '');
28622 onEmptyResults : function(){
28623 Roo.log('empty results');
28628 * Returns true if the dropdown list is expanded, else false.
28630 isExpanded : function(){
28635 * Select an item in the dropdown list by its data value. This function does NOT cause the select event to fire.
28636 * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
28637 * @param {String} value The data value of the item to select
28638 * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
28639 * selected item if it is not currently in view (defaults to true)
28640 * @return {Boolean} True if the value matched an item in the list, else false
28642 selectByValue : function(v, scrollIntoView){
28643 Roo.log('select By Value');
28646 if(v !== undefined && v !== null){
28647 var r = this.findRecord(this.valueField || this.displayField, v);
28649 this.select(this.store.indexOf(r), scrollIntoView);
28657 * Select an item in the dropdown list by its numeric index in the list. This function does NOT cause the select event to fire.
28658 * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
28659 * @param {Number} index The zero-based index of the list item to select
28660 * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
28661 * selected item if it is not currently in view (defaults to true)
28663 select : function(index, scrollIntoView){
28664 Roo.log('select ');
28667 this.selectedIndex = index;
28668 this.view.select(index);
28669 if(scrollIntoView !== false){
28670 var el = this.view.getNode(index);
28672 this.innerList.scrollChildIntoView(el, false);
28680 validateBlur : function(){
28687 initQuery : function(){
28688 this.doQuery(this.getRawValue());
28692 doForce : function(){
28693 if(this.el.dom.value.length > 0){
28694 this.el.dom.value =
28695 this.lastSelectionText === undefined ? '' : this.lastSelectionText;
28701 * Execute a query to filter the dropdown list. Fires the beforequery event prior to performing the
28702 * query allowing the query action to be canceled if needed.
28703 * @param {String} query The SQL query to execute
28704 * @param {Boolean} forceAll True to force the query to execute even if there are currently fewer characters
28705 * in the field than the minimum specified by the minChars config option. It also clears any filter previously
28706 * saved in the current store (defaults to false)
28708 doQuery : function(q, forceAll){
28710 Roo.log('doQuery?');
28711 if(q === undefined || q === null){
28716 forceAll: forceAll,
28720 if(this.fireEvent('beforequery', qe)===false || qe.cancel){
28724 forceAll = qe.forceAll;
28725 if(forceAll === true || (q.length >= this.minChars)){
28726 if(this.lastQuery != q || this.alwaysQuery){
28727 this.lastQuery = q;
28728 if(this.mode == 'local'){
28729 this.selectedIndex = -1;
28731 this.store.clearFilter();
28733 this.store.filter(this.displayField, q);
28737 this.store.baseParams[this.queryParam] = q;
28739 params: this.getParams(q)
28744 this.selectedIndex = -1;
28751 getParams : function(q){
28753 //p[this.queryParam] = q;
28756 p.limit = this.pageSize;
28762 * Hides the dropdown list if it is currently expanded. Fires the 'collapse' event on completion.
28764 collapse : function(){
28769 collapseIf : function(e){
28774 * Expands the dropdown list if it is currently hidden. Fires the 'expand' event on completion.
28776 expand : function(){
28784 * @cfg {Boolean} grow
28788 * @cfg {Number} growMin
28792 * @cfg {Number} growMax
28800 setWidth : function()
28804 getResizeEl : function(){
28807 });//<script type="text/javasscript">
28811 * @class Roo.DDView
28812 * A DnD enabled version of Roo.View.
28813 * @param {Element/String} container The Element in which to create the View.
28814 * @param {String} tpl The template string used to create the markup for each element of the View
28815 * @param {Object} config The configuration properties. These include all the config options of
28816 * {@link Roo.View} plus some specific to this class.<br>
28818 * Drag/drop is implemented by adding {@link Roo.data.Record}s to the target DDView. If copying is
28819 * not being performed, the original {@link Roo.data.Record} is removed from the source DDView.<br>
28821 * The following extra CSS rules are needed to provide insertion point highlighting:<pre><code>
28822 .x-view-drag-insert-above {
28823 border-top:1px dotted #3366cc;
28825 .x-view-drag-insert-below {
28826 border-bottom:1px dotted #3366cc;
28832 Roo.DDView = function(container, tpl, config) {
28833 Roo.DDView.superclass.constructor.apply(this, arguments);
28834 this.getEl().setStyle("outline", "0px none");
28835 this.getEl().unselectable();
28836 if (this.dragGroup) {
28837 this.setDraggable(this.dragGroup.split(","));
28839 if (this.dropGroup) {
28840 this.setDroppable(this.dropGroup.split(","));
28842 if (this.deletable) {
28843 this.setDeletable();
28845 this.isDirtyFlag = false;
28851 Roo.extend(Roo.DDView, Roo.View, {
28852 /** @cfg {String/Array} dragGroup The ddgroup name(s) for the View's DragZone. */
28853 /** @cfg {String/Array} dropGroup The ddgroup name(s) for the View's DropZone. */
28854 /** @cfg {Boolean} copy Causes drag operations to copy nodes rather than move. */
28855 /** @cfg {Boolean} allowCopy Causes ctrl/drag operations to copy nodes rather than move. */
28859 reset: Roo.emptyFn,
28861 clearInvalid: Roo.form.Field.prototype.clearInvalid,
28863 validate: function() {
28867 destroy: function() {
28868 this.purgeListeners();
28869 this.getEl.removeAllListeners();
28870 this.getEl().remove();
28871 if (this.dragZone) {
28872 if (this.dragZone.destroy) {
28873 this.dragZone.destroy();
28876 if (this.dropZone) {
28877 if (this.dropZone.destroy) {
28878 this.dropZone.destroy();
28883 /** Allows this class to be an Roo.form.Field so it can be found using {@link Roo.form.BasicForm#findField}. */
28884 getName: function() {
28888 /** Loads the View from a JSON string representing the Records to put into the Store. */
28889 setValue: function(v) {
28891 throw "DDView.setValue(). DDView must be constructed with a valid Store";
28894 data[this.store.reader.meta.root] = v ? [].concat(v) : [];
28895 this.store.proxy = new Roo.data.MemoryProxy(data);
28899 /** @return {String} a parenthesised list of the ids of the Records in the View. */
28900 getValue: function() {
28902 this.store.each(function(rec) {
28903 result += rec.id + ',';
28905 return result.substr(0, result.length - 1) + ')';
28908 getIds: function() {
28909 var i = 0, result = new Array(this.store.getCount());
28910 this.store.each(function(rec) {
28911 result[i++] = rec.id;
28916 isDirty: function() {
28917 return this.isDirtyFlag;
28921 * Part of the Roo.dd.DropZone interface. If no target node is found, the
28922 * whole Element becomes the target, and this causes the drop gesture to append.
28924 getTargetFromEvent : function(e) {
28925 var target = e.getTarget();
28926 while ((target !== null) && (target.parentNode != this.el.dom)) {
28927 target = target.parentNode;
28930 target = this.el.dom.lastChild || this.el.dom;
28936 * Create the drag data which consists of an object which has the property "ddel" as
28937 * the drag proxy element.
28939 getDragData : function(e) {
28940 var target = this.findItemFromChild(e.getTarget());
28942 this.handleSelection(e);
28943 var selNodes = this.getSelectedNodes();
28946 copy: this.copy || (this.allowCopy && e.ctrlKey),
28950 var selectedIndices = this.getSelectedIndexes();
28951 for (var i = 0; i < selectedIndices.length; i++) {
28952 dragData.records.push(this.store.getAt(selectedIndices[i]));
28954 if (selNodes.length == 1) {
28955 dragData.ddel = target.cloneNode(true); // the div element
28957 var div = document.createElement('div'); // create the multi element drag "ghost"
28958 div.className = 'multi-proxy';
28959 for (var i = 0, len = selNodes.length; i < len; i++) {
28960 div.appendChild(selNodes[i].cloneNode(true));
28962 dragData.ddel = div;
28964 //console.log(dragData)
28965 //console.log(dragData.ddel.innerHTML)
28968 //console.log('nodragData')
28972 /** Specify to which ddGroup items in this DDView may be dragged. */
28973 setDraggable: function(ddGroup) {
28974 if (ddGroup instanceof Array) {
28975 Roo.each(ddGroup, this.setDraggable, this);
28978 if (this.dragZone) {
28979 this.dragZone.addToGroup(ddGroup);
28981 this.dragZone = new Roo.dd.DragZone(this.getEl(), {
28982 containerScroll: true,
28986 // Draggability implies selection. DragZone's mousedown selects the element.
28987 if (!this.multiSelect) { this.singleSelect = true; }
28989 // Wire the DragZone's handlers up to methods in *this*
28990 this.dragZone.getDragData = this.getDragData.createDelegate(this);
28994 /** Specify from which ddGroup this DDView accepts drops. */
28995 setDroppable: function(ddGroup) {
28996 if (ddGroup instanceof Array) {
28997 Roo.each(ddGroup, this.setDroppable, this);
29000 if (this.dropZone) {
29001 this.dropZone.addToGroup(ddGroup);
29003 this.dropZone = new Roo.dd.DropZone(this.getEl(), {
29004 containerScroll: true,
29008 // Wire the DropZone's handlers up to methods in *this*
29009 this.dropZone.getTargetFromEvent = this.getTargetFromEvent.createDelegate(this);
29010 this.dropZone.onNodeEnter = this.onNodeEnter.createDelegate(this);
29011 this.dropZone.onNodeOver = this.onNodeOver.createDelegate(this);
29012 this.dropZone.onNodeOut = this.onNodeOut.createDelegate(this);
29013 this.dropZone.onNodeDrop = this.onNodeDrop.createDelegate(this);
29017 /** Decide whether to drop above or below a View node. */
29018 getDropPoint : function(e, n, dd){
29019 if (n == this.el.dom) { return "above"; }
29020 var t = Roo.lib.Dom.getY(n), b = t + n.offsetHeight;
29021 var c = t + (b - t) / 2;
29022 var y = Roo.lib.Event.getPageY(e);
29030 onNodeEnter : function(n, dd, e, data){
29034 onNodeOver : function(n, dd, e, data){
29035 var pt = this.getDropPoint(e, n, dd);
29036 // set the insert point style on the target node
29037 var dragElClass = this.dropNotAllowed;
29040 if (pt == "above"){
29041 dragElClass = n.previousSibling ? "x-tree-drop-ok-between" : "x-tree-drop-ok-above";
29042 targetElClass = "x-view-drag-insert-above";
29044 dragElClass = n.nextSibling ? "x-tree-drop-ok-between" : "x-tree-drop-ok-below";
29045 targetElClass = "x-view-drag-insert-below";
29047 if (this.lastInsertClass != targetElClass){
29048 Roo.fly(n).replaceClass(this.lastInsertClass, targetElClass);
29049 this.lastInsertClass = targetElClass;
29052 return dragElClass;
29055 onNodeOut : function(n, dd, e, data){
29056 this.removeDropIndicators(n);
29059 onNodeDrop : function(n, dd, e, data){
29060 if (this.fireEvent("drop", this, n, dd, e, data) === false) {
29063 var pt = this.getDropPoint(e, n, dd);
29064 var insertAt = (n == this.el.dom) ? this.nodes.length : n.nodeIndex;
29065 if (pt == "below") { insertAt++; }
29066 for (var i = 0; i < data.records.length; i++) {
29067 var r = data.records[i];
29068 var dup = this.store.getById(r.id);
29069 if (dup && (dd != this.dragZone)) {
29070 Roo.fly(this.getNode(this.store.indexOf(dup))).frame("red", 1);
29073 this.store.insert(insertAt++, r.copy());
29075 data.source.isDirtyFlag = true;
29077 this.store.insert(insertAt++, r);
29079 this.isDirtyFlag = true;
29082 this.dragZone.cachedTarget = null;
29086 removeDropIndicators : function(n){
29088 Roo.fly(n).removeClass([
29089 "x-view-drag-insert-above",
29090 "x-view-drag-insert-below"]);
29091 this.lastInsertClass = "_noclass";
29096 * Utility method. Add a delete option to the DDView's context menu.
29097 * @param {String} imageUrl The URL of the "delete" icon image.
29099 setDeletable: function(imageUrl) {
29100 if (!this.singleSelect && !this.multiSelect) {
29101 this.singleSelect = true;
29103 var c = this.getContextMenu();
29104 this.contextMenu.on("itemclick", function(item) {
29107 this.remove(this.getSelectedIndexes());
29111 this.contextMenu.add({
29118 /** Return the context menu for this DDView. */
29119 getContextMenu: function() {
29120 if (!this.contextMenu) {
29121 // Create the View's context menu
29122 this.contextMenu = new Roo.menu.Menu({
29123 id: this.id + "-contextmenu"
29125 this.el.on("contextmenu", this.showContextMenu, this);
29127 return this.contextMenu;
29130 disableContextMenu: function() {
29131 if (this.contextMenu) {
29132 this.el.un("contextmenu", this.showContextMenu, this);
29136 showContextMenu: function(e, item) {
29137 item = this.findItemFromChild(e.getTarget());
29140 this.select(this.getNode(item), this.multiSelect && e.ctrlKey, true);
29141 this.contextMenu.showAt(e.getXY());
29146 * Remove {@link Roo.data.Record}s at the specified indices.
29147 * @param {Array/Number} selectedIndices The index (or Array of indices) of Records to remove.
29149 remove: function(selectedIndices) {
29150 selectedIndices = [].concat(selectedIndices);
29151 for (var i = 0; i < selectedIndices.length; i++) {
29152 var rec = this.store.getAt(selectedIndices[i]);
29153 this.store.remove(rec);
29158 * Double click fires the event, but also, if this is draggable, and there is only one other
29159 * related DropZone, it transfers the selected node.
29161 onDblClick : function(e){
29162 var item = this.findItemFromChild(e.getTarget());
29164 if (this.fireEvent("dblclick", this, this.indexOf(item), item, e) === false) {
29167 if (this.dragGroup) {
29168 var targets = Roo.dd.DragDropMgr.getRelated(this.dragZone, true);
29169 while (targets.indexOf(this.dropZone) > -1) {
29170 targets.remove(this.dropZone);
29172 if (targets.length == 1) {
29173 this.dragZone.cachedTarget = null;
29174 var el = Roo.get(targets[0].getEl());
29175 var box = el.getBox(true);
29176 targets[0].onNodeDrop(el.dom, {
29178 xy: [box.x, box.y + box.height - 1]
29179 }, null, this.getDragData(e));
29185 handleSelection: function(e) {
29186 this.dragZone.cachedTarget = null;
29187 var item = this.findItemFromChild(e.getTarget());
29189 this.clearSelections(true);
29192 if (item && (this.multiSelect || this.singleSelect)){
29193 if(this.multiSelect && e.shiftKey && (!e.ctrlKey) && this.lastSelection){
29194 this.select(this.getNodes(this.indexOf(this.lastSelection), item.nodeIndex), false);
29195 }else if (this.isSelected(this.getNode(item)) && e.ctrlKey){
29196 this.unselect(item);
29198 this.select(item, this.multiSelect && e.ctrlKey);
29199 this.lastSelection = item;
29204 onItemClick : function(item, index, e){
29205 if(this.fireEvent("beforeclick", this, index, item, e) === false){
29211 unselect : function(nodeInfo, suppressEvent){
29212 var node = this.getNode(nodeInfo);
29213 if(node && this.isSelected(node)){
29214 if(this.fireEvent("beforeselect", this, node, this.selections) !== false){
29215 Roo.fly(node).removeClass(this.selectedClass);
29216 this.selections.remove(node);
29217 if(!suppressEvent){
29218 this.fireEvent("selectionchange", this, this.selections);
29226 * Ext JS Library 1.1.1
29227 * Copyright(c) 2006-2007, Ext JS, LLC.
29229 * Originally Released Under LGPL - original licence link has changed is not relivant.
29232 * <script type="text/javascript">
29236 * @class Roo.LayoutManager
29237 * @extends Roo.util.Observable
29238 * Base class for layout managers.
29240 Roo.LayoutManager = function(container, config){
29241 Roo.LayoutManager.superclass.constructor.call(this);
29242 this.el = Roo.get(container);
29243 // ie scrollbar fix
29244 if(this.el.dom == document.body && Roo.isIE && !config.allowScroll){
29245 document.body.scroll = "no";
29246 }else if(this.el.dom != document.body && this.el.getStyle('position') == 'static'){
29247 this.el.position('relative');
29249 this.id = this.el.id;
29250 this.el.addClass("x-layout-container");
29251 /** false to disable window resize monitoring @type Boolean */
29252 this.monitorWindowResize = true;
29257 * Fires when a layout is performed.
29258 * @param {Roo.LayoutManager} this
29262 * @event regionresized
29263 * Fires when the user resizes a region.
29264 * @param {Roo.LayoutRegion} region The resized region
29265 * @param {Number} newSize The new size (width for east/west, height for north/south)
29267 "regionresized" : true,
29269 * @event regioncollapsed
29270 * Fires when a region is collapsed.
29271 * @param {Roo.LayoutRegion} region The collapsed region
29273 "regioncollapsed" : true,
29275 * @event regionexpanded
29276 * Fires when a region is expanded.
29277 * @param {Roo.LayoutRegion} region The expanded region
29279 "regionexpanded" : true
29281 this.updating = false;
29282 Roo.EventManager.onWindowResize(this.onWindowResize, this, true);
29285 Roo.extend(Roo.LayoutManager, Roo.util.Observable, {
29287 * Returns true if this layout is currently being updated
29288 * @return {Boolean}
29290 isUpdating : function(){
29291 return this.updating;
29295 * Suspend the LayoutManager from doing auto-layouts while
29296 * making multiple add or remove calls
29298 beginUpdate : function(){
29299 this.updating = true;
29303 * Restore auto-layouts and optionally disable the manager from performing a layout
29304 * @param {Boolean} noLayout true to disable a layout update
29306 endUpdate : function(noLayout){
29307 this.updating = false;
29313 layout: function(){
29317 onRegionResized : function(region, newSize){
29318 this.fireEvent("regionresized", region, newSize);
29322 onRegionCollapsed : function(region){
29323 this.fireEvent("regioncollapsed", region);
29326 onRegionExpanded : function(region){
29327 this.fireEvent("regionexpanded", region);
29331 * Returns the size of the current view. This method normalizes document.body and element embedded layouts and
29332 * performs box-model adjustments.
29333 * @return {Object} The size as an object {width: (the width), height: (the height)}
29335 getViewSize : function(){
29337 if(this.el.dom != document.body){
29338 size = this.el.getSize();
29340 size = {width: Roo.lib.Dom.getViewWidth(), height: Roo.lib.Dom.getViewHeight()};
29342 size.width -= this.el.getBorderWidth("lr")-this.el.getPadding("lr");
29343 size.height -= this.el.getBorderWidth("tb")-this.el.getPadding("tb");
29348 * Returns the Element this layout is bound to.
29349 * @return {Roo.Element}
29351 getEl : function(){
29356 * Returns the specified region.
29357 * @param {String} target The region key ('center', 'north', 'south', 'east' or 'west')
29358 * @return {Roo.LayoutRegion}
29360 getRegion : function(target){
29361 return this.regions[target.toLowerCase()];
29364 onWindowResize : function(){
29365 if(this.monitorWindowResize){
29371 * Ext JS Library 1.1.1
29372 * Copyright(c) 2006-2007, Ext JS, LLC.
29374 * Originally Released Under LGPL - original licence link has changed is not relivant.
29377 * <script type="text/javascript">
29380 * @class Roo.BorderLayout
29381 * @extends Roo.LayoutManager
29382 * This class represents a common layout manager used in desktop applications. For screenshots and more details,
29383 * please see: <br><br>
29384 * <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>
29385 * <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>
29388 var layout = new Roo.BorderLayout(document.body, {
29422 preferredTabWidth: 150
29427 var CP = Roo.ContentPanel;
29429 layout.beginUpdate();
29430 layout.add("north", new CP("north", "North"));
29431 layout.add("south", new CP("south", {title: "South", closable: true}));
29432 layout.add("west", new CP("west", {title: "West"}));
29433 layout.add("east", new CP("autoTabs", {title: "Auto Tabs", closable: true}));
29434 layout.add("center", new CP("center1", {title: "Close Me", closable: true}));
29435 layout.add("center", new CP("center2", {title: "Center Panel", closable: false}));
29436 layout.getRegion("center").showPanel("center1");
29437 layout.endUpdate();
29440 <b>The container the layout is rendered into can be either the body element or any other element.
29441 If it is not the body element, the container needs to either be an absolute positioned element,
29442 or you will need to add "position:relative" to the css of the container. You will also need to specify
29443 the container size if it is not the body element.</b>
29446 * Create a new BorderLayout
29447 * @param {String/HTMLElement/Element} container The container this layout is bound to
29448 * @param {Object} config Configuration options
29450 Roo.BorderLayout = function(container, config){
29451 config = config || {};
29452 Roo.BorderLayout.superclass.constructor.call(this, container, config);
29453 this.factory = config.factory || Roo.BorderLayout.RegionFactory;
29454 for(var i = 0, len = this.factory.validRegions.length; i < len; i++) {
29455 var target = this.factory.validRegions[i];
29456 if(config[target]){
29457 this.addRegion(target, config[target]);
29462 Roo.extend(Roo.BorderLayout, Roo.LayoutManager, {
29464 * Creates and adds a new region if it doesn't already exist.
29465 * @param {String} target The target region key (north, south, east, west or center).
29466 * @param {Object} config The regions config object
29467 * @return {BorderLayoutRegion} The new region
29469 addRegion : function(target, config){
29470 if(!this.regions[target]){
29471 var r = this.factory.create(target, this, config);
29472 this.bindRegion(target, r);
29474 return this.regions[target];
29478 bindRegion : function(name, r){
29479 this.regions[name] = r;
29480 r.on("visibilitychange", this.layout, this);
29481 r.on("paneladded", this.layout, this);
29482 r.on("panelremoved", this.layout, this);
29483 r.on("invalidated", this.layout, this);
29484 r.on("resized", this.onRegionResized, this);
29485 r.on("collapsed", this.onRegionCollapsed, this);
29486 r.on("expanded", this.onRegionExpanded, this);
29490 * Performs a layout update.
29492 layout : function(){
29493 if(this.updating) {
29496 var size = this.getViewSize();
29497 var w = size.width;
29498 var h = size.height;
29503 //var x = 0, y = 0;
29505 var rs = this.regions;
29506 var north = rs["north"];
29507 var south = rs["south"];
29508 var west = rs["west"];
29509 var east = rs["east"];
29510 var center = rs["center"];
29511 //if(this.hideOnLayout){ // not supported anymore
29512 //c.el.setStyle("display", "none");
29514 if(north && north.isVisible()){
29515 var b = north.getBox();
29516 var m = north.getMargins();
29517 b.width = w - (m.left+m.right);
29520 centerY = b.height + b.y + m.bottom;
29521 centerH -= centerY;
29522 north.updateBox(this.safeBox(b));
29524 if(south && south.isVisible()){
29525 var b = south.getBox();
29526 var m = south.getMargins();
29527 b.width = w - (m.left+m.right);
29529 var totalHeight = (b.height + m.top + m.bottom);
29530 b.y = h - totalHeight + m.top;
29531 centerH -= totalHeight;
29532 south.updateBox(this.safeBox(b));
29534 if(west && west.isVisible()){
29535 var b = west.getBox();
29536 var m = west.getMargins();
29537 b.height = centerH - (m.top+m.bottom);
29539 b.y = centerY + m.top;
29540 var totalWidth = (b.width + m.left + m.right);
29541 centerX += totalWidth;
29542 centerW -= totalWidth;
29543 west.updateBox(this.safeBox(b));
29545 if(east && east.isVisible()){
29546 var b = east.getBox();
29547 var m = east.getMargins();
29548 b.height = centerH - (m.top+m.bottom);
29549 var totalWidth = (b.width + m.left + m.right);
29550 b.x = w - totalWidth + m.left;
29551 b.y = centerY + m.top;
29552 centerW -= totalWidth;
29553 east.updateBox(this.safeBox(b));
29556 var m = center.getMargins();
29558 x: centerX + m.left,
29559 y: centerY + m.top,
29560 width: centerW - (m.left+m.right),
29561 height: centerH - (m.top+m.bottom)
29563 //if(this.hideOnLayout){
29564 //center.el.setStyle("display", "block");
29566 center.updateBox(this.safeBox(centerBox));
29569 this.fireEvent("layout", this);
29573 safeBox : function(box){
29574 box.width = Math.max(0, box.width);
29575 box.height = Math.max(0, box.height);
29580 * Adds a ContentPanel (or subclass) to this layout.
29581 * @param {String} target The target region key (north, south, east, west or center).
29582 * @param {Roo.ContentPanel} panel The panel to add
29583 * @return {Roo.ContentPanel} The added panel
29585 add : function(target, panel){
29587 target = target.toLowerCase();
29588 return this.regions[target].add(panel);
29592 * Remove a ContentPanel (or subclass) to this layout.
29593 * @param {String} target The target region key (north, south, east, west or center).
29594 * @param {Number/String/Roo.ContentPanel} panel The index, id or panel to remove
29595 * @return {Roo.ContentPanel} The removed panel
29597 remove : function(target, panel){
29598 target = target.toLowerCase();
29599 return this.regions[target].remove(panel);
29603 * Searches all regions for a panel with the specified id
29604 * @param {String} panelId
29605 * @return {Roo.ContentPanel} The panel or null if it wasn't found
29607 findPanel : function(panelId){
29608 var rs = this.regions;
29609 for(var target in rs){
29610 if(typeof rs[target] != "function"){
29611 var p = rs[target].getPanel(panelId);
29621 * Searches all regions for a panel with the specified id and activates (shows) it.
29622 * @param {String/ContentPanel} panelId The panels id or the panel itself
29623 * @return {Roo.ContentPanel} The shown panel or null
29625 showPanel : function(panelId) {
29626 var rs = this.regions;
29627 for(var target in rs){
29628 var r = rs[target];
29629 if(typeof r != "function"){
29630 if(r.hasPanel(panelId)){
29631 return r.showPanel(panelId);
29639 * Restores this layout's state using Roo.state.Manager or the state provided by the passed provider.
29640 * @param {Roo.state.Provider} provider (optional) An alternate state provider
29642 restoreState : function(provider){
29644 provider = Roo.state.Manager;
29646 var sm = new Roo.LayoutStateManager();
29647 sm.init(this, provider);
29651 * Adds a batch of multiple ContentPanels dynamically by passing a special regions config object. This config
29652 * object should contain properties for each region to add ContentPanels to, and each property's value should be
29653 * a valid ContentPanel config object. Example:
29655 // Create the main layout
29656 var layout = new Roo.BorderLayout('main-ct', {
29667 // Create and add multiple ContentPanels at once via configs
29670 id: 'source-files',
29672 title:'Ext Source Files',
29685 * @param {Object} regions An object containing ContentPanel configs by region name
29687 batchAdd : function(regions){
29688 this.beginUpdate();
29689 for(var rname in regions){
29690 var lr = this.regions[rname];
29692 this.addTypedPanels(lr, regions[rname]);
29699 addTypedPanels : function(lr, ps){
29700 if(typeof ps == 'string'){
29701 lr.add(new Roo.ContentPanel(ps));
29703 else if(ps instanceof Array){
29704 for(var i =0, len = ps.length; i < len; i++){
29705 this.addTypedPanels(lr, ps[i]);
29708 else if(!ps.events){ // raw config?
29710 delete ps.el; // prevent conflict
29711 lr.add(new Roo.ContentPanel(el || Roo.id(), ps));
29713 else { // panel object assumed!
29718 * Adds a xtype elements to the layout.
29722 xtype : 'ContentPanel',
29729 xtype : 'NestedLayoutPanel',
29735 items : [ ... list of content panels or nested layout panels.. ]
29739 * @param {Object} cfg Xtype definition of item to add.
29741 addxtype : function(cfg)
29743 // basically accepts a pannel...
29744 // can accept a layout region..!?!?
29745 //Roo.log('Roo.BorderLayout add ' + cfg.xtype)
29747 if (!cfg.xtype.match(/Panel$/)) {
29752 if (typeof(cfg.region) == 'undefined') {
29753 Roo.log("Failed to add Panel, region was not set");
29757 var region = cfg.region;
29763 xitems = cfg.items;
29770 case 'ContentPanel': // ContentPanel (el, cfg)
29771 case 'ScrollPanel': // ContentPanel (el, cfg)
29773 if(cfg.autoCreate) {
29774 ret = new Roo[cfg.xtype](cfg); // new panel!!!!!
29776 var el = this.el.createChild();
29777 ret = new Roo[cfg.xtype](el, cfg); // new panel!!!!!
29780 this.add(region, ret);
29784 case 'TreePanel': // our new panel!
29785 cfg.el = this.el.createChild();
29786 ret = new Roo[cfg.xtype](cfg); // new panel!!!!!
29787 this.add(region, ret);
29790 case 'NestedLayoutPanel':
29791 // create a new Layout (which is a Border Layout...
29792 var el = this.el.createChild();
29793 var clayout = cfg.layout;
29795 clayout.items = clayout.items || [];
29796 // replace this exitems with the clayout ones..
29797 xitems = clayout.items;
29800 if (region == 'center' && this.active && this.getRegion('center').panels.length < 1) {
29801 cfg.background = false;
29803 var layout = new Roo.BorderLayout(el, clayout);
29805 ret = new Roo[cfg.xtype](layout, cfg); // new panel!!!!!
29806 //console.log('adding nested layout panel ' + cfg.toSource());
29807 this.add(region, ret);
29808 nb = {}; /// find first...
29813 // needs grid and region
29815 //var el = this.getRegion(region).el.createChild();
29816 var el = this.el.createChild();
29817 // create the grid first...
29819 var grid = new Roo.grid[cfg.grid.xtype](el, cfg.grid);
29821 if (region == 'center' && this.active ) {
29822 cfg.background = false;
29824 ret = new Roo[cfg.xtype](grid, cfg); // new panel!!!!!
29826 this.add(region, ret);
29827 if (cfg.background) {
29828 ret.on('activate', function(gp) {
29829 if (!gp.grid.rendered) {
29844 if (typeof(Roo[cfg.xtype]) != 'undefined') {
29846 ret = new Roo[cfg.xtype](cfg); // new panel!!!!!
29847 this.add(region, ret);
29850 alert("Can not add '" + cfg.xtype + "' to BorderLayout");
29854 // GridPanel (grid, cfg)
29857 this.beginUpdate();
29861 Roo.each(xitems, function(i) {
29862 region = nb && i.region ? i.region : false;
29864 var add = ret.addxtype(i);
29867 nb[region] = nb[region] == undefined ? 0 : nb[region]+1;
29868 if (!i.background) {
29869 abn[region] = nb[region] ;
29876 // make the last non-background panel active..
29877 //if (nb) { Roo.log(abn); }
29880 for(var r in abn) {
29881 region = this.getRegion(r);
29883 // tried using nb[r], but it does not work..
29885 region.showPanel(abn[r]);
29896 * Shortcut for creating a new BorderLayout object and adding one or more ContentPanels to it in a single step, handling
29897 * the beginUpdate and endUpdate calls internally. The key to this method is the <b>panels</b> property that can be
29898 * provided with each region config, which allows you to add ContentPanel configs in addition to the region configs
29899 * during creation. The following code is equivalent to the constructor-based example at the beginning of this class:
29902 var CP = Roo.ContentPanel;
29904 var layout = Roo.BorderLayout.create({
29908 panels: [new CP("north", "North")]
29917 panels: [new CP("west", {title: "West"})]
29926 panels: [new CP("autoTabs", {title: "Auto Tabs", closable: true})]
29935 panels: [new CP("south", {title: "South", closable: true})]
29942 preferredTabWidth: 150,
29944 new CP("center1", {title: "Close Me", closable: true}),
29945 new CP("center2", {title: "Center Panel", closable: false})
29950 layout.getRegion("center").showPanel("center1");
29955 Roo.BorderLayout.create = function(config, targetEl){
29956 var layout = new Roo.BorderLayout(targetEl || document.body, config);
29957 layout.beginUpdate();
29958 var regions = Roo.BorderLayout.RegionFactory.validRegions;
29959 for(var j = 0, jlen = regions.length; j < jlen; j++){
29960 var lr = regions[j];
29961 if(layout.regions[lr] && config[lr].panels){
29962 var r = layout.regions[lr];
29963 var ps = config[lr].panels;
29964 layout.addTypedPanels(r, ps);
29967 layout.endUpdate();
29972 Roo.BorderLayout.RegionFactory = {
29974 validRegions : ["north","south","east","west","center"],
29977 create : function(target, mgr, config){
29978 target = target.toLowerCase();
29979 if(config.lightweight || config.basic){
29980 return new Roo.BasicLayoutRegion(mgr, config, target);
29984 return new Roo.NorthLayoutRegion(mgr, config);
29986 return new Roo.SouthLayoutRegion(mgr, config);
29988 return new Roo.EastLayoutRegion(mgr, config);
29990 return new Roo.WestLayoutRegion(mgr, config);
29992 return new Roo.CenterLayoutRegion(mgr, config);
29994 throw 'Layout region "'+target+'" not supported.';
29998 * Ext JS Library 1.1.1
29999 * Copyright(c) 2006-2007, Ext JS, LLC.
30001 * Originally Released Under LGPL - original licence link has changed is not relivant.
30004 * <script type="text/javascript">
30008 * @class Roo.BasicLayoutRegion
30009 * @extends Roo.util.Observable
30010 * This class represents a lightweight region in a layout manager. This region does not move dom nodes
30011 * and does not have a titlebar, tabs or any other features. All it does is size and position
30012 * panels. To create a BasicLayoutRegion, add lightweight:true or basic:true to your regions config.
30014 Roo.BasicLayoutRegion = function(mgr, config, pos, skipConfig){
30016 this.position = pos;
30019 * @scope Roo.BasicLayoutRegion
30023 * @event beforeremove
30024 * Fires before a panel is removed (or closed). To cancel the removal set "e.cancel = true" on the event argument.
30025 * @param {Roo.LayoutRegion} this
30026 * @param {Roo.ContentPanel} panel The panel
30027 * @param {Object} e The cancel event object
30029 "beforeremove" : true,
30031 * @event invalidated
30032 * Fires when the layout for this region is changed.
30033 * @param {Roo.LayoutRegion} this
30035 "invalidated" : true,
30037 * @event visibilitychange
30038 * Fires when this region is shown or hidden
30039 * @param {Roo.LayoutRegion} this
30040 * @param {Boolean} visibility true or false
30042 "visibilitychange" : true,
30044 * @event paneladded
30045 * Fires when a panel is added.
30046 * @param {Roo.LayoutRegion} this
30047 * @param {Roo.ContentPanel} panel The panel
30049 "paneladded" : true,
30051 * @event panelremoved
30052 * Fires when a panel is removed.
30053 * @param {Roo.LayoutRegion} this
30054 * @param {Roo.ContentPanel} panel The panel
30056 "panelremoved" : true,
30058 * @event beforecollapse
30059 * Fires when this region before collapse.
30060 * @param {Roo.LayoutRegion} this
30062 "beforecollapse" : true,
30065 * Fires when this region is collapsed.
30066 * @param {Roo.LayoutRegion} this
30068 "collapsed" : true,
30071 * Fires when this region is expanded.
30072 * @param {Roo.LayoutRegion} this
30077 * Fires when this region is slid into view.
30078 * @param {Roo.LayoutRegion} this
30080 "slideshow" : true,
30083 * Fires when this region slides out of view.
30084 * @param {Roo.LayoutRegion} this
30086 "slidehide" : true,
30088 * @event panelactivated
30089 * Fires when a panel is activated.
30090 * @param {Roo.LayoutRegion} this
30091 * @param {Roo.ContentPanel} panel The activated panel
30093 "panelactivated" : true,
30096 * Fires when the user resizes this region.
30097 * @param {Roo.LayoutRegion} this
30098 * @param {Number} newSize The new size (width for east/west, height for north/south)
30102 /** A collection of panels in this region. @type Roo.util.MixedCollection */
30103 this.panels = new Roo.util.MixedCollection();
30104 this.panels.getKey = this.getPanelId.createDelegate(this);
30106 this.activePanel = null;
30107 // ensure listeners are added...
30109 if (config.listeners || config.events) {
30110 Roo.BasicLayoutRegion.superclass.constructor.call(this, {
30111 listeners : config.listeners || {},
30112 events : config.events || {}
30116 if(skipConfig !== true){
30117 this.applyConfig(config);
30121 Roo.extend(Roo.BasicLayoutRegion, Roo.util.Observable, {
30122 getPanelId : function(p){
30126 applyConfig : function(config){
30127 this.margins = config.margins || this.margins || {top: 0, left: 0, right:0, bottom: 0};
30128 this.config = config;
30133 * Resizes the region to the specified size. For vertical regions (west, east) this adjusts
30134 * the width, for horizontal (north, south) the height.
30135 * @param {Number} newSize The new width or height
30137 resizeTo : function(newSize){
30138 var el = this.el ? this.el :
30139 (this.activePanel ? this.activePanel.getEl() : null);
30141 switch(this.position){
30144 el.setWidth(newSize);
30145 this.fireEvent("resized", this, newSize);
30149 el.setHeight(newSize);
30150 this.fireEvent("resized", this, newSize);
30156 getBox : function(){
30157 return this.activePanel ? this.activePanel.getEl().getBox(false, true) : null;
30160 getMargins : function(){
30161 return this.margins;
30164 updateBox : function(box){
30166 var el = this.activePanel.getEl();
30167 el.dom.style.left = box.x + "px";
30168 el.dom.style.top = box.y + "px";
30169 this.activePanel.setSize(box.width, box.height);
30173 * Returns the container element for this region.
30174 * @return {Roo.Element}
30176 getEl : function(){
30177 return this.activePanel;
30181 * Returns true if this region is currently visible.
30182 * @return {Boolean}
30184 isVisible : function(){
30185 return this.activePanel ? true : false;
30188 setActivePanel : function(panel){
30189 panel = this.getPanel(panel);
30190 if(this.activePanel && this.activePanel != panel){
30191 this.activePanel.setActiveState(false);
30192 this.activePanel.getEl().setLeftTop(-10000,-10000);
30194 this.activePanel = panel;
30195 panel.setActiveState(true);
30197 panel.setSize(this.box.width, this.box.height);
30199 this.fireEvent("panelactivated", this, panel);
30200 this.fireEvent("invalidated");
30204 * Show the specified panel.
30205 * @param {Number/String/ContentPanel} panelId The panels index, id or the panel itself
30206 * @return {Roo.ContentPanel} The shown panel or null
30208 showPanel : function(panel){
30209 if(panel = this.getPanel(panel)){
30210 this.setActivePanel(panel);
30216 * Get the active panel for this region.
30217 * @return {Roo.ContentPanel} The active panel or null
30219 getActivePanel : function(){
30220 return this.activePanel;
30224 * Add the passed ContentPanel(s)
30225 * @param {ContentPanel...} panel The ContentPanel(s) to add (you can pass more than one)
30226 * @return {Roo.ContentPanel} The panel added (if only one was added)
30228 add : function(panel){
30229 if(arguments.length > 1){
30230 for(var i = 0, len = arguments.length; i < len; i++) {
30231 this.add(arguments[i]);
30235 if(this.hasPanel(panel)){
30236 this.showPanel(panel);
30239 var el = panel.getEl();
30240 if(el.dom.parentNode != this.mgr.el.dom){
30241 this.mgr.el.dom.appendChild(el.dom);
30243 if(panel.setRegion){
30244 panel.setRegion(this);
30246 this.panels.add(panel);
30247 el.setStyle("position", "absolute");
30248 if(!panel.background){
30249 this.setActivePanel(panel);
30250 if(this.config.initialSize && this.panels.getCount()==1){
30251 this.resizeTo(this.config.initialSize);
30254 this.fireEvent("paneladded", this, panel);
30259 * Returns true if the panel is in this region.
30260 * @param {Number/String/ContentPanel} panel The panels index, id or the panel itself
30261 * @return {Boolean}
30263 hasPanel : function(panel){
30264 if(typeof panel == "object"){ // must be panel obj
30265 panel = panel.getId();
30267 return this.getPanel(panel) ? true : false;
30271 * Removes the specified panel. If preservePanel is not true (either here or in the config), the panel is destroyed.
30272 * @param {Number/String/ContentPanel} panel The panels index, id or the panel itself
30273 * @param {Boolean} preservePanel Overrides the config preservePanel option
30274 * @return {Roo.ContentPanel} The panel that was removed
30276 remove : function(panel, preservePanel){
30277 panel = this.getPanel(panel);
30282 this.fireEvent("beforeremove", this, panel, e);
30283 if(e.cancel === true){
30286 var panelId = panel.getId();
30287 this.panels.removeKey(panelId);
30292 * Returns the panel specified or null if it's not in this region.
30293 * @param {Number/String/ContentPanel} panel The panels index, id or the panel itself
30294 * @return {Roo.ContentPanel}
30296 getPanel : function(id){
30297 if(typeof id == "object"){ // must be panel obj
30300 return this.panels.get(id);
30304 * Returns this regions position (north/south/east/west/center).
30307 getPosition: function(){
30308 return this.position;
30312 * Ext JS Library 1.1.1
30313 * Copyright(c) 2006-2007, Ext JS, LLC.
30315 * Originally Released Under LGPL - original licence link has changed is not relivant.
30318 * <script type="text/javascript">
30322 * @class Roo.LayoutRegion
30323 * @extends Roo.BasicLayoutRegion
30324 * This class represents a region in a layout manager.
30325 * @cfg {Boolean} collapsible False to disable collapsing (defaults to true)
30326 * @cfg {Boolean} collapsed True to set the initial display to collapsed (defaults to false)
30327 * @cfg {Boolean} floatable False to disable floating (defaults to true)
30328 * @cfg {Object} margins Margins for the element (defaults to {top: 0, left: 0, right:0, bottom: 0})
30329 * @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})
30330 * @cfg {String} tabPosition (top|bottom) "top" or "bottom" (defaults to "bottom")
30331 * @cfg {String} collapsedTitle Optional string message to display in the collapsed block of a north or south region
30332 * @cfg {Boolean} alwaysShowTabs True to always display tabs even when there is only 1 panel (defaults to false)
30333 * @cfg {Boolean} autoScroll True to enable overflow scrolling (defaults to false)
30334 * @cfg {Boolean} titlebar True to display a title bar (defaults to true)
30335 * @cfg {String} title The title for the region (overrides panel titles)
30336 * @cfg {Boolean} animate True to animate expand/collapse (defaults to false)
30337 * @cfg {Boolean} autoHide False to disable auto hiding when the mouse leaves the "floated" region (defaults to true)
30338 * @cfg {Boolean} preservePanels True to preserve removed panels so they can be readded later (defaults to false)
30339 * @cfg {Boolean} closeOnTab True to place the close icon on the tabs instead of the region titlebar (defaults to false)
30340 * @cfg {Boolean} hideTabs True to hide the tab strip (defaults to false)
30341 * @cfg {Boolean} resizeTabs True to enable automatic tab resizing. This will resize the tabs so they are all the same size and fit within
30342 * the space available, similar to FireFox 1.5 tabs (defaults to false)
30343 * @cfg {Number} minTabWidth The minimum tab width (defaults to 40)
30344 * @cfg {Number} preferredTabWidth The preferred tab width (defaults to 150)
30345 * @cfg {Boolean} showPin True to show a pin button
30346 * @cfg {Boolean} hidden True to start the region hidden (defaults to false)
30347 * @cfg {Boolean} hideWhenEmpty True to hide the region when it has no panels
30348 * @cfg {Boolean} disableTabTips True to disable tab tooltips
30349 * @cfg {Number} width For East/West panels
30350 * @cfg {Number} height For North/South panels
30351 * @cfg {Boolean} split To show the splitter
30352 * @cfg {Boolean} toolbar xtype configuration for a toolbar - shows on right of tabbar
30354 Roo.LayoutRegion = function(mgr, config, pos){
30355 Roo.LayoutRegion.superclass.constructor.call(this, mgr, config, pos, true);
30356 var dh = Roo.DomHelper;
30357 /** This region's container element
30358 * @type Roo.Element */
30359 this.el = dh.append(mgr.el.dom, {tag: "div", cls: "x-layout-panel x-layout-panel-" + this.position}, true);
30360 /** This region's title element
30361 * @type Roo.Element */
30363 this.titleEl = dh.append(this.el.dom, {tag: "div", unselectable: "on", cls: "x-unselectable x-layout-panel-hd x-layout-title-"+this.position, children:[
30364 {tag: "span", cls: "x-unselectable x-layout-panel-hd-text", unselectable: "on", html: " "},
30365 {tag: "div", cls: "x-unselectable x-layout-panel-hd-tools", unselectable: "on"}
30367 this.titleEl.enableDisplayMode();
30368 /** This region's title text element
30369 * @type HTMLElement */
30370 this.titleTextEl = this.titleEl.dom.firstChild;
30371 this.tools = Roo.get(this.titleEl.dom.childNodes[1], true);
30372 this.closeBtn = this.createTool(this.tools.dom, "x-layout-close");
30373 this.closeBtn.enableDisplayMode();
30374 this.closeBtn.on("click", this.closeClicked, this);
30375 this.closeBtn.hide();
30377 this.createBody(config);
30378 this.visible = true;
30379 this.collapsed = false;
30381 if(config.hideWhenEmpty){
30383 this.on("paneladded", this.validateVisibility, this);
30384 this.on("panelremoved", this.validateVisibility, this);
30386 this.applyConfig(config);
30389 Roo.extend(Roo.LayoutRegion, Roo.BasicLayoutRegion, {
30391 createBody : function(){
30392 /** This region's body element
30393 * @type Roo.Element */
30394 this.bodyEl = this.el.createChild({tag: "div", cls: "x-layout-panel-body"});
30397 applyConfig : function(c){
30398 if(c.collapsible && this.position != "center" && !this.collapsedEl){
30399 var dh = Roo.DomHelper;
30400 if(c.titlebar !== false){
30401 this.collapseBtn = this.createTool(this.tools.dom, "x-layout-collapse-"+this.position);
30402 this.collapseBtn.on("click", this.collapse, this);
30403 this.collapseBtn.enableDisplayMode();
30405 if(c.showPin === true || this.showPin){
30406 this.stickBtn = this.createTool(this.tools.dom, "x-layout-stick");
30407 this.stickBtn.enableDisplayMode();
30408 this.stickBtn.on("click", this.expand, this);
30409 this.stickBtn.hide();
30412 /** This region's collapsed element
30413 * @type Roo.Element */
30414 this.collapsedEl = dh.append(this.mgr.el.dom, {cls: "x-layout-collapsed x-layout-collapsed-"+this.position, children:[
30415 {cls: "x-layout-collapsed-tools", children:[{cls: "x-layout-ctools-inner"}]}
30417 if(c.floatable !== false){
30418 this.collapsedEl.addClassOnOver("x-layout-collapsed-over");
30419 this.collapsedEl.on("click", this.collapseClick, this);
30422 if(c.collapsedTitle && (this.position == "north" || this.position== "south")) {
30423 this.collapsedTitleTextEl = dh.append(this.collapsedEl.dom, {tag: "div", cls: "x-unselectable x-layout-panel-hd-text",
30424 id: "message", unselectable: "on", style:{"float":"left"}});
30425 this.collapsedTitleTextEl.innerHTML = c.collapsedTitle;
30427 this.expandBtn = this.createTool(this.collapsedEl.dom.firstChild.firstChild, "x-layout-expand-"+this.position);
30428 this.expandBtn.on("click", this.expand, this);
30430 if(this.collapseBtn){
30431 this.collapseBtn.setVisible(c.collapsible == true);
30433 this.cmargins = c.cmargins || this.cmargins ||
30434 (this.position == "west" || this.position == "east" ?
30435 {top: 0, left: 2, right:2, bottom: 0} :
30436 {top: 2, left: 0, right:0, bottom: 2});
30437 this.margins = c.margins || this.margins || {top: 0, left: 0, right:0, bottom: 0};
30438 this.bottomTabs = c.tabPosition != "top";
30439 this.autoScroll = c.autoScroll || false;
30440 if(this.autoScroll){
30441 this.bodyEl.setStyle("overflow", "auto");
30443 this.bodyEl.setStyle("overflow", "hidden");
30445 //if(c.titlebar !== false){
30446 if((!c.titlebar && !c.title) || c.titlebar === false){
30447 this.titleEl.hide();
30449 this.titleEl.show();
30451 this.titleTextEl.innerHTML = c.title;
30455 this.duration = c.duration || .30;
30456 this.slideDuration = c.slideDuration || .45;
30459 this.collapse(true);
30466 * Returns true if this region is currently visible.
30467 * @return {Boolean}
30469 isVisible : function(){
30470 return this.visible;
30474 * Updates the title for collapsed north/south regions (used with {@link #collapsedTitle} config option)
30475 * @param {String} title (optional) The title text (accepts HTML markup, defaults to the numeric character reference for a non-breaking space, "&#160;")
30477 setCollapsedTitle : function(title){
30478 title = title || " ";
30479 if(this.collapsedTitleTextEl){
30480 this.collapsedTitleTextEl.innerHTML = title;
30484 getBox : function(){
30486 if(!this.collapsed){
30487 b = this.el.getBox(false, true);
30489 b = this.collapsedEl.getBox(false, true);
30494 getMargins : function(){
30495 return this.collapsed ? this.cmargins : this.margins;
30498 highlight : function(){
30499 this.el.addClass("x-layout-panel-dragover");
30502 unhighlight : function(){
30503 this.el.removeClass("x-layout-panel-dragover");
30506 updateBox : function(box){
30508 if(!this.collapsed){
30509 this.el.dom.style.left = box.x + "px";
30510 this.el.dom.style.top = box.y + "px";
30511 this.updateBody(box.width, box.height);
30513 this.collapsedEl.dom.style.left = box.x + "px";
30514 this.collapsedEl.dom.style.top = box.y + "px";
30515 this.collapsedEl.setSize(box.width, box.height);
30518 this.tabs.autoSizeTabs();
30522 updateBody : function(w, h){
30524 this.el.setWidth(w);
30525 w -= this.el.getBorderWidth("rl");
30526 if(this.config.adjustments){
30527 w += this.config.adjustments[0];
30531 this.el.setHeight(h);
30532 h = this.titleEl && this.titleEl.isDisplayed() ? h - (this.titleEl.getHeight()||0) : h;
30533 h -= this.el.getBorderWidth("tb");
30534 if(this.config.adjustments){
30535 h += this.config.adjustments[1];
30537 this.bodyEl.setHeight(h);
30539 h = this.tabs.syncHeight(h);
30542 if(this.panelSize){
30543 w = w !== null ? w : this.panelSize.width;
30544 h = h !== null ? h : this.panelSize.height;
30546 if(this.activePanel){
30547 var el = this.activePanel.getEl();
30548 w = w !== null ? w : el.getWidth();
30549 h = h !== null ? h : el.getHeight();
30550 this.panelSize = {width: w, height: h};
30551 this.activePanel.setSize(w, h);
30553 if(Roo.isIE && this.tabs){
30554 this.tabs.el.repaint();
30559 * Returns the container element for this region.
30560 * @return {Roo.Element}
30562 getEl : function(){
30567 * Hides this region.
30570 if(!this.collapsed){
30571 this.el.dom.style.left = "-2000px";
30574 this.collapsedEl.dom.style.left = "-2000px";
30575 this.collapsedEl.hide();
30577 this.visible = false;
30578 this.fireEvent("visibilitychange", this, false);
30582 * Shows this region if it was previously hidden.
30585 if(!this.collapsed){
30588 this.collapsedEl.show();
30590 this.visible = true;
30591 this.fireEvent("visibilitychange", this, true);
30594 closeClicked : function(){
30595 if(this.activePanel){
30596 this.remove(this.activePanel);
30600 collapseClick : function(e){
30602 e.stopPropagation();
30605 e.stopPropagation();
30611 * Collapses this region.
30612 * @param {Boolean} skipAnim (optional) true to collapse the element without animation (if animate is true)
30614 collapse : function(skipAnim, skipCheck){
30615 if(this.collapsed) {
30619 if(skipCheck || this.fireEvent("beforecollapse", this) != false){
30621 this.collapsed = true;
30623 this.split.el.hide();
30625 if(this.config.animate && skipAnim !== true){
30626 this.fireEvent("invalidated", this);
30627 this.animateCollapse();
30629 this.el.setLocation(-20000,-20000);
30631 this.collapsedEl.show();
30632 this.fireEvent("collapsed", this);
30633 this.fireEvent("invalidated", this);
30639 animateCollapse : function(){
30644 * Expands this region if it was previously collapsed.
30645 * @param {Roo.EventObject} e The event that triggered the expand (or null if calling manually)
30646 * @param {Boolean} skipAnim (optional) true to expand the element without animation (if animate is true)
30648 expand : function(e, skipAnim){
30650 e.stopPropagation();
30652 if(!this.collapsed || this.el.hasActiveFx()) {
30656 this.afterSlideIn();
30659 this.collapsed = false;
30660 if(this.config.animate && skipAnim !== true){
30661 this.animateExpand();
30665 this.split.el.show();
30667 this.collapsedEl.setLocation(-2000,-2000);
30668 this.collapsedEl.hide();
30669 this.fireEvent("invalidated", this);
30670 this.fireEvent("expanded", this);
30674 animateExpand : function(){
30678 initTabs : function()
30680 this.bodyEl.setStyle("overflow", "hidden");
30681 var ts = new Roo.TabPanel(
30684 tabPosition: this.bottomTabs ? 'bottom' : 'top',
30685 disableTooltips: this.config.disableTabTips,
30686 toolbar : this.config.toolbar
30689 if(this.config.hideTabs){
30690 ts.stripWrap.setDisplayed(false);
30693 ts.resizeTabs = this.config.resizeTabs === true;
30694 ts.minTabWidth = this.config.minTabWidth || 40;
30695 ts.maxTabWidth = this.config.maxTabWidth || 250;
30696 ts.preferredTabWidth = this.config.preferredTabWidth || 150;
30697 ts.monitorResize = false;
30698 ts.bodyEl.setStyle("overflow", this.config.autoScroll ? "auto" : "hidden");
30699 ts.bodyEl.addClass('x-layout-tabs-body');
30700 this.panels.each(this.initPanelAsTab, this);
30703 initPanelAsTab : function(panel){
30704 var ti = this.tabs.addTab(panel.getEl().id, panel.getTitle(), null,
30705 this.config.closeOnTab && panel.isClosable());
30706 if(panel.tabTip !== undefined){
30707 ti.setTooltip(panel.tabTip);
30709 ti.on("activate", function(){
30710 this.setActivePanel(panel);
30712 if(this.config.closeOnTab){
30713 ti.on("beforeclose", function(t, e){
30715 this.remove(panel);
30721 updatePanelTitle : function(panel, title){
30722 if(this.activePanel == panel){
30723 this.updateTitle(title);
30726 var ti = this.tabs.getTab(panel.getEl().id);
30728 if(panel.tabTip !== undefined){
30729 ti.setTooltip(panel.tabTip);
30734 updateTitle : function(title){
30735 if(this.titleTextEl && !this.config.title){
30736 this.titleTextEl.innerHTML = (typeof title != "undefined" && title.length > 0 ? title : " ");
30740 setActivePanel : function(panel){
30741 panel = this.getPanel(panel);
30742 if(this.activePanel && this.activePanel != panel){
30743 this.activePanel.setActiveState(false);
30745 this.activePanel = panel;
30746 panel.setActiveState(true);
30747 if(this.panelSize){
30748 panel.setSize(this.panelSize.width, this.panelSize.height);
30751 this.closeBtn.setVisible(!this.config.closeOnTab && !this.isSlid && panel.isClosable());
30753 this.updateTitle(panel.getTitle());
30755 this.fireEvent("invalidated", this);
30757 this.fireEvent("panelactivated", this, panel);
30761 * Shows the specified panel.
30762 * @param {Number/String/ContentPanel} panelId The panel's index, id or the panel itself
30763 * @return {Roo.ContentPanel} The shown panel, or null if a panel could not be found from panelId
30765 showPanel : function(panel)
30767 panel = this.getPanel(panel);
30770 var tab = this.tabs.getTab(panel.getEl().id);
30771 if(tab.isHidden()){
30772 this.tabs.unhideTab(tab.id);
30776 this.setActivePanel(panel);
30783 * Get the active panel for this region.
30784 * @return {Roo.ContentPanel} The active panel or null
30786 getActivePanel : function(){
30787 return this.activePanel;
30790 validateVisibility : function(){
30791 if(this.panels.getCount() < 1){
30792 this.updateTitle(" ");
30793 this.closeBtn.hide();
30796 if(!this.isVisible()){
30803 * Adds the passed ContentPanel(s) to this region.
30804 * @param {ContentPanel...} panel The ContentPanel(s) to add (you can pass more than one)
30805 * @return {Roo.ContentPanel} The panel added (if only one was added; null otherwise)
30807 add : function(panel){
30808 if(arguments.length > 1){
30809 for(var i = 0, len = arguments.length; i < len; i++) {
30810 this.add(arguments[i]);
30814 if(this.hasPanel(panel)){
30815 this.showPanel(panel);
30818 panel.setRegion(this);
30819 this.panels.add(panel);
30820 if(this.panels.getCount() == 1 && !this.config.alwaysShowTabs){
30821 this.bodyEl.dom.appendChild(panel.getEl().dom);
30822 if(panel.background !== true){
30823 this.setActivePanel(panel);
30825 this.fireEvent("paneladded", this, panel);
30831 this.initPanelAsTab(panel);
30833 if(panel.background !== true){
30834 this.tabs.activate(panel.getEl().id);
30836 this.fireEvent("paneladded", this, panel);
30841 * Hides the tab for the specified panel.
30842 * @param {Number/String/ContentPanel} panel The panel's index, id or the panel itself
30844 hidePanel : function(panel){
30845 if(this.tabs && (panel = this.getPanel(panel))){
30846 this.tabs.hideTab(panel.getEl().id);
30851 * Unhides the tab for a previously hidden panel.
30852 * @param {Number/String/ContentPanel} panel The panel's index, id or the panel itself
30854 unhidePanel : function(panel){
30855 if(this.tabs && (panel = this.getPanel(panel))){
30856 this.tabs.unhideTab(panel.getEl().id);
30860 clearPanels : function(){
30861 while(this.panels.getCount() > 0){
30862 this.remove(this.panels.first());
30867 * Removes the specified panel. If preservePanel is not true (either here or in the config), the panel is destroyed.
30868 * @param {Number/String/ContentPanel} panel The panel's index, id or the panel itself
30869 * @param {Boolean} preservePanel Overrides the config preservePanel option
30870 * @return {Roo.ContentPanel} The panel that was removed
30872 remove : function(panel, preservePanel){
30873 panel = this.getPanel(panel);
30878 this.fireEvent("beforeremove", this, panel, e);
30879 if(e.cancel === true){
30882 preservePanel = (typeof preservePanel != "undefined" ? preservePanel : (this.config.preservePanels === true || panel.preserve === true));
30883 var panelId = panel.getId();
30884 this.panels.removeKey(panelId);
30886 document.body.appendChild(panel.getEl().dom);
30889 this.tabs.removeTab(panel.getEl().id);
30890 }else if (!preservePanel){
30891 this.bodyEl.dom.removeChild(panel.getEl().dom);
30893 if(this.panels.getCount() == 1 && this.tabs && !this.config.alwaysShowTabs){
30894 var p = this.panels.first();
30895 var tempEl = document.createElement("div"); // temp holder to keep IE from deleting the node
30896 tempEl.appendChild(p.getEl().dom);
30897 this.bodyEl.update("");
30898 this.bodyEl.dom.appendChild(p.getEl().dom);
30900 this.updateTitle(p.getTitle());
30902 this.bodyEl.setStyle("overflow", this.config.autoScroll ? "auto" : "hidden");
30903 this.setActivePanel(p);
30905 panel.setRegion(null);
30906 if(this.activePanel == panel){
30907 this.activePanel = null;
30909 if(this.config.autoDestroy !== false && preservePanel !== true){
30910 try{panel.destroy();}catch(e){}
30912 this.fireEvent("panelremoved", this, panel);
30917 * Returns the TabPanel component used by this region
30918 * @return {Roo.TabPanel}
30920 getTabs : function(){
30924 createTool : function(parentEl, className){
30925 var btn = Roo.DomHelper.append(parentEl, {tag: "div", cls: "x-layout-tools-button",
30926 children: [{tag: "div", cls: "x-layout-tools-button-inner " + className, html: " "}]}, true);
30927 btn.addClassOnOver("x-layout-tools-button-over");
30932 * Ext JS Library 1.1.1
30933 * Copyright(c) 2006-2007, Ext JS, LLC.
30935 * Originally Released Under LGPL - original licence link has changed is not relivant.
30938 * <script type="text/javascript">
30944 * @class Roo.SplitLayoutRegion
30945 * @extends Roo.LayoutRegion
30946 * Adds a splitbar and other (private) useful functionality to a {@link Roo.LayoutRegion}.
30948 Roo.SplitLayoutRegion = function(mgr, config, pos, cursor){
30949 this.cursor = cursor;
30950 Roo.SplitLayoutRegion.superclass.constructor.call(this, mgr, config, pos);
30953 Roo.extend(Roo.SplitLayoutRegion, Roo.LayoutRegion, {
30954 splitTip : "Drag to resize.",
30955 collapsibleSplitTip : "Drag to resize. Double click to hide.",
30956 useSplitTips : false,
30958 applyConfig : function(config){
30959 Roo.SplitLayoutRegion.superclass.applyConfig.call(this, config);
30962 var splitEl = Roo.DomHelper.append(this.mgr.el.dom,
30963 {tag: "div", id: this.el.id + "-split", cls: "x-layout-split x-layout-split-"+this.position, html: " "});
30964 /** The SplitBar for this region
30965 * @type Roo.SplitBar */
30966 this.split = new Roo.SplitBar(splitEl, this.el, this.orientation);
30967 this.split.on("moved", this.onSplitMove, this);
30968 this.split.useShim = config.useShim === true;
30969 this.split.getMaximumSize = this[this.position == 'north' || this.position == 'south' ? 'getVMaxSize' : 'getHMaxSize'].createDelegate(this);
30970 if(this.useSplitTips){
30971 this.split.el.dom.title = config.collapsible ? this.collapsibleSplitTip : this.splitTip;
30973 if(config.collapsible){
30974 this.split.el.on("dblclick", this.collapse, this);
30977 if(typeof config.minSize != "undefined"){
30978 this.split.minSize = config.minSize;
30980 if(typeof config.maxSize != "undefined"){
30981 this.split.maxSize = config.maxSize;
30983 if(config.hideWhenEmpty || config.hidden || config.collapsed){
30984 this.hideSplitter();
30989 getHMaxSize : function(){
30990 var cmax = this.config.maxSize || 10000;
30991 var center = this.mgr.getRegion("center");
30992 return Math.min(cmax, (this.el.getWidth()+center.getEl().getWidth())-center.getMinWidth());
30995 getVMaxSize : function(){
30996 var cmax = this.config.maxSize || 10000;
30997 var center = this.mgr.getRegion("center");
30998 return Math.min(cmax, (this.el.getHeight()+center.getEl().getHeight())-center.getMinHeight());
31001 onSplitMove : function(split, newSize){
31002 this.fireEvent("resized", this, newSize);
31006 * Returns the {@link Roo.SplitBar} for this region.
31007 * @return {Roo.SplitBar}
31009 getSplitBar : function(){
31014 this.hideSplitter();
31015 Roo.SplitLayoutRegion.superclass.hide.call(this);
31018 hideSplitter : function(){
31020 this.split.el.setLocation(-2000,-2000);
31021 this.split.el.hide();
31027 this.split.el.show();
31029 Roo.SplitLayoutRegion.superclass.show.call(this);
31032 beforeSlide: function(){
31033 if(Roo.isGecko){// firefox overflow auto bug workaround
31034 this.bodyEl.clip();
31036 this.tabs.bodyEl.clip();
31038 if(this.activePanel){
31039 this.activePanel.getEl().clip();
31041 if(this.activePanel.beforeSlide){
31042 this.activePanel.beforeSlide();
31048 afterSlide : function(){
31049 if(Roo.isGecko){// firefox overflow auto bug workaround
31050 this.bodyEl.unclip();
31052 this.tabs.bodyEl.unclip();
31054 if(this.activePanel){
31055 this.activePanel.getEl().unclip();
31056 if(this.activePanel.afterSlide){
31057 this.activePanel.afterSlide();
31063 initAutoHide : function(){
31064 if(this.autoHide !== false){
31065 if(!this.autoHideHd){
31066 var st = new Roo.util.DelayedTask(this.slideIn, this);
31067 this.autoHideHd = {
31068 "mouseout": function(e){
31069 if(!e.within(this.el, true)){
31073 "mouseover" : function(e){
31079 this.el.on(this.autoHideHd);
31083 clearAutoHide : function(){
31084 if(this.autoHide !== false){
31085 this.el.un("mouseout", this.autoHideHd.mouseout);
31086 this.el.un("mouseover", this.autoHideHd.mouseover);
31090 clearMonitor : function(){
31091 Roo.get(document).un("click", this.slideInIf, this);
31094 // these names are backwards but not changed for compat
31095 slideOut : function(){
31096 if(this.isSlid || this.el.hasActiveFx()){
31099 this.isSlid = true;
31100 if(this.collapseBtn){
31101 this.collapseBtn.hide();
31103 this.closeBtnState = this.closeBtn.getStyle('display');
31104 this.closeBtn.hide();
31106 this.stickBtn.show();
31109 this.el.alignTo(this.collapsedEl, this.getCollapseAnchor());
31110 this.beforeSlide();
31111 this.el.setStyle("z-index", 10001);
31112 this.el.slideIn(this.getSlideAnchor(), {
31113 callback: function(){
31115 this.initAutoHide();
31116 Roo.get(document).on("click", this.slideInIf, this);
31117 this.fireEvent("slideshow", this);
31124 afterSlideIn : function(){
31125 this.clearAutoHide();
31126 this.isSlid = false;
31127 this.clearMonitor();
31128 this.el.setStyle("z-index", "");
31129 if(this.collapseBtn){
31130 this.collapseBtn.show();
31132 this.closeBtn.setStyle('display', this.closeBtnState);
31134 this.stickBtn.hide();
31136 this.fireEvent("slidehide", this);
31139 slideIn : function(cb){
31140 if(!this.isSlid || this.el.hasActiveFx()){
31144 this.isSlid = false;
31145 this.beforeSlide();
31146 this.el.slideOut(this.getSlideAnchor(), {
31147 callback: function(){
31148 this.el.setLeftTop(-10000, -10000);
31150 this.afterSlideIn();
31158 slideInIf : function(e){
31159 if(!e.within(this.el)){
31164 animateCollapse : function(){
31165 this.beforeSlide();
31166 this.el.setStyle("z-index", 20000);
31167 var anchor = this.getSlideAnchor();
31168 this.el.slideOut(anchor, {
31169 callback : function(){
31170 this.el.setStyle("z-index", "");
31171 this.collapsedEl.slideIn(anchor, {duration:.3});
31173 this.el.setLocation(-10000,-10000);
31175 this.fireEvent("collapsed", this);
31182 animateExpand : function(){
31183 this.beforeSlide();
31184 this.el.alignTo(this.collapsedEl, this.getCollapseAnchor(), this.getExpandAdj());
31185 this.el.setStyle("z-index", 20000);
31186 this.collapsedEl.hide({
31189 this.el.slideIn(this.getSlideAnchor(), {
31190 callback : function(){
31191 this.el.setStyle("z-index", "");
31194 this.split.el.show();
31196 this.fireEvent("invalidated", this);
31197 this.fireEvent("expanded", this);
31225 getAnchor : function(){
31226 return this.anchors[this.position];
31229 getCollapseAnchor : function(){
31230 return this.canchors[this.position];
31233 getSlideAnchor : function(){
31234 return this.sanchors[this.position];
31237 getAlignAdj : function(){
31238 var cm = this.cmargins;
31239 switch(this.position){
31255 getExpandAdj : function(){
31256 var c = this.collapsedEl, cm = this.cmargins;
31257 switch(this.position){
31259 return [-(cm.right+c.getWidth()+cm.left), 0];
31262 return [cm.right+c.getWidth()+cm.left, 0];
31265 return [0, -(cm.top+cm.bottom+c.getHeight())];
31268 return [0, cm.top+cm.bottom+c.getHeight()];
31274 * Ext JS Library 1.1.1
31275 * Copyright(c) 2006-2007, Ext JS, LLC.
31277 * Originally Released Under LGPL - original licence link has changed is not relivant.
31280 * <script type="text/javascript">
31283 * These classes are private internal classes
31285 Roo.CenterLayoutRegion = function(mgr, config){
31286 Roo.LayoutRegion.call(this, mgr, config, "center");
31287 this.visible = true;
31288 this.minWidth = config.minWidth || 20;
31289 this.minHeight = config.minHeight || 20;
31292 Roo.extend(Roo.CenterLayoutRegion, Roo.LayoutRegion, {
31294 // center panel can't be hidden
31298 // center panel can't be hidden
31301 getMinWidth: function(){
31302 return this.minWidth;
31305 getMinHeight: function(){
31306 return this.minHeight;
31311 Roo.NorthLayoutRegion = function(mgr, config){
31312 Roo.LayoutRegion.call(this, mgr, config, "north", "n-resize");
31314 this.split.placement = Roo.SplitBar.TOP;
31315 this.split.orientation = Roo.SplitBar.VERTICAL;
31316 this.split.el.addClass("x-layout-split-v");
31318 var size = config.initialSize || config.height;
31319 if(typeof size != "undefined"){
31320 this.el.setHeight(size);
31323 Roo.extend(Roo.NorthLayoutRegion, Roo.SplitLayoutRegion, {
31324 orientation: Roo.SplitBar.VERTICAL,
31325 getBox : function(){
31326 if(this.collapsed){
31327 return this.collapsedEl.getBox();
31329 var box = this.el.getBox();
31331 box.height += this.split.el.getHeight();
31336 updateBox : function(box){
31337 if(this.split && !this.collapsed){
31338 box.height -= this.split.el.getHeight();
31339 this.split.el.setLeft(box.x);
31340 this.split.el.setTop(box.y+box.height);
31341 this.split.el.setWidth(box.width);
31343 if(this.collapsed){
31344 this.updateBody(box.width, null);
31346 Roo.LayoutRegion.prototype.updateBox.call(this, box);
31350 Roo.SouthLayoutRegion = function(mgr, config){
31351 Roo.SplitLayoutRegion.call(this, mgr, config, "south", "s-resize");
31353 this.split.placement = Roo.SplitBar.BOTTOM;
31354 this.split.orientation = Roo.SplitBar.VERTICAL;
31355 this.split.el.addClass("x-layout-split-v");
31357 var size = config.initialSize || config.height;
31358 if(typeof size != "undefined"){
31359 this.el.setHeight(size);
31362 Roo.extend(Roo.SouthLayoutRegion, Roo.SplitLayoutRegion, {
31363 orientation: Roo.SplitBar.VERTICAL,
31364 getBox : function(){
31365 if(this.collapsed){
31366 return this.collapsedEl.getBox();
31368 var box = this.el.getBox();
31370 var sh = this.split.el.getHeight();
31377 updateBox : function(box){
31378 if(this.split && !this.collapsed){
31379 var sh = this.split.el.getHeight();
31382 this.split.el.setLeft(box.x);
31383 this.split.el.setTop(box.y-sh);
31384 this.split.el.setWidth(box.width);
31386 if(this.collapsed){
31387 this.updateBody(box.width, null);
31389 Roo.LayoutRegion.prototype.updateBox.call(this, box);
31393 Roo.EastLayoutRegion = function(mgr, config){
31394 Roo.SplitLayoutRegion.call(this, mgr, config, "east", "e-resize");
31396 this.split.placement = Roo.SplitBar.RIGHT;
31397 this.split.orientation = Roo.SplitBar.HORIZONTAL;
31398 this.split.el.addClass("x-layout-split-h");
31400 var size = config.initialSize || config.width;
31401 if(typeof size != "undefined"){
31402 this.el.setWidth(size);
31405 Roo.extend(Roo.EastLayoutRegion, Roo.SplitLayoutRegion, {
31406 orientation: Roo.SplitBar.HORIZONTAL,
31407 getBox : function(){
31408 if(this.collapsed){
31409 return this.collapsedEl.getBox();
31411 var box = this.el.getBox();
31413 var sw = this.split.el.getWidth();
31420 updateBox : function(box){
31421 if(this.split && !this.collapsed){
31422 var sw = this.split.el.getWidth();
31424 this.split.el.setLeft(box.x);
31425 this.split.el.setTop(box.y);
31426 this.split.el.setHeight(box.height);
31429 if(this.collapsed){
31430 this.updateBody(null, box.height);
31432 Roo.LayoutRegion.prototype.updateBox.call(this, box);
31436 Roo.WestLayoutRegion = function(mgr, config){
31437 Roo.SplitLayoutRegion.call(this, mgr, config, "west", "w-resize");
31439 this.split.placement = Roo.SplitBar.LEFT;
31440 this.split.orientation = Roo.SplitBar.HORIZONTAL;
31441 this.split.el.addClass("x-layout-split-h");
31443 var size = config.initialSize || config.width;
31444 if(typeof size != "undefined"){
31445 this.el.setWidth(size);
31448 Roo.extend(Roo.WestLayoutRegion, Roo.SplitLayoutRegion, {
31449 orientation: Roo.SplitBar.HORIZONTAL,
31450 getBox : function(){
31451 if(this.collapsed){
31452 return this.collapsedEl.getBox();
31454 var box = this.el.getBox();
31456 box.width += this.split.el.getWidth();
31461 updateBox : function(box){
31462 if(this.split && !this.collapsed){
31463 var sw = this.split.el.getWidth();
31465 this.split.el.setLeft(box.x+box.width);
31466 this.split.el.setTop(box.y);
31467 this.split.el.setHeight(box.height);
31469 if(this.collapsed){
31470 this.updateBody(null, box.height);
31472 Roo.LayoutRegion.prototype.updateBox.call(this, box);
31477 * Ext JS Library 1.1.1
31478 * Copyright(c) 2006-2007, Ext JS, LLC.
31480 * Originally Released Under LGPL - original licence link has changed is not relivant.
31483 * <script type="text/javascript">
31488 * Private internal class for reading and applying state
31490 Roo.LayoutStateManager = function(layout){
31491 // default empty state
31500 Roo.LayoutStateManager.prototype = {
31501 init : function(layout, provider){
31502 this.provider = provider;
31503 var state = provider.get(layout.id+"-layout-state");
31505 var wasUpdating = layout.isUpdating();
31507 layout.beginUpdate();
31509 for(var key in state){
31510 if(typeof state[key] != "function"){
31511 var rstate = state[key];
31512 var r = layout.getRegion(key);
31515 r.resizeTo(rstate.size);
31517 if(rstate.collapsed == true){
31520 r.expand(null, true);
31526 layout.endUpdate();
31528 this.state = state;
31530 this.layout = layout;
31531 layout.on("regionresized", this.onRegionResized, this);
31532 layout.on("regioncollapsed", this.onRegionCollapsed, this);
31533 layout.on("regionexpanded", this.onRegionExpanded, this);
31536 storeState : function(){
31537 this.provider.set(this.layout.id+"-layout-state", this.state);
31540 onRegionResized : function(region, newSize){
31541 this.state[region.getPosition()].size = newSize;
31545 onRegionCollapsed : function(region){
31546 this.state[region.getPosition()].collapsed = true;
31550 onRegionExpanded : function(region){
31551 this.state[region.getPosition()].collapsed = false;
31556 * Ext JS Library 1.1.1
31557 * Copyright(c) 2006-2007, Ext JS, LLC.
31559 * Originally Released Under LGPL - original licence link has changed is not relivant.
31562 * <script type="text/javascript">
31565 * @class Roo.ContentPanel
31566 * @extends Roo.util.Observable
31567 * A basic ContentPanel element.
31568 * @cfg {Boolean} fitToFrame True for this panel to adjust its size to fit when the region resizes (defaults to false)
31569 * @cfg {Boolean} fitContainer When using {@link #fitToFrame} and {@link #resizeEl}, you can also fit the parent container (defaults to false)
31570 * @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
31571 * @cfg {Boolean} closable True if the panel can be closed/removed
31572 * @cfg {Boolean} background True if the panel should not be activated when it is added (defaults to false)
31573 * @cfg {String/HTMLElement/Element} resizeEl An element to resize if {@link #fitToFrame} is true (instead of this panel's element)
31574 * @cfg {Toolbar} toolbar A toolbar for this panel
31575 * @cfg {Boolean} autoScroll True to scroll overflow in this panel (use with {@link #fitToFrame})
31576 * @cfg {String} title The title for this panel
31577 * @cfg {Array} adjustments Values to <b>add</b> to the width/height when doing a {@link #fitToFrame} (default is [0, 0])
31578 * @cfg {String} url Calls {@link #setUrl} with this value
31579 * @cfg {String} region (center|north|south|east|west) which region to put this panel on (when used with xtype constructors)
31580 * @cfg {String/Object} params When used with {@link #url}, calls {@link #setUrl} with this value
31581 * @cfg {Boolean} loadOnce When used with {@link #url}, calls {@link #setUrl} with this value
31582 * @cfg {String} content Raw content to fill content panel with (uses setContent on construction.)
31585 * Create a new ContentPanel.
31586 * @param {String/HTMLElement/Roo.Element} el The container element for this panel
31587 * @param {String/Object} config A string to set only the title or a config object
31588 * @param {String} content (optional) Set the HTML content for this panel
31589 * @param {String} region (optional) Used by xtype constructors to add to regions. (values center,east,west,south,north)
31591 Roo.ContentPanel = function(el, config, content){
31595 if(el.autoCreate || el.xtype){ // xtype is available if this is called from factory
31599 if (config && config.parentLayout) {
31600 el = config.parentLayout.el.createChild();
31603 if(el.autoCreate){ // xtype is available if this is called from factory
31607 this.el = Roo.get(el);
31608 if(!this.el && config && config.autoCreate){
31609 if(typeof config.autoCreate == "object"){
31610 if(!config.autoCreate.id){
31611 config.autoCreate.id = config.id||el;
31613 this.el = Roo.DomHelper.append(document.body,
31614 config.autoCreate, true);
31616 this.el = Roo.DomHelper.append(document.body,
31617 {tag: "div", cls: "x-layout-inactive-content", id: config.id||el}, true);
31620 this.closable = false;
31621 this.loaded = false;
31622 this.active = false;
31623 if(typeof config == "string"){
31624 this.title = config;
31626 Roo.apply(this, config);
31629 if (this.toolbar && !this.toolbar.el && this.toolbar.xtype) {
31630 this.wrapEl = this.el.wrap();
31631 this.toolbar.container = this.el.insertSibling(false, 'before');
31632 this.toolbar = new Roo.Toolbar(this.toolbar);
31635 // xtype created footer. - not sure if will work as we normally have to render first..
31636 if (this.footer && !this.footer.el && this.footer.xtype) {
31637 if (!this.wrapEl) {
31638 this.wrapEl = this.el.wrap();
31641 this.footer.container = this.wrapEl.createChild();
31643 this.footer = Roo.factory(this.footer, Roo);
31648 this.resizeEl = Roo.get(this.resizeEl, true);
31650 this.resizeEl = this.el;
31652 // handle view.xtype
31660 * Fires when this panel is activated.
31661 * @param {Roo.ContentPanel} this
31665 * @event deactivate
31666 * Fires when this panel is activated.
31667 * @param {Roo.ContentPanel} this
31669 "deactivate" : true,
31673 * Fires when this panel is resized if fitToFrame is true.
31674 * @param {Roo.ContentPanel} this
31675 * @param {Number} width The width after any component adjustments
31676 * @param {Number} height The height after any component adjustments
31682 * Fires when this tab is created
31683 * @param {Roo.ContentPanel} this
31693 if(this.autoScroll){
31694 this.resizeEl.setStyle("overflow", "auto");
31696 // fix randome scrolling
31697 this.el.on('scroll', function() {
31698 Roo.log('fix random scolling');
31699 this.scrollTo('top',0);
31702 content = content || this.content;
31704 this.setContent(content);
31706 if(config && config.url){
31707 this.setUrl(this.url, this.params, this.loadOnce);
31712 Roo.ContentPanel.superclass.constructor.call(this);
31714 if (this.view && typeof(this.view.xtype) != 'undefined') {
31715 this.view.el = this.el.appendChild(document.createElement("div"));
31716 this.view = Roo.factory(this.view);
31717 this.view.render && this.view.render(false, '');
31721 this.fireEvent('render', this);
31724 Roo.extend(Roo.ContentPanel, Roo.util.Observable, {
31726 setRegion : function(region){
31727 this.region = region;
31729 this.el.replaceClass("x-layout-inactive-content", "x-layout-active-content");
31731 this.el.replaceClass("x-layout-active-content", "x-layout-inactive-content");
31736 * Returns the toolbar for this Panel if one was configured.
31737 * @return {Roo.Toolbar}
31739 getToolbar : function(){
31740 return this.toolbar;
31743 setActiveState : function(active){
31744 this.active = active;
31746 this.fireEvent("deactivate", this);
31748 this.fireEvent("activate", this);
31752 * Updates this panel's element
31753 * @param {String} content The new content
31754 * @param {Boolean} loadScripts (optional) true to look for and process scripts
31756 setContent : function(content, loadScripts){
31757 this.el.update(content, loadScripts);
31760 ignoreResize : function(w, h){
31761 if(this.lastSize && this.lastSize.width == w && this.lastSize.height == h){
31764 this.lastSize = {width: w, height: h};
31769 * Get the {@link Roo.UpdateManager} for this panel. Enables you to perform Ajax updates.
31770 * @return {Roo.UpdateManager} The UpdateManager
31772 getUpdateManager : function(){
31773 return this.el.getUpdateManager();
31776 * Loads this content panel immediately with content from XHR. Note: to delay loading until the panel is activated, use {@link #setUrl}.
31777 * @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:
31780 url: "your-url.php",
31781 params: {param1: "foo", param2: "bar"}, // or a URL encoded string
31782 callback: yourFunction,
31783 scope: yourObject, //(optional scope)
31786 text: "Loading...",
31791 * The only required property is <i>url</i>. The optional properties <i>nocache</i>, <i>text</i> and <i>scripts</i>
31792 * 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.
31793 * @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}
31794 * @param {Function} callback (optional) Callback when transaction is complete -- called with signature (oElement, bSuccess, oResponse)
31795 * @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.
31796 * @return {Roo.ContentPanel} this
31799 var um = this.el.getUpdateManager();
31800 um.update.apply(um, arguments);
31806 * 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.
31807 * @param {String/Function} url The URL to load the content from or a function to call to get the URL
31808 * @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)
31809 * @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)
31810 * @return {Roo.UpdateManager} The UpdateManager
31812 setUrl : function(url, params, loadOnce){
31813 if(this.refreshDelegate){
31814 this.removeListener("activate", this.refreshDelegate);
31816 this.refreshDelegate = this._handleRefresh.createDelegate(this, [url, params, loadOnce]);
31817 this.on("activate", this.refreshDelegate);
31818 return this.el.getUpdateManager();
31821 _handleRefresh : function(url, params, loadOnce){
31822 if(!loadOnce || !this.loaded){
31823 var updater = this.el.getUpdateManager();
31824 updater.update(url, params, this._setLoaded.createDelegate(this));
31828 _setLoaded : function(){
31829 this.loaded = true;
31833 * Returns this panel's id
31836 getId : function(){
31841 * Returns this panel's element - used by regiosn to add.
31842 * @return {Roo.Element}
31844 getEl : function(){
31845 return this.wrapEl || this.el;
31848 adjustForComponents : function(width, height)
31850 //Roo.log('adjustForComponents ');
31851 if(this.resizeEl != this.el){
31852 width -= this.el.getFrameWidth('lr');
31853 height -= this.el.getFrameWidth('tb');
31856 var te = this.toolbar.getEl();
31857 height -= te.getHeight();
31858 te.setWidth(width);
31861 var te = this.footer.getEl();
31862 //Roo.log("footer:" + te.getHeight());
31864 height -= te.getHeight();
31865 te.setWidth(width);
31869 if(this.adjustments){
31870 width += this.adjustments[0];
31871 height += this.adjustments[1];
31873 return {"width": width, "height": height};
31876 setSize : function(width, height){
31877 if(this.fitToFrame && !this.ignoreResize(width, height)){
31878 if(this.fitContainer && this.resizeEl != this.el){
31879 this.el.setSize(width, height);
31881 var size = this.adjustForComponents(width, height);
31882 this.resizeEl.setSize(this.autoWidth ? "auto" : size.width, this.autoHeight ? "auto" : size.height);
31883 this.fireEvent('resize', this, size.width, size.height);
31888 * Returns this panel's title
31891 getTitle : function(){
31896 * Set this panel's title
31897 * @param {String} title
31899 setTitle : function(title){
31900 this.title = title;
31902 this.region.updatePanelTitle(this, title);
31907 * Returns true is this panel was configured to be closable
31908 * @return {Boolean}
31910 isClosable : function(){
31911 return this.closable;
31914 beforeSlide : function(){
31916 this.resizeEl.clip();
31919 afterSlide : function(){
31921 this.resizeEl.unclip();
31925 * Force a content refresh from the URL specified in the {@link #setUrl} method.
31926 * Will fail silently if the {@link #setUrl} method has not been called.
31927 * This does not activate the panel, just updates its content.
31929 refresh : function(){
31930 if(this.refreshDelegate){
31931 this.loaded = false;
31932 this.refreshDelegate();
31937 * Destroys this panel
31939 destroy : function(){
31940 this.el.removeAllListeners();
31941 var tempEl = document.createElement("span");
31942 tempEl.appendChild(this.el.dom);
31943 tempEl.innerHTML = "";
31949 * form - if the content panel contains a form - this is a reference to it.
31950 * @type {Roo.form.Form}
31954 * view - if the content panel contains a view (Roo.DatePicker / Roo.View / Roo.JsonView)
31955 * This contains a reference to it.
31961 * Adds a xtype elements to the panel - currently only supports Forms, View, JsonView.
31971 * @param {Object} cfg Xtype definition of item to add.
31974 addxtype : function(cfg) {
31976 if (cfg.xtype.match(/^Form$/)) {
31979 //if (this.footer) {
31980 // el = this.footer.container.insertSibling(false, 'before');
31982 el = this.el.createChild();
31985 this.form = new Roo.form.Form(cfg);
31988 if ( this.form.allItems.length) {
31989 this.form.render(el.dom);
31993 // should only have one of theses..
31994 if ([ 'View', 'JsonView', 'DatePicker'].indexOf(cfg.xtype) > -1) {
31995 // views.. should not be just added - used named prop 'view''
31997 cfg.el = this.el.appendChild(document.createElement("div"));
32000 var ret = new Roo.factory(cfg);
32002 ret.render && ret.render(false, ''); // render blank..
32011 * @class Roo.GridPanel
32012 * @extends Roo.ContentPanel
32014 * Create a new GridPanel.
32015 * @param {Roo.grid.Grid} grid The grid for this panel
32016 * @param {String/Object} config A string to set only the panel's title, or a config object
32018 Roo.GridPanel = function(grid, config){
32021 this.wrapper = Roo.DomHelper.append(document.body, // wrapper for IE7 strict & safari scroll issue
32022 {tag: "div", cls: "x-layout-grid-wrapper x-layout-inactive-content"}, true);
32024 this.wrapper.dom.appendChild(grid.getGridEl().dom);
32026 Roo.GridPanel.superclass.constructor.call(this, this.wrapper, config);
32029 this.toolbar.el.insertBefore(this.wrapper.dom.firstChild);
32031 // xtype created footer. - not sure if will work as we normally have to render first..
32032 if (this.footer && !this.footer.el && this.footer.xtype) {
32034 this.footer.container = this.grid.getView().getFooterPanel(true);
32035 this.footer.dataSource = this.grid.dataSource;
32036 this.footer = Roo.factory(this.footer, Roo);
32040 grid.monitorWindowResize = false; // turn off autosizing
32041 grid.autoHeight = false;
32042 grid.autoWidth = false;
32044 this.grid.getGridEl().replaceClass("x-layout-inactive-content", "x-layout-component-panel");
32047 Roo.extend(Roo.GridPanel, Roo.ContentPanel, {
32048 getId : function(){
32049 return this.grid.id;
32053 * Returns the grid for this panel
32054 * @return {Roo.grid.Grid}
32056 getGrid : function(){
32060 setSize : function(width, height){
32061 if(!this.ignoreResize(width, height)){
32062 var grid = this.grid;
32063 var size = this.adjustForComponents(width, height);
32064 grid.getGridEl().setSize(size.width, size.height);
32069 beforeSlide : function(){
32070 this.grid.getView().scroller.clip();
32073 afterSlide : function(){
32074 this.grid.getView().scroller.unclip();
32077 destroy : function(){
32078 this.grid.destroy();
32080 Roo.GridPanel.superclass.destroy.call(this);
32086 * @class Roo.NestedLayoutPanel
32087 * @extends Roo.ContentPanel
32089 * Create a new NestedLayoutPanel.
32092 * @param {Roo.BorderLayout} layout The layout for this panel
32093 * @param {String/Object} config A string to set only the title or a config object
32095 Roo.NestedLayoutPanel = function(layout, config)
32097 // construct with only one argument..
32098 /* FIXME - implement nicer consturctors
32099 if (layout.layout) {
32101 layout = config.layout;
32102 delete config.layout;
32104 if (layout.xtype && !layout.getEl) {
32105 // then layout needs constructing..
32106 layout = Roo.factory(layout, Roo);
32111 Roo.NestedLayoutPanel.superclass.constructor.call(this, layout.getEl(), config);
32113 layout.monitorWindowResize = false; // turn off autosizing
32114 this.layout = layout;
32115 this.layout.getEl().addClass("x-layout-nested-layout");
32122 Roo.extend(Roo.NestedLayoutPanel, Roo.ContentPanel, {
32124 setSize : function(width, height){
32125 if(!this.ignoreResize(width, height)){
32126 var size = this.adjustForComponents(width, height);
32127 var el = this.layout.getEl();
32128 el.setSize(size.width, size.height);
32129 var touch = el.dom.offsetWidth;
32130 this.layout.layout();
32131 // ie requires a double layout on the first pass
32132 if(Roo.isIE && !this.initialized){
32133 this.initialized = true;
32134 this.layout.layout();
32139 // activate all subpanels if not currently active..
32141 setActiveState : function(active){
32142 this.active = active;
32144 this.fireEvent("deactivate", this);
32148 this.fireEvent("activate", this);
32149 // not sure if this should happen before or after..
32150 if (!this.layout) {
32151 return; // should not happen..
32154 for (var r in this.layout.regions) {
32155 reg = this.layout.getRegion(r);
32156 if (reg.getActivePanel()) {
32157 //reg.showPanel(reg.getActivePanel()); // force it to activate..
32158 reg.setActivePanel(reg.getActivePanel());
32161 if (!reg.panels.length) {
32164 reg.showPanel(reg.getPanel(0));
32173 * Returns the nested BorderLayout for this panel
32174 * @return {Roo.BorderLayout}
32176 getLayout : function(){
32177 return this.layout;
32181 * Adds a xtype elements to the layout of the nested panel
32185 xtype : 'ContentPanel',
32192 xtype : 'NestedLayoutPanel',
32198 items : [ ... list of content panels or nested layout panels.. ]
32202 * @param {Object} cfg Xtype definition of item to add.
32204 addxtype : function(cfg) {
32205 return this.layout.addxtype(cfg);
32210 Roo.ScrollPanel = function(el, config, content){
32211 config = config || {};
32212 config.fitToFrame = true;
32213 Roo.ScrollPanel.superclass.constructor.call(this, el, config, content);
32215 this.el.dom.style.overflow = "hidden";
32216 var wrap = this.el.wrap({cls: "x-scroller x-layout-inactive-content"});
32217 this.el.removeClass("x-layout-inactive-content");
32218 this.el.on("mousewheel", this.onWheel, this);
32220 var up = wrap.createChild({cls: "x-scroller-up", html: " "}, this.el.dom);
32221 var down = wrap.createChild({cls: "x-scroller-down", html: " "});
32222 up.unselectable(); down.unselectable();
32223 up.on("click", this.scrollUp, this);
32224 down.on("click", this.scrollDown, this);
32225 up.addClassOnOver("x-scroller-btn-over");
32226 down.addClassOnOver("x-scroller-btn-over");
32227 up.addClassOnClick("x-scroller-btn-click");
32228 down.addClassOnClick("x-scroller-btn-click");
32229 this.adjustments = [0, -(up.getHeight() + down.getHeight())];
32231 this.resizeEl = this.el;
32232 this.el = wrap; this.up = up; this.down = down;
32235 Roo.extend(Roo.ScrollPanel, Roo.ContentPanel, {
32237 wheelIncrement : 5,
32238 scrollUp : function(){
32239 this.resizeEl.scroll("up", this.increment, {callback: this.afterScroll, scope: this});
32242 scrollDown : function(){
32243 this.resizeEl.scroll("down", this.increment, {callback: this.afterScroll, scope: this});
32246 afterScroll : function(){
32247 var el = this.resizeEl;
32248 var t = el.dom.scrollTop, h = el.dom.scrollHeight, ch = el.dom.clientHeight;
32249 this.up[t == 0 ? "addClass" : "removeClass"]("x-scroller-btn-disabled");
32250 this.down[h - t <= ch ? "addClass" : "removeClass"]("x-scroller-btn-disabled");
32253 setSize : function(){
32254 Roo.ScrollPanel.superclass.setSize.apply(this, arguments);
32255 this.afterScroll();
32258 onWheel : function(e){
32259 var d = e.getWheelDelta();
32260 this.resizeEl.dom.scrollTop -= (d*this.wheelIncrement);
32261 this.afterScroll();
32265 setContent : function(content, loadScripts){
32266 this.resizeEl.update(content, loadScripts);
32280 * @class Roo.TreePanel
32281 * @extends Roo.ContentPanel
32283 * Create a new TreePanel. - defaults to fit/scoll contents.
32284 * @param {String/Object} config A string to set only the panel's title, or a config object
32285 * @cfg {Roo.tree.TreePanel} tree The tree TreePanel, with config etc.
32287 Roo.TreePanel = function(config){
32288 var el = config.el;
32289 var tree = config.tree;
32290 delete config.tree;
32291 delete config.el; // hopefull!
32293 // wrapper for IE7 strict & safari scroll issue
32295 var treeEl = el.createChild();
32296 config.resizeEl = treeEl;
32300 Roo.TreePanel.superclass.constructor.call(this, el, config);
32303 this.tree = new Roo.tree.TreePanel(treeEl , tree);
32304 //console.log(tree);
32305 this.on('activate', function()
32307 if (this.tree.rendered) {
32310 //console.log('render tree');
32311 this.tree.render();
32313 // this should not be needed.. - it's actually the 'el' that resizes?
32314 // actuall it breaks the containerScroll - dragging nodes auto scroll at top
32316 //this.on('resize', function (cp, w, h) {
32317 // this.tree.innerCt.setWidth(w);
32318 // this.tree.innerCt.setHeight(h);
32319 // //this.tree.innerCt.setStyle('overflow-y', 'auto');
32326 Roo.extend(Roo.TreePanel, Roo.ContentPanel, {
32343 * Ext JS Library 1.1.1
32344 * Copyright(c) 2006-2007, Ext JS, LLC.
32346 * Originally Released Under LGPL - original licence link has changed is not relivant.
32349 * <script type="text/javascript">
32354 * @class Roo.ReaderLayout
32355 * @extends Roo.BorderLayout
32356 * This is a pre-built layout that represents a classic, 5-pane application. It consists of a header, a primary
32357 * center region containing two nested regions (a top one for a list view and one for item preview below),
32358 * and regions on either side that can be used for navigation, application commands, informational displays, etc.
32359 * The setup and configuration work exactly the same as it does for a {@link Roo.BorderLayout} - this class simply
32360 * expedites the setup of the overall layout and regions for this common application style.
32363 var reader = new Roo.ReaderLayout();
32364 var CP = Roo.ContentPanel; // shortcut for adding
32366 reader.beginUpdate();
32367 reader.add("north", new CP("north", "North"));
32368 reader.add("west", new CP("west", {title: "West"}));
32369 reader.add("east", new CP("east", {title: "East"}));
32371 reader.regions.listView.add(new CP("listView", "List"));
32372 reader.regions.preview.add(new CP("preview", "Preview"));
32373 reader.endUpdate();
32376 * Create a new ReaderLayout
32377 * @param {Object} config Configuration options
32378 * @param {String/HTMLElement/Element} container (optional) The container this layout is bound to (defaults to
32379 * document.body if omitted)
32381 Roo.ReaderLayout = function(config, renderTo){
32382 var c = config || {size:{}};
32383 Roo.ReaderLayout.superclass.constructor.call(this, renderTo || document.body, {
32384 north: c.north !== false ? Roo.apply({
32388 }, c.north) : false,
32389 west: c.west !== false ? Roo.apply({
32397 margins:{left:5,right:0,bottom:5,top:5},
32398 cmargins:{left:5,right:5,bottom:5,top:5}
32399 }, c.west) : false,
32400 east: c.east !== false ? Roo.apply({
32408 margins:{left:0,right:5,bottom:5,top:5},
32409 cmargins:{left:5,right:5,bottom:5,top:5}
32410 }, c.east) : false,
32411 center: Roo.apply({
32412 tabPosition: 'top',
32416 margins:{left:c.west!==false ? 0 : 5,right:c.east!==false ? 0 : 5,bottom:5,top:2}
32420 this.el.addClass('x-reader');
32422 this.beginUpdate();
32424 var inner = new Roo.BorderLayout(Roo.get(document.body).createChild(), {
32425 south: c.preview !== false ? Roo.apply({
32432 cmargins:{top:5,left:0, right:0, bottom:0}
32433 }, c.preview) : false,
32434 center: Roo.apply({
32440 this.add('center', new Roo.NestedLayoutPanel(inner,
32441 Roo.apply({title: c.mainTitle || '',tabTip:''},c.innerPanelCfg)));
32445 this.regions.preview = inner.getRegion('south');
32446 this.regions.listView = inner.getRegion('center');
32449 Roo.extend(Roo.ReaderLayout, Roo.BorderLayout);/*
32451 * Ext JS Library 1.1.1
32452 * Copyright(c) 2006-2007, Ext JS, LLC.
32454 * Originally Released Under LGPL - original licence link has changed is not relivant.
32457 * <script type="text/javascript">
32461 * @class Roo.grid.Grid
32462 * @extends Roo.util.Observable
32463 * This class represents the primary interface of a component based grid control.
32464 * <br><br>Usage:<pre><code>
32465 var grid = new Roo.grid.Grid("my-container-id", {
32468 selModel: mySelectionModel,
32469 autoSizeColumns: true,
32470 monitorWindowResize: false,
32471 trackMouseOver: true
32476 * <b>Common Problems:</b><br/>
32477 * - Grid does not resize properly when going smaller: Setting overflow hidden on the container
32478 * element will correct this<br/>
32479 * - If you get el.style[camel]= NaNpx or -2px or something related, be certain you have given your container element
32480 * dimensions. The grid adapts to your container's size, if your container has no size defined then the results
32481 * are unpredictable.<br/>
32482 * - Do not render the grid into an element with display:none. Try using visibility:hidden. Otherwise there is no way for the
32483 * grid to calculate dimensions/offsets.<br/>
32485 * @param {String/HTMLElement/Roo.Element} container The element into which this grid will be rendered -
32486 * The container MUST have some type of size defined for the grid to fill. The container will be
32487 * automatically set to position relative if it isn't already.
32488 * @param {Object} config A config object that sets properties on this grid.
32490 Roo.grid.Grid = function(container, config){
32491 // initialize the container
32492 this.container = Roo.get(container);
32493 this.container.update("");
32494 this.container.setStyle("overflow", "hidden");
32495 this.container.addClass('x-grid-container');
32497 this.id = this.container.id;
32499 Roo.apply(this, config);
32500 // check and correct shorthanded configs
32502 this.dataSource = this.ds;
32506 this.colModel = this.cm;
32510 this.selModel = this.sm;
32514 if (this.selModel) {
32515 this.selModel = Roo.factory(this.selModel, Roo.grid);
32516 this.sm = this.selModel;
32517 this.sm.xmodule = this.xmodule || false;
32519 if (typeof(this.colModel.config) == 'undefined') {
32520 this.colModel = new Roo.grid.ColumnModel(this.colModel);
32521 this.cm = this.colModel;
32522 this.cm.xmodule = this.xmodule || false;
32524 if (this.dataSource) {
32525 this.dataSource= Roo.factory(this.dataSource, Roo.data);
32526 this.ds = this.dataSource;
32527 this.ds.xmodule = this.xmodule || false;
32534 this.container.setWidth(this.width);
32538 this.container.setHeight(this.height);
32545 * The raw click event for the entire grid.
32546 * @param {Roo.EventObject} e
32551 * The raw dblclick event for the entire grid.
32552 * @param {Roo.EventObject} e
32556 * @event contextmenu
32557 * The raw contextmenu event for the entire grid.
32558 * @param {Roo.EventObject} e
32560 "contextmenu" : true,
32563 * The raw mousedown event for the entire grid.
32564 * @param {Roo.EventObject} e
32566 "mousedown" : true,
32569 * The raw mouseup event for the entire grid.
32570 * @param {Roo.EventObject} e
32575 * The raw mouseover event for the entire grid.
32576 * @param {Roo.EventObject} e
32578 "mouseover" : true,
32581 * The raw mouseout event for the entire grid.
32582 * @param {Roo.EventObject} e
32587 * The raw keypress event for the entire grid.
32588 * @param {Roo.EventObject} e
32593 * The raw keydown event for the entire grid.
32594 * @param {Roo.EventObject} e
32602 * Fires when a cell is clicked
32603 * @param {Grid} this
32604 * @param {Number} rowIndex
32605 * @param {Number} columnIndex
32606 * @param {Roo.EventObject} e
32608 "cellclick" : true,
32610 * @event celldblclick
32611 * Fires when a cell is double clicked
32612 * @param {Grid} this
32613 * @param {Number} rowIndex
32614 * @param {Number} columnIndex
32615 * @param {Roo.EventObject} e
32617 "celldblclick" : true,
32620 * Fires when a row is clicked
32621 * @param {Grid} this
32622 * @param {Number} rowIndex
32623 * @param {Roo.EventObject} e
32627 * @event rowdblclick
32628 * Fires when a row is double clicked
32629 * @param {Grid} this
32630 * @param {Number} rowIndex
32631 * @param {Roo.EventObject} e
32633 "rowdblclick" : true,
32635 * @event headerclick
32636 * Fires when a header is clicked
32637 * @param {Grid} this
32638 * @param {Number} columnIndex
32639 * @param {Roo.EventObject} e
32641 "headerclick" : true,
32643 * @event headerdblclick
32644 * Fires when a header cell is double clicked
32645 * @param {Grid} this
32646 * @param {Number} columnIndex
32647 * @param {Roo.EventObject} e
32649 "headerdblclick" : true,
32651 * @event rowcontextmenu
32652 * Fires when a row is right clicked
32653 * @param {Grid} this
32654 * @param {Number} rowIndex
32655 * @param {Roo.EventObject} e
32657 "rowcontextmenu" : true,
32659 * @event cellcontextmenu
32660 * Fires when a cell is right clicked
32661 * @param {Grid} this
32662 * @param {Number} rowIndex
32663 * @param {Number} cellIndex
32664 * @param {Roo.EventObject} e
32666 "cellcontextmenu" : true,
32668 * @event headercontextmenu
32669 * Fires when a header is right clicked
32670 * @param {Grid} this
32671 * @param {Number} columnIndex
32672 * @param {Roo.EventObject} e
32674 "headercontextmenu" : true,
32676 * @event bodyscroll
32677 * Fires when the body element is scrolled
32678 * @param {Number} scrollLeft
32679 * @param {Number} scrollTop
32681 "bodyscroll" : true,
32683 * @event columnresize
32684 * Fires when the user resizes a column
32685 * @param {Number} columnIndex
32686 * @param {Number} newSize
32688 "columnresize" : true,
32690 * @event columnmove
32691 * Fires when the user moves a column
32692 * @param {Number} oldIndex
32693 * @param {Number} newIndex
32695 "columnmove" : true,
32698 * Fires when row(s) start being dragged
32699 * @param {Grid} this
32700 * @param {Roo.GridDD} dd The drag drop object
32701 * @param {event} e The raw browser event
32703 "startdrag" : true,
32706 * Fires when a drag operation is complete
32707 * @param {Grid} this
32708 * @param {Roo.GridDD} dd The drag drop object
32709 * @param {event} e The raw browser event
32714 * Fires when dragged row(s) are dropped on a valid DD target
32715 * @param {Grid} this
32716 * @param {Roo.GridDD} dd The drag drop object
32717 * @param {String} targetId The target drag drop object
32718 * @param {event} e The raw browser event
32723 * Fires while row(s) are being dragged. "targetId" is the id of the Yahoo.util.DD object the selected rows are being dragged over.
32724 * @param {Grid} this
32725 * @param {Roo.GridDD} dd The drag drop object
32726 * @param {String} targetId The target drag drop object
32727 * @param {event} e The raw browser event
32732 * Fires when the dragged row(s) first cross another DD target while being dragged
32733 * @param {Grid} this
32734 * @param {Roo.GridDD} dd The drag drop object
32735 * @param {String} targetId The target drag drop object
32736 * @param {event} e The raw browser event
32738 "dragenter" : true,
32741 * Fires when the dragged row(s) leave another DD target while being dragged
32742 * @param {Grid} this
32743 * @param {Roo.GridDD} dd The drag drop object
32744 * @param {String} targetId The target drag drop object
32745 * @param {event} e The raw browser event
32750 * Fires when a row is rendered, so you can change add a style to it.
32751 * @param {GridView} gridview The grid view
32752 * @param {Object} rowcfg contains record rowIndex and rowClass - set rowClass to add a style.
32758 * Fires when the grid is rendered
32759 * @param {Grid} grid
32764 Roo.grid.Grid.superclass.constructor.call(this);
32766 Roo.extend(Roo.grid.Grid, Roo.util.Observable, {
32769 * @cfg {String} ddGroup - drag drop group.
32773 * @cfg {Number} minColumnWidth The minimum width a column can be resized to. Default is 25.
32775 minColumnWidth : 25,
32778 * @cfg {Boolean} autoSizeColumns True to automatically resize the columns to fit their content
32779 * <b>on initial render.</b> It is more efficient to explicitly size the columns
32780 * through the ColumnModel's {@link Roo.grid.ColumnModel#width} config option. Default is false.
32782 autoSizeColumns : false,
32785 * @cfg {Boolean} autoSizeHeaders True to measure headers with column data when auto sizing columns. Default is true.
32787 autoSizeHeaders : true,
32790 * @cfg {Boolean} monitorWindowResize True to autoSize the grid when the window resizes. Default is true.
32792 monitorWindowResize : true,
32795 * @cfg {Boolean} maxRowsToMeasure If autoSizeColumns is on, maxRowsToMeasure can be used to limit the number of
32796 * rows measured to get a columns size. Default is 0 (all rows).
32798 maxRowsToMeasure : 0,
32801 * @cfg {Boolean} trackMouseOver True to highlight rows when the mouse is over. Default is true.
32803 trackMouseOver : true,
32806 * @cfg {Boolean} enableDrag True to enable drag of rows. Default is false. (double check if this is needed?)
32810 * @cfg {Boolean} enableDragDrop True to enable drag and drop of rows. Default is false.
32812 enableDragDrop : false,
32815 * @cfg {Boolean} enableColumnMove True to enable drag and drop reorder of columns. Default is true.
32817 enableColumnMove : true,
32820 * @cfg {Boolean} enableColumnHide True to enable hiding of columns with the header context menu. Default is true.
32822 enableColumnHide : true,
32825 * @cfg {Boolean} enableRowHeightSync True to manually sync row heights across locked and not locked rows. Default is false.
32827 enableRowHeightSync : false,
32830 * @cfg {Boolean} stripeRows True to stripe the rows. Default is true.
32835 * @cfg {Boolean} autoHeight True to fit the height of the grid container to the height of the data. Default is false.
32837 autoHeight : false,
32840 * @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.
32842 autoExpandColumn : false,
32845 * @cfg {Number} autoExpandMin The minimum width the autoExpandColumn can have (if enabled).
32848 autoExpandMin : 50,
32851 * @cfg {Number} autoExpandMax The maximum width the autoExpandColumn can have (if enabled). Default is 1000.
32853 autoExpandMax : 1000,
32856 * @cfg {Object} view The {@link Roo.grid.GridView} used by the grid. This can be set before a call to render().
32861 * @cfg {Object} loadMask An {@link Roo.LoadMask} config or true to mask the grid while loading. Default is false.
32865 * @cfg {Roo.dd.DropTarget} dropTarget An {@link Roo.dd.DropTarget} config
32875 * @cfg {Boolean} autoWidth True to set the grid's width to the default total width of the grid's columns instead
32876 * of a fixed width. Default is false.
32879 * @cfg {Number} maxHeight Sets the maximum height of the grid - ignored if autoHeight is not on.
32882 * Called once after all setup has been completed and the grid is ready to be rendered.
32883 * @return {Roo.grid.Grid} this
32885 render : function()
32887 var c = this.container;
32888 // try to detect autoHeight/width mode
32889 if((!c.dom.offsetHeight || c.dom.offsetHeight < 20) || c.getStyle("height") == "auto"){
32890 this.autoHeight = true;
32892 var view = this.getView();
32895 c.on("click", this.onClick, this);
32896 c.on("dblclick", this.onDblClick, this);
32897 c.on("contextmenu", this.onContextMenu, this);
32898 c.on("keydown", this.onKeyDown, this);
32900 c.on("touchstart", this.onTouchStart, this);
32903 this.relayEvents(c, ["mousedown","mouseup","mouseover","mouseout","keypress"]);
32905 this.getSelectionModel().init(this);
32910 this.loadMask = new Roo.LoadMask(this.container,
32911 Roo.apply({store:this.dataSource}, this.loadMask));
32915 if (this.toolbar && this.toolbar.xtype) {
32916 this.toolbar.container = this.getView().getHeaderPanel(true);
32917 this.toolbar = new Roo.Toolbar(this.toolbar);
32919 if (this.footer && this.footer.xtype) {
32920 this.footer.dataSource = this.getDataSource();
32921 this.footer.container = this.getView().getFooterPanel(true);
32922 this.footer = Roo.factory(this.footer, Roo);
32924 if (this.dropTarget && this.dropTarget.xtype) {
32925 delete this.dropTarget.xtype;
32926 this.dropTarget = new Roo.dd.DropTarget(this.getView().mainBody, this.dropTarget);
32930 this.rendered = true;
32931 this.fireEvent('render', this);
32936 * Reconfigures the grid to use a different Store and Column Model.
32937 * The View will be bound to the new objects and refreshed.
32938 * @param {Roo.data.Store} dataSource The new {@link Roo.data.Store} object
32939 * @param {Roo.grid.ColumnModel} The new {@link Roo.grid.ColumnModel} object
32941 reconfigure : function(dataSource, colModel){
32943 this.loadMask.destroy();
32944 this.loadMask = new Roo.LoadMask(this.container,
32945 Roo.apply({store:dataSource}, this.loadMask));
32947 this.view.bind(dataSource, colModel);
32948 this.dataSource = dataSource;
32949 this.colModel = colModel;
32950 this.view.refresh(true);
32954 onKeyDown : function(e){
32955 this.fireEvent("keydown", e);
32959 * Destroy this grid.
32960 * @param {Boolean} removeEl True to remove the element
32962 destroy : function(removeEl, keepListeners){
32964 this.loadMask.destroy();
32966 var c = this.container;
32967 c.removeAllListeners();
32968 this.view.destroy();
32969 this.colModel.purgeListeners();
32970 if(!keepListeners){
32971 this.purgeListeners();
32974 if(removeEl === true){
32980 processEvent : function(name, e){
32981 // does this fire select???
32982 //Roo.log('grid:processEvent ' + name);
32984 if (name != 'touchstart' ) {
32985 this.fireEvent(name, e);
32988 var t = e.getTarget();
32990 var header = v.findHeaderIndex(t);
32991 if(header !== false){
32992 var ename = name == 'touchstart' ? 'click' : name;
32994 this.fireEvent("header" + ename, this, header, e);
32996 var row = v.findRowIndex(t);
32997 var cell = v.findCellIndex(t);
32998 if (name == 'touchstart') {
32999 // first touch is always a click.
33000 // hopefull this happens after selection is updated.?
33003 if (typeof(this.selModel.getSelectedCell) != 'undefined') {
33004 var cs = this.selModel.getSelectedCell();
33005 if (row == cs[0] && cell == cs[1]){
33009 if (typeof(this.selModel.getSelections) != 'undefined') {
33010 var cs = this.selModel.getSelections();
33011 var ds = this.dataSource;
33012 if (cs.length == 1 && ds.getAt(row) == cs[0]){
33023 this.fireEvent("row" + name, this, row, e);
33024 if(cell !== false){
33025 this.fireEvent("cell" + name, this, row, cell, e);
33032 onClick : function(e){
33033 this.processEvent("click", e);
33036 onTouchStart : function(e){
33037 this.processEvent("touchstart", e);
33041 onContextMenu : function(e, t){
33042 this.processEvent("contextmenu", e);
33046 onDblClick : function(e){
33047 this.processEvent("dblclick", e);
33051 walkCells : function(row, col, step, fn, scope){
33052 var cm = this.colModel, clen = cm.getColumnCount();
33053 var ds = this.dataSource, rlen = ds.getCount(), first = true;
33065 if(fn.call(scope || this, row, col, cm) === true){
33083 if(fn.call(scope || this, row, col, cm) === true){
33095 getSelections : function(){
33096 return this.selModel.getSelections();
33100 * Causes the grid to manually recalculate its dimensions. Generally this is done automatically,
33101 * but if manual update is required this method will initiate it.
33103 autoSize : function(){
33105 this.view.layout();
33106 if(this.view.adjustForScroll){
33107 this.view.adjustForScroll();
33113 * Returns the grid's underlying element.
33114 * @return {Element} The element
33116 getGridEl : function(){
33117 return this.container;
33120 // private for compatibility, overridden by editor grid
33121 stopEditing : function(){},
33124 * Returns the grid's SelectionModel.
33125 * @return {SelectionModel}
33127 getSelectionModel : function(){
33128 if(!this.selModel){
33129 this.selModel = new Roo.grid.RowSelectionModel();
33131 return this.selModel;
33135 * Returns the grid's DataSource.
33136 * @return {DataSource}
33138 getDataSource : function(){
33139 return this.dataSource;
33143 * Returns the grid's ColumnModel.
33144 * @return {ColumnModel}
33146 getColumnModel : function(){
33147 return this.colModel;
33151 * Returns the grid's GridView object.
33152 * @return {GridView}
33154 getView : function(){
33156 this.view = new Roo.grid.GridView(this.viewConfig);
33161 * Called to get grid's drag proxy text, by default returns this.ddText.
33164 getDragDropText : function(){
33165 var count = this.selModel.getCount();
33166 return String.format(this.ddText, count, count == 1 ? '' : 's');
33170 * Configures the text is the drag proxy (defaults to "%0 selected row(s)").
33171 * %0 is replaced with the number of selected rows.
33174 Roo.grid.Grid.prototype.ddText = "{0} selected row{1}";/*
33176 * Ext JS Library 1.1.1
33177 * Copyright(c) 2006-2007, Ext JS, LLC.
33179 * Originally Released Under LGPL - original licence link has changed is not relivant.
33182 * <script type="text/javascript">
33185 Roo.grid.AbstractGridView = function(){
33189 "beforerowremoved" : true,
33190 "beforerowsinserted" : true,
33191 "beforerefresh" : true,
33192 "rowremoved" : true,
33193 "rowsinserted" : true,
33194 "rowupdated" : true,
33197 Roo.grid.AbstractGridView.superclass.constructor.call(this);
33200 Roo.extend(Roo.grid.AbstractGridView, Roo.util.Observable, {
33201 rowClass : "x-grid-row",
33202 cellClass : "x-grid-cell",
33203 tdClass : "x-grid-td",
33204 hdClass : "x-grid-hd",
33205 splitClass : "x-grid-hd-split",
33207 init: function(grid){
33209 var cid = this.grid.getGridEl().id;
33210 this.colSelector = "#" + cid + " ." + this.cellClass + "-";
33211 this.tdSelector = "#" + cid + " ." + this.tdClass + "-";
33212 this.hdSelector = "#" + cid + " ." + this.hdClass + "-";
33213 this.splitSelector = "#" + cid + " ." + this.splitClass + "-";
33216 getColumnRenderers : function(){
33217 var renderers = [];
33218 var cm = this.grid.colModel;
33219 var colCount = cm.getColumnCount();
33220 for(var i = 0; i < colCount; i++){
33221 renderers[i] = cm.getRenderer(i);
33226 getColumnIds : function(){
33228 var cm = this.grid.colModel;
33229 var colCount = cm.getColumnCount();
33230 for(var i = 0; i < colCount; i++){
33231 ids[i] = cm.getColumnId(i);
33236 getDataIndexes : function(){
33237 if(!this.indexMap){
33238 this.indexMap = this.buildIndexMap();
33240 return this.indexMap.colToData;
33243 getColumnIndexByDataIndex : function(dataIndex){
33244 if(!this.indexMap){
33245 this.indexMap = this.buildIndexMap();
33247 return this.indexMap.dataToCol[dataIndex];
33251 * Set a css style for a column dynamically.
33252 * @param {Number} colIndex The index of the column
33253 * @param {String} name The css property name
33254 * @param {String} value The css value
33256 setCSSStyle : function(colIndex, name, value){
33257 var selector = "#" + this.grid.id + " .x-grid-col-" + colIndex;
33258 Roo.util.CSS.updateRule(selector, name, value);
33261 generateRules : function(cm){
33262 var ruleBuf = [], rulesId = this.grid.id + '-cssrules';
33263 Roo.util.CSS.removeStyleSheet(rulesId);
33264 for(var i = 0, len = cm.getColumnCount(); i < len; i++){
33265 var cid = cm.getColumnId(i);
33266 ruleBuf.push(this.colSelector, cid, " {\n", cm.config[i].css, "}\n",
33267 this.tdSelector, cid, " {\n}\n",
33268 this.hdSelector, cid, " {\n}\n",
33269 this.splitSelector, cid, " {\n}\n");
33271 return Roo.util.CSS.createStyleSheet(ruleBuf.join(""), rulesId);
33275 * Ext JS Library 1.1.1
33276 * Copyright(c) 2006-2007, Ext JS, LLC.
33278 * Originally Released Under LGPL - original licence link has changed is not relivant.
33281 * <script type="text/javascript">
33285 // This is a support class used internally by the Grid components
33286 Roo.grid.HeaderDragZone = function(grid, hd, hd2){
33288 this.view = grid.getView();
33289 this.ddGroup = "gridHeader" + this.grid.getGridEl().id;
33290 Roo.grid.HeaderDragZone.superclass.constructor.call(this, hd);
33292 this.setHandleElId(Roo.id(hd));
33293 this.setOuterHandleElId(Roo.id(hd2));
33295 this.scroll = false;
33297 Roo.extend(Roo.grid.HeaderDragZone, Roo.dd.DragZone, {
33299 getDragData : function(e){
33300 var t = Roo.lib.Event.getTarget(e);
33301 var h = this.view.findHeaderCell(t);
33303 return {ddel: h.firstChild, header:h};
33308 onInitDrag : function(e){
33309 this.view.headersDisabled = true;
33310 var clone = this.dragData.ddel.cloneNode(true);
33311 clone.id = Roo.id();
33312 clone.style.width = Math.min(this.dragData.header.offsetWidth,this.maxDragWidth) + "px";
33313 this.proxy.update(clone);
33317 afterValidDrop : function(){
33319 setTimeout(function(){
33320 v.headersDisabled = false;
33324 afterInvalidDrop : function(){
33326 setTimeout(function(){
33327 v.headersDisabled = false;
33333 * Ext JS Library 1.1.1
33334 * Copyright(c) 2006-2007, Ext JS, LLC.
33336 * Originally Released Under LGPL - original licence link has changed is not relivant.
33339 * <script type="text/javascript">
33342 // This is a support class used internally by the Grid components
33343 Roo.grid.HeaderDropZone = function(grid, hd, hd2){
33345 this.view = grid.getView();
33346 // split the proxies so they don't interfere with mouse events
33347 this.proxyTop = Roo.DomHelper.append(document.body, {
33348 cls:"col-move-top", html:" "
33350 this.proxyBottom = Roo.DomHelper.append(document.body, {
33351 cls:"col-move-bottom", html:" "
33353 this.proxyTop.hide = this.proxyBottom.hide = function(){
33354 this.setLeftTop(-100,-100);
33355 this.setStyle("visibility", "hidden");
33357 this.ddGroup = "gridHeader" + this.grid.getGridEl().id;
33358 // temporarily disabled
33359 //Roo.dd.ScrollManager.register(this.view.scroller.dom);
33360 Roo.grid.HeaderDropZone.superclass.constructor.call(this, grid.getGridEl().dom);
33362 Roo.extend(Roo.grid.HeaderDropZone, Roo.dd.DropZone, {
33363 proxyOffsets : [-4, -9],
33364 fly: Roo.Element.fly,
33366 getTargetFromEvent : function(e){
33367 var t = Roo.lib.Event.getTarget(e);
33368 var cindex = this.view.findCellIndex(t);
33369 if(cindex !== false){
33370 return this.view.getHeaderCell(cindex);
33375 nextVisible : function(h){
33376 var v = this.view, cm = this.grid.colModel;
33379 if(!cm.isHidden(v.getCellIndex(h))){
33387 prevVisible : function(h){
33388 var v = this.view, cm = this.grid.colModel;
33391 if(!cm.isHidden(v.getCellIndex(h))){
33399 positionIndicator : function(h, n, e){
33400 var x = Roo.lib.Event.getPageX(e);
33401 var r = Roo.lib.Dom.getRegion(n.firstChild);
33402 var px, pt, py = r.top + this.proxyOffsets[1];
33403 if((r.right - x) <= (r.right-r.left)/2){
33404 px = r.right+this.view.borderWidth;
33410 var oldIndex = this.view.getCellIndex(h);
33411 var newIndex = this.view.getCellIndex(n);
33413 if(this.grid.colModel.isFixed(newIndex)){
33417 var locked = this.grid.colModel.isLocked(newIndex);
33422 if(oldIndex < newIndex){
33425 if(oldIndex == newIndex && (locked == this.grid.colModel.isLocked(oldIndex))){
33428 px += this.proxyOffsets[0];
33429 this.proxyTop.setLeftTop(px, py);
33430 this.proxyTop.show();
33431 if(!this.bottomOffset){
33432 this.bottomOffset = this.view.mainHd.getHeight();
33434 this.proxyBottom.setLeftTop(px, py+this.proxyTop.dom.offsetHeight+this.bottomOffset);
33435 this.proxyBottom.show();
33439 onNodeEnter : function(n, dd, e, data){
33440 if(data.header != n){
33441 this.positionIndicator(data.header, n, e);
33445 onNodeOver : function(n, dd, e, data){
33446 var result = false;
33447 if(data.header != n){
33448 result = this.positionIndicator(data.header, n, e);
33451 this.proxyTop.hide();
33452 this.proxyBottom.hide();
33454 return result ? this.dropAllowed : this.dropNotAllowed;
33457 onNodeOut : function(n, dd, e, data){
33458 this.proxyTop.hide();
33459 this.proxyBottom.hide();
33462 onNodeDrop : function(n, dd, e, data){
33463 var h = data.header;
33465 var cm = this.grid.colModel;
33466 var x = Roo.lib.Event.getPageX(e);
33467 var r = Roo.lib.Dom.getRegion(n.firstChild);
33468 var pt = (r.right - x) <= ((r.right-r.left)/2) ? "after" : "before";
33469 var oldIndex = this.view.getCellIndex(h);
33470 var newIndex = this.view.getCellIndex(n);
33471 var locked = cm.isLocked(newIndex);
33475 if(oldIndex < newIndex){
33478 if(oldIndex == newIndex && (locked == cm.isLocked(oldIndex))){
33481 cm.setLocked(oldIndex, locked, true);
33482 cm.moveColumn(oldIndex, newIndex);
33483 this.grid.fireEvent("columnmove", oldIndex, newIndex);
33491 * Ext JS Library 1.1.1
33492 * Copyright(c) 2006-2007, Ext JS, LLC.
33494 * Originally Released Under LGPL - original licence link has changed is not relivant.
33497 * <script type="text/javascript">
33501 * @class Roo.grid.GridView
33502 * @extends Roo.util.Observable
33505 * @param {Object} config
33507 Roo.grid.GridView = function(config){
33508 Roo.grid.GridView.superclass.constructor.call(this);
33511 Roo.apply(this, config);
33514 Roo.extend(Roo.grid.GridView, Roo.grid.AbstractGridView, {
33516 unselectable : 'unselectable="on"',
33517 unselectableCls : 'x-unselectable',
33520 rowClass : "x-grid-row",
33522 cellClass : "x-grid-col",
33524 tdClass : "x-grid-td",
33526 hdClass : "x-grid-hd",
33528 splitClass : "x-grid-split",
33530 sortClasses : ["sort-asc", "sort-desc"],
33532 enableMoveAnim : false,
33536 dh : Roo.DomHelper,
33538 fly : Roo.Element.fly,
33540 css : Roo.util.CSS,
33546 scrollIncrement : 22,
33548 cellRE: /(?:.*?)x-grid-(?:hd|cell|csplit)-(?:[\d]+)-([\d]+)(?:.*?)/,
33550 findRE: /\s?(?:x-grid-hd|x-grid-col|x-grid-csplit)\s/,
33552 bind : function(ds, cm){
33554 this.ds.un("load", this.onLoad, this);
33555 this.ds.un("datachanged", this.onDataChange, this);
33556 this.ds.un("add", this.onAdd, this);
33557 this.ds.un("remove", this.onRemove, this);
33558 this.ds.un("update", this.onUpdate, this);
33559 this.ds.un("clear", this.onClear, this);
33562 ds.on("load", this.onLoad, this);
33563 ds.on("datachanged", this.onDataChange, this);
33564 ds.on("add", this.onAdd, this);
33565 ds.on("remove", this.onRemove, this);
33566 ds.on("update", this.onUpdate, this);
33567 ds.on("clear", this.onClear, this);
33572 this.cm.un("widthchange", this.onColWidthChange, this);
33573 this.cm.un("headerchange", this.onHeaderChange, this);
33574 this.cm.un("hiddenchange", this.onHiddenChange, this);
33575 this.cm.un("columnmoved", this.onColumnMove, this);
33576 this.cm.un("columnlockchange", this.onColumnLock, this);
33579 this.generateRules(cm);
33580 cm.on("widthchange", this.onColWidthChange, this);
33581 cm.on("headerchange", this.onHeaderChange, this);
33582 cm.on("hiddenchange", this.onHiddenChange, this);
33583 cm.on("columnmoved", this.onColumnMove, this);
33584 cm.on("columnlockchange", this.onColumnLock, this);
33589 init: function(grid){
33590 Roo.grid.GridView.superclass.init.call(this, grid);
33592 this.bind(grid.dataSource, grid.colModel);
33594 grid.on("headerclick", this.handleHeaderClick, this);
33596 if(grid.trackMouseOver){
33597 grid.on("mouseover", this.onRowOver, this);
33598 grid.on("mouseout", this.onRowOut, this);
33600 grid.cancelTextSelection = function(){};
33601 this.gridId = grid.id;
33603 var tpls = this.templates || {};
33606 tpls.master = new Roo.Template(
33607 '<div class="x-grid" hidefocus="true">',
33608 '<a href="#" class="x-grid-focus" tabIndex="-1"></a>',
33609 '<div class="x-grid-topbar"></div>',
33610 '<div class="x-grid-scroller"><div></div></div>',
33611 '<div class="x-grid-locked">',
33612 '<div class="x-grid-header">{lockedHeader}</div>',
33613 '<div class="x-grid-body">{lockedBody}</div>',
33615 '<div class="x-grid-viewport">',
33616 '<div class="x-grid-header">{header}</div>',
33617 '<div class="x-grid-body">{body}</div>',
33619 '<div class="x-grid-bottombar"></div>',
33621 '<div class="x-grid-resize-proxy"> </div>',
33624 tpls.master.disableformats = true;
33628 tpls.header = new Roo.Template(
33629 '<table border="0" cellspacing="0" cellpadding="0">',
33630 '<tbody><tr class="x-grid-hd-row">{cells}</tr></tbody>',
33633 tpls.header.disableformats = true;
33635 tpls.header.compile();
33638 tpls.hcell = new Roo.Template(
33639 '<td class="x-grid-hd x-grid-td-{id} {cellId}"><div title="{title}" class="x-grid-hd-inner x-grid-hd-{id}">',
33640 '<div class="x-grid-hd-text ' + this.unselectableCls + '" ' + this.unselectable +'>{value}<img class="x-grid-sort-icon" src="', Roo.BLANK_IMAGE_URL, '" /></div>',
33643 tpls.hcell.disableFormats = true;
33645 tpls.hcell.compile();
33648 tpls.hsplit = new Roo.Template('<div class="x-grid-split {splitId} x-grid-split-{id}" style="{style} ' +
33649 this.unselectableCls + '" ' + this.unselectable +'> </div>');
33650 tpls.hsplit.disableFormats = true;
33652 tpls.hsplit.compile();
33655 tpls.body = new Roo.Template(
33656 '<table border="0" cellspacing="0" cellpadding="0">',
33657 "<tbody>{rows}</tbody>",
33660 tpls.body.disableFormats = true;
33662 tpls.body.compile();
33665 tpls.row = new Roo.Template('<tr class="x-grid-row {alt}">{cells}</tr>');
33666 tpls.row.disableFormats = true;
33668 tpls.row.compile();
33671 tpls.cell = new Roo.Template(
33672 '<td class="x-grid-col x-grid-td-{id} {cellId} {css}" tabIndex="0">',
33673 '<div class="x-grid-col-{id} x-grid-cell-inner"><div class="x-grid-cell-text ' +
33674 this.unselectableCls + '" ' + this.unselectable +'" {attr}>{value}</div></div>',
33677 tpls.cell.disableFormats = true;
33679 tpls.cell.compile();
33681 this.templates = tpls;
33684 // remap these for backwards compat
33685 onColWidthChange : function(){
33686 this.updateColumns.apply(this, arguments);
33688 onHeaderChange : function(){
33689 this.updateHeaders.apply(this, arguments);
33691 onHiddenChange : function(){
33692 this.handleHiddenChange.apply(this, arguments);
33694 onColumnMove : function(){
33695 this.handleColumnMove.apply(this, arguments);
33697 onColumnLock : function(){
33698 this.handleLockChange.apply(this, arguments);
33701 onDataChange : function(){
33703 this.updateHeaderSortState();
33706 onClear : function(){
33710 onUpdate : function(ds, record){
33711 this.refreshRow(record);
33714 refreshRow : function(record){
33715 var ds = this.ds, index;
33716 if(typeof record == 'number'){
33718 record = ds.getAt(index);
33720 index = ds.indexOf(record);
33722 this.insertRows(ds, index, index, true);
33723 this.onRemove(ds, record, index+1, true);
33724 this.syncRowHeights(index, index);
33726 this.fireEvent("rowupdated", this, index, record);
33729 onAdd : function(ds, records, index){
33730 this.insertRows(ds, index, index + (records.length-1));
33733 onRemove : function(ds, record, index, isUpdate){
33734 if(isUpdate !== true){
33735 this.fireEvent("beforerowremoved", this, index, record);
33737 var bt = this.getBodyTable(), lt = this.getLockedTable();
33738 if(bt.rows[index]){
33739 bt.firstChild.removeChild(bt.rows[index]);
33741 if(lt.rows[index]){
33742 lt.firstChild.removeChild(lt.rows[index]);
33744 if(isUpdate !== true){
33745 this.stripeRows(index);
33746 this.syncRowHeights(index, index);
33748 this.fireEvent("rowremoved", this, index, record);
33752 onLoad : function(){
33753 this.scrollToTop();
33757 * Scrolls the grid to the top
33759 scrollToTop : function(){
33761 this.scroller.dom.scrollTop = 0;
33767 * Gets a panel in the header of the grid that can be used for toolbars etc.
33768 * After modifying the contents of this panel a call to grid.autoSize() may be
33769 * required to register any changes in size.
33770 * @param {Boolean} doShow By default the header is hidden. Pass true to show the panel
33771 * @return Roo.Element
33773 getHeaderPanel : function(doShow){
33775 this.headerPanel.show();
33777 return this.headerPanel;
33781 * Gets a panel in the footer of the grid that can be used for toolbars etc.
33782 * After modifying the contents of this panel a call to grid.autoSize() may be
33783 * required to register any changes in size.
33784 * @param {Boolean} doShow By default the footer is hidden. Pass true to show the panel
33785 * @return Roo.Element
33787 getFooterPanel : function(doShow){
33789 this.footerPanel.show();
33791 return this.footerPanel;
33794 initElements : function(){
33795 var E = Roo.Element;
33796 var el = this.grid.getGridEl().dom.firstChild;
33797 var cs = el.childNodes;
33799 this.el = new E(el);
33801 this.focusEl = new E(el.firstChild);
33802 this.focusEl.swallowEvent("click", true);
33804 this.headerPanel = new E(cs[1]);
33805 this.headerPanel.enableDisplayMode("block");
33807 this.scroller = new E(cs[2]);
33808 this.scrollSizer = new E(this.scroller.dom.firstChild);
33810 this.lockedWrap = new E(cs[3]);
33811 this.lockedHd = new E(this.lockedWrap.dom.firstChild);
33812 this.lockedBody = new E(this.lockedWrap.dom.childNodes[1]);
33814 this.mainWrap = new E(cs[4]);
33815 this.mainHd = new E(this.mainWrap.dom.firstChild);
33816 this.mainBody = new E(this.mainWrap.dom.childNodes[1]);
33818 this.footerPanel = new E(cs[5]);
33819 this.footerPanel.enableDisplayMode("block");
33821 this.resizeProxy = new E(cs[6]);
33823 this.headerSelector = String.format(
33824 '#{0} td.x-grid-hd, #{1} td.x-grid-hd',
33825 this.lockedHd.id, this.mainHd.id
33828 this.splitterSelector = String.format(
33829 '#{0} div.x-grid-split, #{1} div.x-grid-split',
33830 this.idToCssName(this.lockedHd.id), this.idToCssName(this.mainHd.id)
33833 idToCssName : function(s)
33835 return s.replace(/[^a-z0-9]+/ig, '-');
33838 getHeaderCell : function(index){
33839 return Roo.DomQuery.select(this.headerSelector)[index];
33842 getHeaderCellMeasure : function(index){
33843 return this.getHeaderCell(index).firstChild;
33846 getHeaderCellText : function(index){
33847 return this.getHeaderCell(index).firstChild.firstChild;
33850 getLockedTable : function(){
33851 return this.lockedBody.dom.firstChild;
33854 getBodyTable : function(){
33855 return this.mainBody.dom.firstChild;
33858 getLockedRow : function(index){
33859 return this.getLockedTable().rows[index];
33862 getRow : function(index){
33863 return this.getBodyTable().rows[index];
33866 getRowComposite : function(index){
33868 this.rowEl = new Roo.CompositeElementLite();
33870 var els = [], lrow, mrow;
33871 if(lrow = this.getLockedRow(index)){
33874 if(mrow = this.getRow(index)){
33877 this.rowEl.elements = els;
33881 * Gets the 'td' of the cell
33883 * @param {Integer} rowIndex row to select
33884 * @param {Integer} colIndex column to select
33888 getCell : function(rowIndex, colIndex){
33889 var locked = this.cm.getLockedCount();
33891 if(colIndex < locked){
33892 source = this.lockedBody.dom.firstChild;
33894 source = this.mainBody.dom.firstChild;
33895 colIndex -= locked;
33897 return source.rows[rowIndex].childNodes[colIndex];
33900 getCellText : function(rowIndex, colIndex){
33901 return this.getCell(rowIndex, colIndex).firstChild.firstChild;
33904 getCellBox : function(cell){
33905 var b = this.fly(cell).getBox();
33906 if(Roo.isOpera){ // opera fails to report the Y
33907 b.y = cell.offsetTop + this.mainBody.getY();
33912 getCellIndex : function(cell){
33913 var id = String(cell.className).match(this.cellRE);
33915 return parseInt(id[1], 10);
33920 findHeaderIndex : function(n){
33921 var r = Roo.fly(n).findParent("td." + this.hdClass, 6);
33922 return r ? this.getCellIndex(r) : false;
33925 findHeaderCell : function(n){
33926 var r = Roo.fly(n).findParent("td." + this.hdClass, 6);
33927 return r ? r : false;
33930 findRowIndex : function(n){
33934 var r = Roo.fly(n).findParent("tr." + this.rowClass, 6);
33935 return r ? r.rowIndex : false;
33938 findCellIndex : function(node){
33939 var stop = this.el.dom;
33940 while(node && node != stop){
33941 if(this.findRE.test(node.className)){
33942 return this.getCellIndex(node);
33944 node = node.parentNode;
33949 getColumnId : function(index){
33950 return this.cm.getColumnId(index);
33953 getSplitters : function()
33955 if(this.splitterSelector){
33956 return Roo.DomQuery.select(this.splitterSelector);
33962 getSplitter : function(index){
33963 return this.getSplitters()[index];
33966 onRowOver : function(e, t){
33968 if((row = this.findRowIndex(t)) !== false){
33969 this.getRowComposite(row).addClass("x-grid-row-over");
33973 onRowOut : function(e, t){
33975 if((row = this.findRowIndex(t)) !== false && row !== this.findRowIndex(e.getRelatedTarget())){
33976 this.getRowComposite(row).removeClass("x-grid-row-over");
33980 renderHeaders : function(){
33982 var ct = this.templates.hcell, ht = this.templates.header, st = this.templates.hsplit;
33983 var cb = [], lb = [], sb = [], lsb = [], p = {};
33984 for(var i = 0, len = cm.getColumnCount(); i < len; i++){
33985 p.cellId = "x-grid-hd-0-" + i;
33986 p.splitId = "x-grid-csplit-0-" + i;
33987 p.id = cm.getColumnId(i);
33988 p.value = cm.getColumnHeader(i) || "";
33989 p.title = cm.getColumnTooltip(i) || (''+p.value).match(/\</) ? '' : p.value || "";
33990 p.style = (this.grid.enableColumnResize === false || !cm.isResizable(i) || cm.isFixed(i)) ? 'cursor:default' : '';
33991 if(!cm.isLocked(i)){
33992 cb[cb.length] = ct.apply(p);
33993 sb[sb.length] = st.apply(p);
33995 lb[lb.length] = ct.apply(p);
33996 lsb[lsb.length] = st.apply(p);
33999 return [ht.apply({cells: lb.join(""), splits:lsb.join("")}),
34000 ht.apply({cells: cb.join(""), splits:sb.join("")})];
34003 updateHeaders : function(){
34004 var html = this.renderHeaders();
34005 this.lockedHd.update(html[0]);
34006 this.mainHd.update(html[1]);
34010 * Focuses the specified row.
34011 * @param {Number} row The row index
34013 focusRow : function(row)
34015 //Roo.log('GridView.focusRow');
34016 var x = this.scroller.dom.scrollLeft;
34017 this.focusCell(row, 0, false);
34018 this.scroller.dom.scrollLeft = x;
34022 * Focuses the specified cell.
34023 * @param {Number} row The row index
34024 * @param {Number} col The column index
34025 * @param {Boolean} hscroll false to disable horizontal scrolling
34027 focusCell : function(row, col, hscroll)
34029 //Roo.log('GridView.focusCell');
34030 var el = this.ensureVisible(row, col, hscroll);
34031 this.focusEl.alignTo(el, "tl-tl");
34033 this.focusEl.focus();
34035 this.focusEl.focus.defer(1, this.focusEl);
34040 * Scrolls the specified cell into view
34041 * @param {Number} row The row index
34042 * @param {Number} col The column index
34043 * @param {Boolean} hscroll false to disable horizontal scrolling
34045 ensureVisible : function(row, col, hscroll)
34047 //Roo.log('GridView.ensureVisible,' + row + ',' + col);
34048 //return null; //disable for testing.
34049 if(typeof row != "number"){
34050 row = row.rowIndex;
34052 if(row < 0 && row >= this.ds.getCount()){
34055 col = (col !== undefined ? col : 0);
34056 var cm = this.grid.colModel;
34057 while(cm.isHidden(col)){
34061 var el = this.getCell(row, col);
34065 var c = this.scroller.dom;
34067 var ctop = parseInt(el.offsetTop, 10);
34068 var cleft = parseInt(el.offsetLeft, 10);
34069 var cbot = ctop + el.offsetHeight;
34070 var cright = cleft + el.offsetWidth;
34072 var ch = c.clientHeight - this.mainHd.dom.offsetHeight;
34073 var stop = parseInt(c.scrollTop, 10);
34074 var sleft = parseInt(c.scrollLeft, 10);
34075 var sbot = stop + ch;
34076 var sright = sleft + c.clientWidth;
34078 Roo.log('GridView.ensureVisible:' +
34080 ' c.clientHeight:' + c.clientHeight +
34081 ' this.mainHd.dom.offsetHeight:' + this.mainHd.dom.offsetHeight +
34089 c.scrollTop = ctop;
34090 //Roo.log("set scrolltop to ctop DISABLE?");
34091 }else if(cbot > sbot){
34092 //Roo.log("set scrolltop to cbot-ch");
34093 c.scrollTop = cbot-ch;
34096 if(hscroll !== false){
34098 c.scrollLeft = cleft;
34099 }else if(cright > sright){
34100 c.scrollLeft = cright-c.clientWidth;
34107 updateColumns : function(){
34108 this.grid.stopEditing();
34109 var cm = this.grid.colModel, colIds = this.getColumnIds();
34110 //var totalWidth = cm.getTotalWidth();
34112 for(var i = 0, len = cm.getColumnCount(); i < len; i++){
34113 //if(cm.isHidden(i)) continue;
34114 var w = cm.getColumnWidth(i);
34115 this.css.updateRule(this.colSelector+this.idToCssName(colIds[i]), "width", (w - this.borderWidth) + "px");
34116 this.css.updateRule(this.hdSelector+this.idToCssName(colIds[i]), "width", (w - this.borderWidth) + "px");
34118 this.updateSplitters();
34121 generateRules : function(cm){
34122 var ruleBuf = [], rulesId = this.idToCssName(this.grid.id)+ '-cssrules';
34123 Roo.util.CSS.removeStyleSheet(rulesId);
34124 for(var i = 0, len = cm.getColumnCount(); i < len; i++){
34125 var cid = cm.getColumnId(i);
34127 if(cm.config[i].align){
34128 align = 'text-align:'+cm.config[i].align+';';
34131 if(cm.isHidden(i)){
34132 hidden = 'display:none;';
34134 var width = "width:" + (cm.getColumnWidth(i) - this.borderWidth) + "px;";
34136 this.colSelector, cid, " {\n", cm.config[i].css, align, width, "\n}\n",
34137 this.hdSelector, cid, " {\n", align, width, "}\n",
34138 this.tdSelector, cid, " {\n",hidden,"\n}\n",
34139 this.splitSelector, cid, " {\n", hidden , "\n}\n");
34141 return Roo.util.CSS.createStyleSheet(ruleBuf.join(""), rulesId);
34144 updateSplitters : function(){
34145 var cm = this.cm, s = this.getSplitters();
34146 if(s){ // splitters not created yet
34147 var pos = 0, locked = true;
34148 for(var i = 0, len = cm.getColumnCount(); i < len; i++){
34149 if(cm.isHidden(i)) {
34152 var w = cm.getColumnWidth(i); // make sure it's a number
34153 if(!cm.isLocked(i) && locked){
34158 s[i].style.left = (pos-this.splitOffset) + "px";
34163 handleHiddenChange : function(colModel, colIndex, hidden){
34165 this.hideColumn(colIndex);
34167 this.unhideColumn(colIndex);
34171 hideColumn : function(colIndex){
34172 var cid = this.getColumnId(colIndex);
34173 this.css.updateRule(this.tdSelector+this.idToCssName(cid), "display", "none");
34174 this.css.updateRule(this.splitSelector+this.idToCssName(cid), "display", "none");
34176 this.updateHeaders();
34178 this.updateSplitters();
34182 unhideColumn : function(colIndex){
34183 var cid = this.getColumnId(colIndex);
34184 this.css.updateRule(this.tdSelector+this.idToCssName(cid), "display", "");
34185 this.css.updateRule(this.splitSelector+this.idToCssName(cid), "display", "");
34188 this.updateHeaders();
34190 this.updateSplitters();
34194 insertRows : function(dm, firstRow, lastRow, isUpdate){
34195 if(firstRow == 0 && lastRow == dm.getCount()-1){
34199 this.fireEvent("beforerowsinserted", this, firstRow, lastRow);
34201 var s = this.getScrollState();
34202 var markup = this.renderRows(firstRow, lastRow);
34203 this.bufferRows(markup[0], this.getLockedTable(), firstRow);
34204 this.bufferRows(markup[1], this.getBodyTable(), firstRow);
34205 this.restoreScroll(s);
34207 this.fireEvent("rowsinserted", this, firstRow, lastRow);
34208 this.syncRowHeights(firstRow, lastRow);
34209 this.stripeRows(firstRow);
34215 bufferRows : function(markup, target, index){
34216 var before = null, trows = target.rows, tbody = target.tBodies[0];
34217 if(index < trows.length){
34218 before = trows[index];
34220 var b = document.createElement("div");
34221 b.innerHTML = "<table><tbody>"+markup+"</tbody></table>";
34222 var rows = b.firstChild.rows;
34223 for(var i = 0, len = rows.length; i < len; i++){
34225 tbody.insertBefore(rows[0], before);
34227 tbody.appendChild(rows[0]);
34234 deleteRows : function(dm, firstRow, lastRow){
34235 if(dm.getRowCount()<1){
34236 this.fireEvent("beforerefresh", this);
34237 this.mainBody.update("");
34238 this.lockedBody.update("");
34239 this.fireEvent("refresh", this);
34241 this.fireEvent("beforerowsdeleted", this, firstRow, lastRow);
34242 var bt = this.getBodyTable();
34243 var tbody = bt.firstChild;
34244 var rows = bt.rows;
34245 for(var rowIndex = firstRow; rowIndex <= lastRow; rowIndex++){
34246 tbody.removeChild(rows[firstRow]);
34248 this.stripeRows(firstRow);
34249 this.fireEvent("rowsdeleted", this, firstRow, lastRow);
34253 updateRows : function(dataSource, firstRow, lastRow){
34254 var s = this.getScrollState();
34256 this.restoreScroll(s);
34259 handleSort : function(dataSource, sortColumnIndex, sortDir, noRefresh){
34263 this.updateHeaderSortState();
34266 getScrollState : function(){
34268 var sb = this.scroller.dom;
34269 return {left: sb.scrollLeft, top: sb.scrollTop};
34272 stripeRows : function(startRow){
34273 if(!this.grid.stripeRows || this.ds.getCount() < 1){
34276 startRow = startRow || 0;
34277 var rows = this.getBodyTable().rows;
34278 var lrows = this.getLockedTable().rows;
34279 var cls = ' x-grid-row-alt ';
34280 for(var i = startRow, len = rows.length; i < len; i++){
34281 var row = rows[i], lrow = lrows[i];
34282 var isAlt = ((i+1) % 2 == 0);
34283 var hasAlt = (' '+row.className + ' ').indexOf(cls) != -1;
34284 if(isAlt == hasAlt){
34288 row.className += " x-grid-row-alt";
34290 row.className = row.className.replace("x-grid-row-alt", "");
34293 lrow.className = row.className;
34298 restoreScroll : function(state){
34299 //Roo.log('GridView.restoreScroll');
34300 var sb = this.scroller.dom;
34301 sb.scrollLeft = state.left;
34302 sb.scrollTop = state.top;
34306 syncScroll : function(){
34307 //Roo.log('GridView.syncScroll');
34308 var sb = this.scroller.dom;
34309 var sh = this.mainHd.dom;
34310 var bs = this.mainBody.dom;
34311 var lv = this.lockedBody.dom;
34312 sh.scrollLeft = bs.scrollLeft = sb.scrollLeft;
34313 lv.scrollTop = bs.scrollTop = sb.scrollTop;
34316 handleScroll : function(e){
34318 var sb = this.scroller.dom;
34319 this.grid.fireEvent("bodyscroll", sb.scrollLeft, sb.scrollTop);
34323 handleWheel : function(e){
34324 var d = e.getWheelDelta();
34325 this.scroller.dom.scrollTop -= d*22;
34326 // set this here to prevent jumpy scrolling on large tables
34327 this.lockedBody.dom.scrollTop = this.mainBody.dom.scrollTop = this.scroller.dom.scrollTop;
34331 renderRows : function(startRow, endRow){
34332 // pull in all the crap needed to render rows
34333 var g = this.grid, cm = g.colModel, ds = g.dataSource, stripe = g.stripeRows;
34334 var colCount = cm.getColumnCount();
34336 if(ds.getCount() < 1){
34340 // build a map for all the columns
34342 for(var i = 0; i < colCount; i++){
34343 var name = cm.getDataIndex(i);
34345 name : typeof name == 'undefined' ? ds.fields.get(i).name : name,
34346 renderer : cm.getRenderer(i),
34347 id : cm.getColumnId(i),
34348 locked : cm.isLocked(i),
34349 has_editor : cm.isCellEditable(i)
34353 startRow = startRow || 0;
34354 endRow = typeof endRow == "undefined"? ds.getCount()-1 : endRow;
34356 // records to render
34357 var rs = ds.getRange(startRow, endRow);
34359 return this.doRender(cs, rs, ds, startRow, colCount, stripe);
34362 // As much as I hate to duplicate code, this was branched because FireFox really hates
34363 // [].join("") on strings. The performance difference was substantial enough to
34364 // branch this function
34365 doRender : Roo.isGecko ?
34366 function(cs, rs, ds, startRow, colCount, stripe){
34367 var ts = this.templates, ct = ts.cell, rt = ts.row;
34369 var buf = "", lbuf = "", cb, lcb, c, p = {}, rp = {}, r, rowIndex;
34371 var hasListener = this.grid.hasListener('rowclass');
34373 for(var j = 0, len = rs.length; j < len; j++){
34374 r = rs[j]; cb = ""; lcb = ""; rowIndex = (j+startRow);
34375 for(var i = 0; i < colCount; i++){
34377 p.cellId = "x-grid-cell-" + rowIndex + "-" + i;
34379 p.css = p.attr = "";
34380 p.value = c.renderer(r.data[c.name], p, r, rowIndex, i, ds);
34381 if(p.value == undefined || p.value === "") {
34382 p.value = " ";
34385 p.css += ' x-grid-editable-cell';
34387 if(c.dirty && typeof r.modified[c.name] !== 'undefined'){
34388 p.css += ' x-grid-dirty-cell';
34390 var markup = ct.apply(p);
34398 if(stripe && ((rowIndex+1) % 2 == 0)){
34399 alt.push("x-grid-row-alt")
34402 alt.push( " x-grid-dirty-row");
34405 if(this.getRowClass){
34406 alt.push(this.getRowClass(r, rowIndex));
34412 rowIndex : rowIndex,
34415 this.grid.fireEvent('rowclass', this, rowcfg);
34416 alt.push(rowcfg.rowClass);
34418 rp.alt = alt.join(" ");
34419 lbuf+= rt.apply(rp);
34421 buf+= rt.apply(rp);
34423 return [lbuf, buf];
34425 function(cs, rs, ds, startRow, colCount, stripe){
34426 var ts = this.templates, ct = ts.cell, rt = ts.row;
34428 var buf = [], lbuf = [], cb, lcb, c, p = {}, rp = {}, r, rowIndex;
34429 var hasListener = this.grid.hasListener('rowclass');
34432 for(var j = 0, len = rs.length; j < len; j++){
34433 r = rs[j]; cb = []; lcb = []; rowIndex = (j+startRow);
34434 for(var i = 0; i < colCount; i++){
34436 p.cellId = "x-grid-cell-" + rowIndex + "-" + i;
34438 p.css = p.attr = "";
34439 p.value = c.renderer(r.data[c.name], p, r, rowIndex, i, ds);
34440 if(p.value == undefined || p.value === "") {
34441 p.value = " ";
34445 p.css += ' x-grid-editable-cell';
34447 if(r.dirty && typeof r.modified[c.name] !== 'undefined'){
34448 p.css += ' x-grid-dirty-cell'
34451 var markup = ct.apply(p);
34453 cb[cb.length] = markup;
34455 lcb[lcb.length] = markup;
34459 if(stripe && ((rowIndex+1) % 2 == 0)){
34460 alt.push( "x-grid-row-alt");
34463 alt.push(" x-grid-dirty-row");
34466 if(this.getRowClass){
34467 alt.push( this.getRowClass(r, rowIndex));
34473 rowIndex : rowIndex,
34476 this.grid.fireEvent('rowclass', this, rowcfg);
34477 alt.push(rowcfg.rowClass);
34480 rp.alt = alt.join(" ");
34481 rp.cells = lcb.join("");
34482 lbuf[lbuf.length] = rt.apply(rp);
34483 rp.cells = cb.join("");
34484 buf[buf.length] = rt.apply(rp);
34486 return [lbuf.join(""), buf.join("")];
34489 renderBody : function(){
34490 var markup = this.renderRows();
34491 var bt = this.templates.body;
34492 return [bt.apply({rows: markup[0]}), bt.apply({rows: markup[1]})];
34496 * Refreshes the grid
34497 * @param {Boolean} headersToo
34499 refresh : function(headersToo){
34500 this.fireEvent("beforerefresh", this);
34501 this.grid.stopEditing();
34502 var result = this.renderBody();
34503 this.lockedBody.update(result[0]);
34504 this.mainBody.update(result[1]);
34505 if(headersToo === true){
34506 this.updateHeaders();
34507 this.updateColumns();
34508 this.updateSplitters();
34509 this.updateHeaderSortState();
34511 this.syncRowHeights();
34513 this.fireEvent("refresh", this);
34516 handleColumnMove : function(cm, oldIndex, newIndex){
34517 this.indexMap = null;
34518 var s = this.getScrollState();
34519 this.refresh(true);
34520 this.restoreScroll(s);
34521 this.afterMove(newIndex);
34524 afterMove : function(colIndex){
34525 if(this.enableMoveAnim && Roo.enableFx){
34526 this.fly(this.getHeaderCell(colIndex).firstChild).highlight(this.hlColor);
34528 // if multisort - fix sortOrder, and reload..
34529 if (this.grid.dataSource.multiSort) {
34530 // the we can call sort again..
34531 var dm = this.grid.dataSource;
34532 var cm = this.grid.colModel;
34534 for(var i = 0; i < cm.config.length; i++ ) {
34536 if ((typeof(dm.sortToggle[cm.config[i].dataIndex]) == 'undefined')) {
34537 continue; // dont' bother, it's not in sort list or being set.
34540 so.push(cm.config[i].dataIndex);
34543 dm.load(dm.lastOptions);
34550 updateCell : function(dm, rowIndex, dataIndex){
34551 var colIndex = this.getColumnIndexByDataIndex(dataIndex);
34552 if(typeof colIndex == "undefined"){ // not present in grid
34555 var cm = this.grid.colModel;
34556 var cell = this.getCell(rowIndex, colIndex);
34557 var cellText = this.getCellText(rowIndex, colIndex);
34560 cellId : "x-grid-cell-" + rowIndex + "-" + colIndex,
34561 id : cm.getColumnId(colIndex),
34562 css: colIndex == cm.getColumnCount()-1 ? "x-grid-col-last" : ""
34564 var renderer = cm.getRenderer(colIndex);
34565 var val = renderer(dm.getValueAt(rowIndex, dataIndex), p, rowIndex, colIndex, dm);
34566 if(typeof val == "undefined" || val === "") {
34569 cellText.innerHTML = val;
34570 cell.className = this.cellClass + " " + this.idToCssName(p.cellId) + " " + p.css;
34571 this.syncRowHeights(rowIndex, rowIndex);
34574 calcColumnWidth : function(colIndex, maxRowsToMeasure){
34576 if(this.grid.autoSizeHeaders){
34577 var h = this.getHeaderCellMeasure(colIndex);
34578 maxWidth = Math.max(maxWidth, h.scrollWidth);
34581 if(this.cm.isLocked(colIndex)){
34582 tb = this.getLockedTable();
34585 tb = this.getBodyTable();
34586 index = colIndex - this.cm.getLockedCount();
34589 var rows = tb.rows;
34590 var stopIndex = Math.min(maxRowsToMeasure || rows.length, rows.length);
34591 for(var i = 0; i < stopIndex; i++){
34592 var cell = rows[i].childNodes[index].firstChild;
34593 maxWidth = Math.max(maxWidth, cell.scrollWidth);
34596 return maxWidth + /*margin for error in IE*/ 5;
34599 * Autofit a column to its content.
34600 * @param {Number} colIndex
34601 * @param {Boolean} forceMinSize true to force the column to go smaller if possible
34603 autoSizeColumn : function(colIndex, forceMinSize, suppressEvent){
34604 if(this.cm.isHidden(colIndex)){
34605 return; // can't calc a hidden column
34608 var cid = this.cm.getColumnId(colIndex);
34609 this.css.updateRule(this.colSelector +this.idToCssName( cid), "width", this.grid.minColumnWidth + "px");
34610 if(this.grid.autoSizeHeaders){
34611 this.css.updateRule(this.hdSelector + this.idToCssName(cid), "width", this.grid.minColumnWidth + "px");
34614 var newWidth = this.calcColumnWidth(colIndex);
34615 this.cm.setColumnWidth(colIndex,
34616 Math.max(this.grid.minColumnWidth, newWidth), suppressEvent);
34617 if(!suppressEvent){
34618 this.grid.fireEvent("columnresize", colIndex, newWidth);
34623 * Autofits all columns to their content and then expands to fit any extra space in the grid
34625 autoSizeColumns : function(){
34626 var cm = this.grid.colModel;
34627 var colCount = cm.getColumnCount();
34628 for(var i = 0; i < colCount; i++){
34629 this.autoSizeColumn(i, true, true);
34631 if(cm.getTotalWidth() < this.scroller.dom.clientWidth){
34634 this.updateColumns();
34640 * Autofits all columns to the grid's width proportionate with their current size
34641 * @param {Boolean} reserveScrollSpace Reserve space for a scrollbar
34643 fitColumns : function(reserveScrollSpace){
34644 var cm = this.grid.colModel;
34645 var colCount = cm.getColumnCount();
34649 for (i = 0; i < colCount; i++){
34650 if(!cm.isHidden(i) && !cm.isFixed(i)){
34651 w = cm.getColumnWidth(i);
34657 var avail = Math.min(this.scroller.dom.clientWidth, this.el.getWidth());
34658 if(reserveScrollSpace){
34661 var frac = (avail - cm.getTotalWidth())/width;
34662 while (cols.length){
34665 cm.setColumnWidth(i, Math.floor(w + w*frac), true);
34667 this.updateColumns();
34671 onRowSelect : function(rowIndex){
34672 var row = this.getRowComposite(rowIndex);
34673 row.addClass("x-grid-row-selected");
34676 onRowDeselect : function(rowIndex){
34677 var row = this.getRowComposite(rowIndex);
34678 row.removeClass("x-grid-row-selected");
34681 onCellSelect : function(row, col){
34682 var cell = this.getCell(row, col);
34684 Roo.fly(cell).addClass("x-grid-cell-selected");
34688 onCellDeselect : function(row, col){
34689 var cell = this.getCell(row, col);
34691 Roo.fly(cell).removeClass("x-grid-cell-selected");
34695 updateHeaderSortState : function(){
34697 // sort state can be single { field: xxx, direction : yyy}
34698 // or { xxx=>ASC , yyy : DESC ..... }
34701 if (!this.ds.multiSort) {
34702 var state = this.ds.getSortState();
34706 mstate[state.field] = state.direction;
34707 // FIXME... - this is not used here.. but might be elsewhere..
34708 this.sortState = state;
34711 mstate = this.ds.sortToggle;
34713 //remove existing sort classes..
34715 var sc = this.sortClasses;
34716 var hds = this.el.select(this.headerSelector).removeClass(sc);
34718 for(var f in mstate) {
34720 var sortColumn = this.cm.findColumnIndex(f);
34722 if(sortColumn != -1){
34723 var sortDir = mstate[f];
34724 hds.item(sortColumn).addClass(sc[sortDir == "DESC" ? 1 : 0]);
34733 handleHeaderClick : function(g, index,e){
34735 Roo.log("header click");
34738 // touch events on header are handled by context
34739 this.handleHdCtx(g,index,e);
34744 if(this.headersDisabled){
34747 var dm = g.dataSource, cm = g.colModel;
34748 if(!cm.isSortable(index)){
34753 if (dm.multiSort) {
34754 // update the sortOrder
34756 for(var i = 0; i < cm.config.length; i++ ) {
34758 if ((typeof(dm.sortToggle[cm.config[i].dataIndex]) == 'undefined') && (index != i)) {
34759 continue; // dont' bother, it's not in sort list or being set.
34762 so.push(cm.config[i].dataIndex);
34768 dm.sort(cm.getDataIndex(index));
34772 destroy : function(){
34774 this.colMenu.removeAll();
34775 Roo.menu.MenuMgr.unregister(this.colMenu);
34776 this.colMenu.getEl().remove();
34777 delete this.colMenu;
34780 this.hmenu.removeAll();
34781 Roo.menu.MenuMgr.unregister(this.hmenu);
34782 this.hmenu.getEl().remove();
34785 if(this.grid.enableColumnMove){
34786 var dds = Roo.dd.DDM.ids['gridHeader' + this.grid.getGridEl().id];
34788 for(var dd in dds){
34789 if(!dds[dd].config.isTarget && dds[dd].dragElId){
34790 var elid = dds[dd].dragElId;
34792 Roo.get(elid).remove();
34793 } else if(dds[dd].config.isTarget){
34794 dds[dd].proxyTop.remove();
34795 dds[dd].proxyBottom.remove();
34798 if(Roo.dd.DDM.locationCache[dd]){
34799 delete Roo.dd.DDM.locationCache[dd];
34802 delete Roo.dd.DDM.ids['gridHeader' + this.grid.getGridEl().id];
34805 Roo.util.CSS.removeStyleSheet(this.idToCssName(this.grid.id) + '-cssrules');
34806 this.bind(null, null);
34807 Roo.EventManager.removeResizeListener(this.onWindowResize, this);
34810 handleLockChange : function(){
34811 this.refresh(true);
34814 onDenyColumnLock : function(){
34818 onDenyColumnHide : function(){
34822 handleHdMenuClick : function(item){
34823 var index = this.hdCtxIndex;
34824 var cm = this.cm, ds = this.ds;
34827 ds.sort(cm.getDataIndex(index), "ASC");
34830 ds.sort(cm.getDataIndex(index), "DESC");
34833 var lc = cm.getLockedCount();
34834 if(cm.getColumnCount(true) <= lc+1){
34835 this.onDenyColumnLock();
34839 cm.setLocked(index, true, true);
34840 cm.moveColumn(index, lc);
34841 this.grid.fireEvent("columnmove", index, lc);
34843 cm.setLocked(index, true);
34847 var lc = cm.getLockedCount();
34848 if((lc-1) != index){
34849 cm.setLocked(index, false, true);
34850 cm.moveColumn(index, lc-1);
34851 this.grid.fireEvent("columnmove", index, lc-1);
34853 cm.setLocked(index, false);
34856 case 'wider': // used to expand cols on touch..
34858 var cw = cm.getColumnWidth(index);
34859 cw += (item.id == 'wider' ? 1 : -1) * 50;
34860 cw = Math.max(0, cw);
34861 cw = Math.min(cw,4000);
34862 cm.setColumnWidth(index, cw);
34866 index = cm.getIndexById(item.id.substr(4));
34868 if(item.checked && cm.getColumnCount(true) <= 1){
34869 this.onDenyColumnHide();
34872 cm.setHidden(index, item.checked);
34878 beforeColMenuShow : function(){
34879 var cm = this.cm, colCount = cm.getColumnCount();
34880 this.colMenu.removeAll();
34881 for(var i = 0; i < colCount; i++){
34882 this.colMenu.add(new Roo.menu.CheckItem({
34883 id: "col-"+cm.getColumnId(i),
34884 text: cm.getColumnHeader(i),
34885 checked: !cm.isHidden(i),
34891 handleHdCtx : function(g, index, e){
34893 var hd = this.getHeaderCell(index);
34894 this.hdCtxIndex = index;
34895 var ms = this.hmenu.items, cm = this.cm;
34896 ms.get("asc").setDisabled(!cm.isSortable(index));
34897 ms.get("desc").setDisabled(!cm.isSortable(index));
34898 if(this.grid.enableColLock !== false){
34899 ms.get("lock").setDisabled(cm.isLocked(index));
34900 ms.get("unlock").setDisabled(!cm.isLocked(index));
34902 this.hmenu.show(hd, "tl-bl");
34905 handleHdOver : function(e){
34906 var hd = this.findHeaderCell(e.getTarget());
34907 if(hd && !this.headersDisabled){
34908 if(this.grid.colModel.isSortable(this.getCellIndex(hd))){
34909 this.fly(hd).addClass("x-grid-hd-over");
34914 handleHdOut : function(e){
34915 var hd = this.findHeaderCell(e.getTarget());
34917 this.fly(hd).removeClass("x-grid-hd-over");
34921 handleSplitDblClick : function(e, t){
34922 var i = this.getCellIndex(t);
34923 if(this.grid.enableColumnResize !== false && this.cm.isResizable(i) && !this.cm.isFixed(i)){
34924 this.autoSizeColumn(i, true);
34929 render : function(){
34932 var colCount = cm.getColumnCount();
34934 if(this.grid.monitorWindowResize === true){
34935 Roo.EventManager.onWindowResize(this.onWindowResize, this, true);
34937 var header = this.renderHeaders();
34938 var body = this.templates.body.apply({rows:""});
34939 var html = this.templates.master.apply({
34942 lockedHeader: header[0],
34946 //this.updateColumns();
34948 this.grid.getGridEl().dom.innerHTML = html;
34950 this.initElements();
34952 // a kludge to fix the random scolling effect in webkit
34953 this.el.on("scroll", function() {
34954 this.el.dom.scrollTop=0; // hopefully not recursive..
34957 this.scroller.on("scroll", this.handleScroll, this);
34958 this.lockedBody.on("mousewheel", this.handleWheel, this);
34959 this.mainBody.on("mousewheel", this.handleWheel, this);
34961 this.mainHd.on("mouseover", this.handleHdOver, this);
34962 this.mainHd.on("mouseout", this.handleHdOut, this);
34963 this.mainHd.on("dblclick", this.handleSplitDblClick, this,
34964 {delegate: "."+this.splitClass});
34966 this.lockedHd.on("mouseover", this.handleHdOver, this);
34967 this.lockedHd.on("mouseout", this.handleHdOut, this);
34968 this.lockedHd.on("dblclick", this.handleSplitDblClick, this,
34969 {delegate: "."+this.splitClass});
34971 if(this.grid.enableColumnResize !== false && Roo.grid.SplitDragZone){
34972 new Roo.grid.SplitDragZone(this.grid, this.lockedHd.dom, this.mainHd.dom);
34975 this.updateSplitters();
34977 if(this.grid.enableColumnMove && Roo.grid.HeaderDragZone){
34978 new Roo.grid.HeaderDragZone(this.grid, this.lockedHd.dom, this.mainHd.dom);
34979 new Roo.grid.HeaderDropZone(this.grid, this.lockedHd.dom, this.mainHd.dom);
34982 if(this.grid.enableCtxMenu !== false && Roo.menu.Menu){
34983 this.hmenu = new Roo.menu.Menu({id: this.grid.id + "-hctx"});
34985 {id:"asc", text: this.sortAscText, cls: "xg-hmenu-sort-asc"},
34986 {id:"desc", text: this.sortDescText, cls: "xg-hmenu-sort-desc"}
34988 if(this.grid.enableColLock !== false){
34989 this.hmenu.add('-',
34990 {id:"lock", text: this.lockText, cls: "xg-hmenu-lock"},
34991 {id:"unlock", text: this.unlockText, cls: "xg-hmenu-unlock"}
34995 this.hmenu.add('-',
34996 {id:"wider", text: this.columnsWiderText},
34997 {id:"narrow", text: this.columnsNarrowText }
35003 if(this.grid.enableColumnHide !== false){
35005 this.colMenu = new Roo.menu.Menu({id:this.grid.id + "-hcols-menu"});
35006 this.colMenu.on("beforeshow", this.beforeColMenuShow, this);
35007 this.colMenu.on("itemclick", this.handleHdMenuClick, this);
35009 this.hmenu.add('-',
35010 {id:"columns", text: this.columnsText, menu: this.colMenu}
35013 this.hmenu.on("itemclick", this.handleHdMenuClick, this);
35015 this.grid.on("headercontextmenu", this.handleHdCtx, this);
35018 if((this.grid.enableDragDrop || this.grid.enableDrag) && Roo.grid.GridDragZone){
35019 this.dd = new Roo.grid.GridDragZone(this.grid, {
35020 ddGroup : this.grid.ddGroup || 'GridDD'
35026 for(var i = 0; i < colCount; i++){
35027 if(cm.isHidden(i)){
35028 this.hideColumn(i);
35030 if(cm.config[i].align){
35031 this.css.updateRule(this.colSelector + i, "textAlign", cm.config[i].align);
35032 this.css.updateRule(this.hdSelector + i, "textAlign", cm.config[i].align);
35036 this.updateHeaderSortState();
35038 this.beforeInitialResize();
35041 // two part rendering gives faster view to the user
35042 this.renderPhase2.defer(1, this);
35045 renderPhase2 : function(){
35046 // render the rows now
35048 if(this.grid.autoSizeColumns){
35049 this.autoSizeColumns();
35053 beforeInitialResize : function(){
35057 onColumnSplitterMoved : function(i, w){
35058 this.userResized = true;
35059 var cm = this.grid.colModel;
35060 cm.setColumnWidth(i, w, true);
35061 var cid = cm.getColumnId(i);
35062 this.css.updateRule(this.colSelector + this.idToCssName(cid), "width", (w-this.borderWidth) + "px");
35063 this.css.updateRule(this.hdSelector + this.idToCssName(cid), "width", (w-this.borderWidth) + "px");
35064 this.updateSplitters();
35066 this.grid.fireEvent("columnresize", i, w);
35069 syncRowHeights : function(startIndex, endIndex){
35070 if(this.grid.enableRowHeightSync === true && this.cm.getLockedCount() > 0){
35071 startIndex = startIndex || 0;
35072 var mrows = this.getBodyTable().rows;
35073 var lrows = this.getLockedTable().rows;
35074 var len = mrows.length-1;
35075 endIndex = Math.min(endIndex || len, len);
35076 for(var i = startIndex; i <= endIndex; i++){
35077 var m = mrows[i], l = lrows[i];
35078 var h = Math.max(m.offsetHeight, l.offsetHeight);
35079 m.style.height = l.style.height = h + "px";
35084 layout : function(initialRender, is2ndPass){
35086 var auto = g.autoHeight;
35087 var scrollOffset = 16;
35088 var c = g.getGridEl(), cm = this.cm,
35089 expandCol = g.autoExpandColumn,
35091 //c.beginMeasure();
35093 if(!c.dom.offsetWidth){ // display:none?
35095 this.lockedWrap.show();
35096 this.mainWrap.show();
35101 var hasLock = this.cm.isLocked(0);
35103 var tbh = this.headerPanel.getHeight();
35104 var bbh = this.footerPanel.getHeight();
35107 var ch = this.getBodyTable().offsetHeight + tbh + bbh + this.mainHd.getHeight();
35108 var newHeight = ch + c.getBorderWidth("tb");
35110 newHeight = Math.min(g.maxHeight, newHeight);
35112 c.setHeight(newHeight);
35116 c.setWidth(cm.getTotalWidth()+c.getBorderWidth('lr'));
35119 var s = this.scroller;
35121 var csize = c.getSize(true);
35123 this.el.setSize(csize.width, csize.height);
35125 this.headerPanel.setWidth(csize.width);
35126 this.footerPanel.setWidth(csize.width);
35128 var hdHeight = this.mainHd.getHeight();
35129 var vw = csize.width;
35130 var vh = csize.height - (tbh + bbh);
35134 var bt = this.getBodyTable();
35136 if(cm.getLockedCount() == cm.config.length){
35137 bt = this.getLockedTable();
35140 var ltWidth = hasLock ?
35141 Math.max(this.getLockedTable().offsetWidth, this.lockedHd.dom.firstChild.offsetWidth) : 0;
35143 var scrollHeight = bt.offsetHeight;
35144 var scrollWidth = ltWidth + bt.offsetWidth;
35145 var vscroll = false, hscroll = false;
35147 this.scrollSizer.setSize(scrollWidth, scrollHeight+hdHeight);
35149 var lw = this.lockedWrap, mw = this.mainWrap;
35150 var lb = this.lockedBody, mb = this.mainBody;
35152 setTimeout(function(){
35153 var t = s.dom.offsetTop;
35154 var w = s.dom.clientWidth,
35155 h = s.dom.clientHeight;
35158 lw.setSize(ltWidth, h);
35160 mw.setLeftTop(ltWidth, t);
35161 mw.setSize(w-ltWidth, h);
35163 lb.setHeight(h-hdHeight);
35164 mb.setHeight(h-hdHeight);
35166 if(is2ndPass !== true && !gv.userResized && expandCol){
35167 // high speed resize without full column calculation
35169 var ci = cm.getIndexById(expandCol);
35171 ci = cm.findColumnIndex(expandCol);
35173 ci = Math.max(0, ci); // make sure it's got at least the first col.
35174 var expandId = cm.getColumnId(ci);
35175 var tw = cm.getTotalWidth(false);
35176 var currentWidth = cm.getColumnWidth(ci);
35177 var cw = Math.min(Math.max(((w-tw)+currentWidth-2)-/*scrollbar*/(w <= s.dom.offsetWidth ? 0 : 18), g.autoExpandMin), g.autoExpandMax);
35178 if(currentWidth != cw){
35179 cm.setColumnWidth(ci, cw, true);
35180 gv.css.updateRule(gv.colSelector+gv.idToCssName(expandId), "width", (cw - gv.borderWidth) + "px");
35181 gv.css.updateRule(gv.hdSelector+gv.idToCssName(expandId), "width", (cw - gv.borderWidth) + "px");
35182 gv.updateSplitters();
35183 gv.layout(false, true);
35195 onWindowResize : function(){
35196 if(!this.grid.monitorWindowResize || this.grid.autoHeight){
35202 appendFooter : function(parentEl){
35206 sortAscText : "Sort Ascending",
35207 sortDescText : "Sort Descending",
35208 lockText : "Lock Column",
35209 unlockText : "Unlock Column",
35210 columnsText : "Columns",
35212 columnsWiderText : "Wider",
35213 columnsNarrowText : "Thinner"
35217 Roo.grid.GridView.ColumnDragZone = function(grid, hd){
35218 Roo.grid.GridView.ColumnDragZone.superclass.constructor.call(this, grid, hd, null);
35219 this.proxy.el.addClass('x-grid3-col-dd');
35222 Roo.extend(Roo.grid.GridView.ColumnDragZone, Roo.grid.HeaderDragZone, {
35223 handleMouseDown : function(e){
35227 callHandleMouseDown : function(e){
35228 Roo.grid.GridView.ColumnDragZone.superclass.handleMouseDown.call(this, e);
35233 * Ext JS Library 1.1.1
35234 * Copyright(c) 2006-2007, Ext JS, LLC.
35236 * Originally Released Under LGPL - original licence link has changed is not relivant.
35239 * <script type="text/javascript">
35243 // This is a support class used internally by the Grid components
35244 Roo.grid.SplitDragZone = function(grid, hd, hd2){
35246 this.view = grid.getView();
35247 this.proxy = this.view.resizeProxy;
35248 Roo.grid.SplitDragZone.superclass.constructor.call(this, hd,
35249 "gridSplitters" + this.grid.getGridEl().id, {
35250 dragElId : Roo.id(this.proxy.dom), resizeFrame:false
35252 this.setHandleElId(Roo.id(hd));
35253 this.setOuterHandleElId(Roo.id(hd2));
35254 this.scroll = false;
35256 Roo.extend(Roo.grid.SplitDragZone, Roo.dd.DDProxy, {
35257 fly: Roo.Element.fly,
35259 b4StartDrag : function(x, y){
35260 this.view.headersDisabled = true;
35261 this.proxy.setHeight(this.view.mainWrap.getHeight());
35262 var w = this.cm.getColumnWidth(this.cellIndex);
35263 var minw = Math.max(w-this.grid.minColumnWidth, 0);
35264 this.resetConstraints();
35265 this.setXConstraint(minw, 1000);
35266 this.setYConstraint(0, 0);
35267 this.minX = x - minw;
35268 this.maxX = x + 1000;
35270 Roo.dd.DDProxy.prototype.b4StartDrag.call(this, x, y);
35274 handleMouseDown : function(e){
35275 ev = Roo.EventObject.setEvent(e);
35276 var t = this.fly(ev.getTarget());
35277 if(t.hasClass("x-grid-split")){
35278 this.cellIndex = this.view.getCellIndex(t.dom);
35279 this.split = t.dom;
35280 this.cm = this.grid.colModel;
35281 if(this.cm.isResizable(this.cellIndex) && !this.cm.isFixed(this.cellIndex)){
35282 Roo.grid.SplitDragZone.superclass.handleMouseDown.apply(this, arguments);
35287 endDrag : function(e){
35288 this.view.headersDisabled = false;
35289 var endX = Math.max(this.minX, Roo.lib.Event.getPageX(e));
35290 var diff = endX - this.startPos;
35291 this.view.onColumnSplitterMoved(this.cellIndex, this.cm.getColumnWidth(this.cellIndex)+diff);
35294 autoOffset : function(){
35295 this.setDelta(0,0);
35299 * Ext JS Library 1.1.1
35300 * Copyright(c) 2006-2007, Ext JS, LLC.
35302 * Originally Released Under LGPL - original licence link has changed is not relivant.
35305 * <script type="text/javascript">
35309 // This is a support class used internally by the Grid components
35310 Roo.grid.GridDragZone = function(grid, config){
35311 this.view = grid.getView();
35312 Roo.grid.GridDragZone.superclass.constructor.call(this, this.view.mainBody.dom, config);
35313 if(this.view.lockedBody){
35314 this.setHandleElId(Roo.id(this.view.mainBody.dom));
35315 this.setOuterHandleElId(Roo.id(this.view.lockedBody.dom));
35317 this.scroll = false;
35319 this.ddel = document.createElement('div');
35320 this.ddel.className = 'x-grid-dd-wrap';
35323 Roo.extend(Roo.grid.GridDragZone, Roo.dd.DragZone, {
35324 ddGroup : "GridDD",
35326 getDragData : function(e){
35327 var t = Roo.lib.Event.getTarget(e);
35328 var rowIndex = this.view.findRowIndex(t);
35329 var sm = this.grid.selModel;
35331 //Roo.log(rowIndex);
35333 if (sm.getSelectedCell) {
35334 // cell selection..
35335 if (!sm.getSelectedCell()) {
35338 if (rowIndex != sm.getSelectedCell()[0]) {
35344 if(rowIndex !== false){
35349 //Roo.log([ sm.getSelectedCell() ? sm.getSelectedCell()[0] : 'NO' , rowIndex ]);
35351 //if(!sm.isSelected(rowIndex) || e.hasModifier()){
35354 if (e.hasModifier()){
35355 sm.handleMouseDown(e, t); // non modifier buttons are handled by row select.
35358 Roo.log("getDragData");
35363 rowIndex: rowIndex,
35364 selections:sm.getSelections ? sm.getSelections() : (
35365 sm.getSelectedCell() ? [ this.grid.ds.getAt(sm.getSelectedCell()[0]) ] : []
35372 onInitDrag : function(e){
35373 var data = this.dragData;
35374 this.ddel.innerHTML = this.grid.getDragDropText();
35375 this.proxy.update(this.ddel);
35376 // fire start drag?
35379 afterRepair : function(){
35380 this.dragging = false;
35383 getRepairXY : function(e, data){
35387 onEndDrag : function(data, e){
35391 onValidDrop : function(dd, e, id){
35396 beforeInvalidDrop : function(e, id){
35401 * Ext JS Library 1.1.1
35402 * Copyright(c) 2006-2007, Ext JS, LLC.
35404 * Originally Released Under LGPL - original licence link has changed is not relivant.
35407 * <script type="text/javascript">
35412 * @class Roo.grid.ColumnModel
35413 * @extends Roo.util.Observable
35414 * This is the default implementation of a ColumnModel used by the Grid. It defines
35415 * the columns in the grid.
35418 var colModel = new Roo.grid.ColumnModel([
35419 {header: "Ticker", width: 60, sortable: true, locked: true},
35420 {header: "Company Name", width: 150, sortable: true},
35421 {header: "Market Cap.", width: 100, sortable: true},
35422 {header: "$ Sales", width: 100, sortable: true, renderer: money},
35423 {header: "Employees", width: 100, sortable: true, resizable: false}
35428 * The config options listed for this class are options which may appear in each
35429 * individual column definition.
35430 * <br/>RooJS Fix - column id's are not sequential but use Roo.id() - fixes bugs with layouts.
35432 * @param {Object} config An Array of column config objects. See this class's
35433 * config objects for details.
35435 Roo.grid.ColumnModel = function(config){
35437 * The config passed into the constructor
35439 this.config = config;
35442 // if no id, create one
35443 // if the column does not have a dataIndex mapping,
35444 // map it to the order it is in the config
35445 for(var i = 0, len = config.length; i < len; i++){
35447 if(typeof c.dataIndex == "undefined"){
35450 if(typeof c.renderer == "string"){
35451 c.renderer = Roo.util.Format[c.renderer];
35453 if(typeof c.id == "undefined"){
35456 if(c.editor && c.editor.xtype){
35457 c.editor = Roo.factory(c.editor, Roo.grid);
35459 if(c.editor && c.editor.isFormField){
35460 c.editor = new Roo.grid.GridEditor(c.editor);
35462 this.lookup[c.id] = c;
35466 * The width of columns which have no width specified (defaults to 100)
35469 this.defaultWidth = 100;
35472 * Default sortable of columns which have no sortable specified (defaults to false)
35475 this.defaultSortable = false;
35479 * @event widthchange
35480 * Fires when the width of a column changes.
35481 * @param {ColumnModel} this
35482 * @param {Number} columnIndex The column index
35483 * @param {Number} newWidth The new width
35485 "widthchange": true,
35487 * @event headerchange
35488 * Fires when the text of a header changes.
35489 * @param {ColumnModel} this
35490 * @param {Number} columnIndex The column index
35491 * @param {Number} newText The new header text
35493 "headerchange": true,
35495 * @event hiddenchange
35496 * Fires when a column is hidden or "unhidden".
35497 * @param {ColumnModel} this
35498 * @param {Number} columnIndex The column index
35499 * @param {Boolean} hidden true if hidden, false otherwise
35501 "hiddenchange": true,
35503 * @event columnmoved
35504 * Fires when a column is moved.
35505 * @param {ColumnModel} this
35506 * @param {Number} oldIndex
35507 * @param {Number} newIndex
35509 "columnmoved" : true,
35511 * @event columlockchange
35512 * Fires when a column's locked state is changed
35513 * @param {ColumnModel} this
35514 * @param {Number} colIndex
35515 * @param {Boolean} locked true if locked
35517 "columnlockchange" : true
35519 Roo.grid.ColumnModel.superclass.constructor.call(this);
35521 Roo.extend(Roo.grid.ColumnModel, Roo.util.Observable, {
35523 * @cfg {String} header The header text to display in the Grid view.
35526 * @cfg {String} dataIndex (Optional) The name of the field in the grid's {@link Roo.data.Store}'s
35527 * {@link Roo.data.Record} definition from which to draw the column's value. If not
35528 * specified, the column's index is used as an index into the Record's data Array.
35531 * @cfg {Number} width (Optional) The initial width in pixels of the column. Using this
35532 * instead of {@link Roo.grid.Grid#autoSizeColumns} is more efficient.
35535 * @cfg {Boolean} sortable (Optional) True if sorting is to be allowed on this column.
35536 * Defaults to the value of the {@link #defaultSortable} property.
35537 * Whether local/remote sorting is used is specified in {@link Roo.data.Store#remoteSort}.
35540 * @cfg {Boolean} locked (Optional) True to lock the column in place while scrolling the Grid. Defaults to false.
35543 * @cfg {Boolean} fixed (Optional) True if the column width cannot be changed. Defaults to false.
35546 * @cfg {Boolean} resizable (Optional) False to disable column resizing. Defaults to true.
35549 * @cfg {Boolean} hidden (Optional) True to hide the column. Defaults to false.
35552 * @cfg {Function} renderer (Optional) A function used to generate HTML markup for a cell
35553 * given the cell's data value. See {@link #setRenderer}. If not specified, the
35554 * default renderer returns the escaped data value. If an object is returned (bootstrap only)
35555 * then it is treated as a Roo Component object instance, and it is rendered after the initial row is rendered
35558 * @cfg {Roo.grid.GridEditor} editor (Optional) For grid editors - returns the grid editor
35561 * @cfg {String} align (Optional) Set the CSS text-align property of the column. Defaults to undefined.
35564 * @cfg {String} valign (Optional) Set the CSS vertical-align property of the column (eg. middle, top, bottom etc). Defaults to undefined.
35567 * @cfg {String} cursor (Optional)
35570 * @cfg {String} tooltip (Optional)
35573 * @cfg {Number} xs (Optional)
35576 * @cfg {Number} sm (Optional)
35579 * @cfg {Number} md (Optional)
35582 * @cfg {Number} lg (Optional)
35585 * Returns the id of the column at the specified index.
35586 * @param {Number} index The column index
35587 * @return {String} the id
35589 getColumnId : function(index){
35590 return this.config[index].id;
35594 * Returns the column for a specified id.
35595 * @param {String} id The column id
35596 * @return {Object} the column
35598 getColumnById : function(id){
35599 return this.lookup[id];
35604 * Returns the column for a specified dataIndex.
35605 * @param {String} dataIndex The column dataIndex
35606 * @return {Object|Boolean} the column or false if not found
35608 getColumnByDataIndex: function(dataIndex){
35609 var index = this.findColumnIndex(dataIndex);
35610 return index > -1 ? this.config[index] : false;
35614 * Returns the index for a specified column id.
35615 * @param {String} id The column id
35616 * @return {Number} the index, or -1 if not found
35618 getIndexById : function(id){
35619 for(var i = 0, len = this.config.length; i < len; i++){
35620 if(this.config[i].id == id){
35628 * Returns the index for a specified column dataIndex.
35629 * @param {String} dataIndex The column dataIndex
35630 * @return {Number} the index, or -1 if not found
35633 findColumnIndex : function(dataIndex){
35634 for(var i = 0, len = this.config.length; i < len; i++){
35635 if(this.config[i].dataIndex == dataIndex){
35643 moveColumn : function(oldIndex, newIndex){
35644 var c = this.config[oldIndex];
35645 this.config.splice(oldIndex, 1);
35646 this.config.splice(newIndex, 0, c);
35647 this.dataMap = null;
35648 this.fireEvent("columnmoved", this, oldIndex, newIndex);
35651 isLocked : function(colIndex){
35652 return this.config[colIndex].locked === true;
35655 setLocked : function(colIndex, value, suppressEvent){
35656 if(this.isLocked(colIndex) == value){
35659 this.config[colIndex].locked = value;
35660 if(!suppressEvent){
35661 this.fireEvent("columnlockchange", this, colIndex, value);
35665 getTotalLockedWidth : function(){
35666 var totalWidth = 0;
35667 for(var i = 0; i < this.config.length; i++){
35668 if(this.isLocked(i) && !this.isHidden(i)){
35669 this.totalWidth += this.getColumnWidth(i);
35675 getLockedCount : function(){
35676 for(var i = 0, len = this.config.length; i < len; i++){
35677 if(!this.isLocked(i)){
35682 return this.config.length;
35686 * Returns the number of columns.
35689 getColumnCount : function(visibleOnly){
35690 if(visibleOnly === true){
35692 for(var i = 0, len = this.config.length; i < len; i++){
35693 if(!this.isHidden(i)){
35699 return this.config.length;
35703 * Returns the column configs that return true by the passed function that is called with (columnConfig, index)
35704 * @param {Function} fn
35705 * @param {Object} scope (optional)
35706 * @return {Array} result
35708 getColumnsBy : function(fn, scope){
35710 for(var i = 0, len = this.config.length; i < len; i++){
35711 var c = this.config[i];
35712 if(fn.call(scope||this, c, i) === true){
35720 * Returns true if the specified column is sortable.
35721 * @param {Number} col The column index
35722 * @return {Boolean}
35724 isSortable : function(col){
35725 if(typeof this.config[col].sortable == "undefined"){
35726 return this.defaultSortable;
35728 return this.config[col].sortable;
35732 * Returns the rendering (formatting) function defined for the column.
35733 * @param {Number} col The column index.
35734 * @return {Function} The function used to render the cell. See {@link #setRenderer}.
35736 getRenderer : function(col){
35737 if(!this.config[col].renderer){
35738 return Roo.grid.ColumnModel.defaultRenderer;
35740 return this.config[col].renderer;
35744 * Sets the rendering (formatting) function for a column.
35745 * @param {Number} col The column index
35746 * @param {Function} fn The function to use to process the cell's raw data
35747 * to return HTML markup for the grid view. The render function is called with
35748 * the following parameters:<ul>
35749 * <li>Data value.</li>
35750 * <li>Cell metadata. An object in which you may set the following attributes:<ul>
35751 * <li>css A CSS style string to apply to the table cell.</li>
35752 * <li>attr An HTML attribute definition string to apply to the data container element <i>within</i> the table cell.</li></ul>
35753 * <li>The {@link Roo.data.Record} from which the data was extracted.</li>
35754 * <li>Row index</li>
35755 * <li>Column index</li>
35756 * <li>The {@link Roo.data.Store} object from which the Record was extracted</li></ul>
35758 setRenderer : function(col, fn){
35759 this.config[col].renderer = fn;
35763 * Returns the width for the specified column.
35764 * @param {Number} col The column index
35767 getColumnWidth : function(col){
35768 return this.config[col].width * 1 || this.defaultWidth;
35772 * Sets the width for a column.
35773 * @param {Number} col The column index
35774 * @param {Number} width The new width
35776 setColumnWidth : function(col, width, suppressEvent){
35777 this.config[col].width = width;
35778 this.totalWidth = null;
35779 if(!suppressEvent){
35780 this.fireEvent("widthchange", this, col, width);
35785 * Returns the total width of all columns.
35786 * @param {Boolean} includeHidden True to include hidden column widths
35789 getTotalWidth : function(includeHidden){
35790 if(!this.totalWidth){
35791 this.totalWidth = 0;
35792 for(var i = 0, len = this.config.length; i < len; i++){
35793 if(includeHidden || !this.isHidden(i)){
35794 this.totalWidth += this.getColumnWidth(i);
35798 return this.totalWidth;
35802 * Returns the header for the specified column.
35803 * @param {Number} col The column index
35806 getColumnHeader : function(col){
35807 return this.config[col].header;
35811 * Sets the header for a column.
35812 * @param {Number} col The column index
35813 * @param {String} header The new header
35815 setColumnHeader : function(col, header){
35816 this.config[col].header = header;
35817 this.fireEvent("headerchange", this, col, header);
35821 * Returns the tooltip for the specified column.
35822 * @param {Number} col The column index
35825 getColumnTooltip : function(col){
35826 return this.config[col].tooltip;
35829 * Sets the tooltip for a column.
35830 * @param {Number} col The column index
35831 * @param {String} tooltip The new tooltip
35833 setColumnTooltip : function(col, tooltip){
35834 this.config[col].tooltip = tooltip;
35838 * Returns the dataIndex for the specified column.
35839 * @param {Number} col The column index
35842 getDataIndex : function(col){
35843 return this.config[col].dataIndex;
35847 * Sets the dataIndex for a column.
35848 * @param {Number} col The column index
35849 * @param {Number} dataIndex The new dataIndex
35851 setDataIndex : function(col, dataIndex){
35852 this.config[col].dataIndex = dataIndex;
35858 * Returns true if the cell is editable.
35859 * @param {Number} colIndex The column index
35860 * @param {Number} rowIndex The row index - this is nto actually used..?
35861 * @return {Boolean}
35863 isCellEditable : function(colIndex, rowIndex){
35864 return (this.config[colIndex].editable || (typeof this.config[colIndex].editable == "undefined" && this.config[colIndex].editor)) ? true : false;
35868 * Returns the editor defined for the cell/column.
35869 * return false or null to disable editing.
35870 * @param {Number} colIndex The column index
35871 * @param {Number} rowIndex The row index
35874 getCellEditor : function(colIndex, rowIndex){
35875 return this.config[colIndex].editor;
35879 * Sets if a column is editable.
35880 * @param {Number} col The column index
35881 * @param {Boolean} editable True if the column is editable
35883 setEditable : function(col, editable){
35884 this.config[col].editable = editable;
35889 * Returns true if the column is hidden.
35890 * @param {Number} colIndex The column index
35891 * @return {Boolean}
35893 isHidden : function(colIndex){
35894 return this.config[colIndex].hidden;
35899 * Returns true if the column width cannot be changed
35901 isFixed : function(colIndex){
35902 return this.config[colIndex].fixed;
35906 * Returns true if the column can be resized
35907 * @return {Boolean}
35909 isResizable : function(colIndex){
35910 return colIndex >= 0 && this.config[colIndex].resizable !== false && this.config[colIndex].fixed !== true;
35913 * Sets if a column is hidden.
35914 * @param {Number} colIndex The column index
35915 * @param {Boolean} hidden True if the column is hidden
35917 setHidden : function(colIndex, hidden){
35918 this.config[colIndex].hidden = hidden;
35919 this.totalWidth = null;
35920 this.fireEvent("hiddenchange", this, colIndex, hidden);
35924 * Sets the editor for a column.
35925 * @param {Number} col The column index
35926 * @param {Object} editor The editor object
35928 setEditor : function(col, editor){
35929 this.config[col].editor = editor;
35933 Roo.grid.ColumnModel.defaultRenderer = function(value)
35935 if(typeof value == "object") {
35938 if(typeof value == "string" && value.length < 1){
35942 return String.format("{0}", value);
35945 // Alias for backwards compatibility
35946 Roo.grid.DefaultColumnModel = Roo.grid.ColumnModel;
35949 * Ext JS Library 1.1.1
35950 * Copyright(c) 2006-2007, Ext JS, LLC.
35952 * Originally Released Under LGPL - original licence link has changed is not relivant.
35955 * <script type="text/javascript">
35959 * @class Roo.grid.AbstractSelectionModel
35960 * @extends Roo.util.Observable
35961 * Abstract base class for grid SelectionModels. It provides the interface that should be
35962 * implemented by descendant classes. This class should not be directly instantiated.
35965 Roo.grid.AbstractSelectionModel = function(){
35966 this.locked = false;
35967 Roo.grid.AbstractSelectionModel.superclass.constructor.call(this);
35970 Roo.extend(Roo.grid.AbstractSelectionModel, Roo.util.Observable, {
35971 /** @ignore Called by the grid automatically. Do not call directly. */
35972 init : function(grid){
35978 * Locks the selections.
35981 this.locked = true;
35985 * Unlocks the selections.
35987 unlock : function(){
35988 this.locked = false;
35992 * Returns true if the selections are locked.
35993 * @return {Boolean}
35995 isLocked : function(){
35996 return this.locked;
36000 * Ext JS Library 1.1.1
36001 * Copyright(c) 2006-2007, Ext JS, LLC.
36003 * Originally Released Under LGPL - original licence link has changed is not relivant.
36006 * <script type="text/javascript">
36009 * @extends Roo.grid.AbstractSelectionModel
36010 * @class Roo.grid.RowSelectionModel
36011 * The default SelectionModel used by {@link Roo.grid.Grid}.
36012 * It supports multiple selections and keyboard selection/navigation.
36014 * @param {Object} config
36016 Roo.grid.RowSelectionModel = function(config){
36017 Roo.apply(this, config);
36018 this.selections = new Roo.util.MixedCollection(false, function(o){
36023 this.lastActive = false;
36027 * @event selectionchange
36028 * Fires when the selection changes
36029 * @param {SelectionModel} this
36031 "selectionchange" : true,
36033 * @event afterselectionchange
36034 * Fires after the selection changes (eg. by key press or clicking)
36035 * @param {SelectionModel} this
36037 "afterselectionchange" : true,
36039 * @event beforerowselect
36040 * Fires when a row is selected being selected, return false to cancel.
36041 * @param {SelectionModel} this
36042 * @param {Number} rowIndex The selected index
36043 * @param {Boolean} keepExisting False if other selections will be cleared
36045 "beforerowselect" : true,
36048 * Fires when a row is selected.
36049 * @param {SelectionModel} this
36050 * @param {Number} rowIndex The selected index
36051 * @param {Roo.data.Record} r The record
36053 "rowselect" : true,
36055 * @event rowdeselect
36056 * Fires when a row is deselected.
36057 * @param {SelectionModel} this
36058 * @param {Number} rowIndex The selected index
36060 "rowdeselect" : true
36062 Roo.grid.RowSelectionModel.superclass.constructor.call(this);
36063 this.locked = false;
36066 Roo.extend(Roo.grid.RowSelectionModel, Roo.grid.AbstractSelectionModel, {
36068 * @cfg {Boolean} singleSelect
36069 * True to allow selection of only one row at a time (defaults to false)
36071 singleSelect : false,
36074 initEvents : function(){
36076 if(!this.grid.enableDragDrop && !this.grid.enableDrag){
36077 this.grid.on("mousedown", this.handleMouseDown, this);
36078 }else{ // allow click to work like normal
36079 this.grid.on("rowclick", this.handleDragableRowClick, this);
36082 this.rowNav = new Roo.KeyNav(this.grid.getGridEl(), {
36083 "up" : function(e){
36085 this.selectPrevious(e.shiftKey);
36086 }else if(this.last !== false && this.lastActive !== false){
36087 var last = this.last;
36088 this.selectRange(this.last, this.lastActive-1);
36089 this.grid.getView().focusRow(this.lastActive);
36090 if(last !== false){
36094 this.selectFirstRow();
36096 this.fireEvent("afterselectionchange", this);
36098 "down" : function(e){
36100 this.selectNext(e.shiftKey);
36101 }else if(this.last !== false && this.lastActive !== false){
36102 var last = this.last;
36103 this.selectRange(this.last, this.lastActive+1);
36104 this.grid.getView().focusRow(this.lastActive);
36105 if(last !== false){
36109 this.selectFirstRow();
36111 this.fireEvent("afterselectionchange", this);
36116 var view = this.grid.view;
36117 view.on("refresh", this.onRefresh, this);
36118 view.on("rowupdated", this.onRowUpdated, this);
36119 view.on("rowremoved", this.onRemove, this);
36123 onRefresh : function(){
36124 var ds = this.grid.dataSource, i, v = this.grid.view;
36125 var s = this.selections;
36126 s.each(function(r){
36127 if((i = ds.indexOfId(r.id)) != -1){
36129 s.add(ds.getAt(i)); // updating the selection relate data
36137 onRemove : function(v, index, r){
36138 this.selections.remove(r);
36142 onRowUpdated : function(v, index, r){
36143 if(this.isSelected(r)){
36144 v.onRowSelect(index);
36150 * @param {Array} records The records to select
36151 * @param {Boolean} keepExisting (optional) True to keep existing selections
36153 selectRecords : function(records, keepExisting){
36155 this.clearSelections();
36157 var ds = this.grid.dataSource;
36158 for(var i = 0, len = records.length; i < len; i++){
36159 this.selectRow(ds.indexOf(records[i]), true);
36164 * Gets the number of selected rows.
36167 getCount : function(){
36168 return this.selections.length;
36172 * Selects the first row in the grid.
36174 selectFirstRow : function(){
36179 * Select the last row.
36180 * @param {Boolean} keepExisting (optional) True to keep existing selections
36182 selectLastRow : function(keepExisting){
36183 this.selectRow(this.grid.dataSource.getCount() - 1, keepExisting);
36187 * Selects the row immediately following the last selected row.
36188 * @param {Boolean} keepExisting (optional) True to keep existing selections
36190 selectNext : function(keepExisting){
36191 if(this.last !== false && (this.last+1) < this.grid.dataSource.getCount()){
36192 this.selectRow(this.last+1, keepExisting);
36193 this.grid.getView().focusRow(this.last);
36198 * Selects the row that precedes the last selected row.
36199 * @param {Boolean} keepExisting (optional) True to keep existing selections
36201 selectPrevious : function(keepExisting){
36203 this.selectRow(this.last-1, keepExisting);
36204 this.grid.getView().focusRow(this.last);
36209 * Returns the selected records
36210 * @return {Array} Array of selected records
36212 getSelections : function(){
36213 return [].concat(this.selections.items);
36217 * Returns the first selected record.
36220 getSelected : function(){
36221 return this.selections.itemAt(0);
36226 * Clears all selections.
36228 clearSelections : function(fast){
36233 var ds = this.grid.dataSource;
36234 var s = this.selections;
36235 s.each(function(r){
36236 this.deselectRow(ds.indexOfId(r.id));
36240 this.selections.clear();
36247 * Selects all rows.
36249 selectAll : function(){
36253 this.selections.clear();
36254 for(var i = 0, len = this.grid.dataSource.getCount(); i < len; i++){
36255 this.selectRow(i, true);
36260 * Returns True if there is a selection.
36261 * @return {Boolean}
36263 hasSelection : function(){
36264 return this.selections.length > 0;
36268 * Returns True if the specified row is selected.
36269 * @param {Number/Record} record The record or index of the record to check
36270 * @return {Boolean}
36272 isSelected : function(index){
36273 var r = typeof index == "number" ? this.grid.dataSource.getAt(index) : index;
36274 return (r && this.selections.key(r.id) ? true : false);
36278 * Returns True if the specified record id is selected.
36279 * @param {String} id The id of record to check
36280 * @return {Boolean}
36282 isIdSelected : function(id){
36283 return (this.selections.key(id) ? true : false);
36287 handleMouseDown : function(e, t){
36288 var view = this.grid.getView(), rowIndex;
36289 if(this.isLocked() || (rowIndex = view.findRowIndex(t)) === false){
36292 if(e.shiftKey && this.last !== false){
36293 var last = this.last;
36294 this.selectRange(last, rowIndex, e.ctrlKey);
36295 this.last = last; // reset the last
36296 view.focusRow(rowIndex);
36298 var isSelected = this.isSelected(rowIndex);
36299 if(e.button !== 0 && isSelected){
36300 view.focusRow(rowIndex);
36301 }else if(e.ctrlKey && isSelected){
36302 this.deselectRow(rowIndex);
36303 }else if(!isSelected){
36304 this.selectRow(rowIndex, e.button === 0 && (e.ctrlKey || e.shiftKey));
36305 view.focusRow(rowIndex);
36308 this.fireEvent("afterselectionchange", this);
36311 handleDragableRowClick : function(grid, rowIndex, e)
36313 if(e.button === 0 && !e.shiftKey && !e.ctrlKey) {
36314 this.selectRow(rowIndex, false);
36315 grid.view.focusRow(rowIndex);
36316 this.fireEvent("afterselectionchange", this);
36321 * Selects multiple rows.
36322 * @param {Array} rows Array of the indexes of the row to select
36323 * @param {Boolean} keepExisting (optional) True to keep existing selections
36325 selectRows : function(rows, keepExisting){
36327 this.clearSelections();
36329 for(var i = 0, len = rows.length; i < len; i++){
36330 this.selectRow(rows[i], true);
36335 * Selects a range of rows. All rows in between startRow and endRow are also selected.
36336 * @param {Number} startRow The index of the first row in the range
36337 * @param {Number} endRow The index of the last row in the range
36338 * @param {Boolean} keepExisting (optional) True to retain existing selections
36340 selectRange : function(startRow, endRow, keepExisting){
36345 this.clearSelections();
36347 if(startRow <= endRow){
36348 for(var i = startRow; i <= endRow; i++){
36349 this.selectRow(i, true);
36352 for(var i = startRow; i >= endRow; i--){
36353 this.selectRow(i, true);
36359 * Deselects a range of rows. All rows in between startRow and endRow are also deselected.
36360 * @param {Number} startRow The index of the first row in the range
36361 * @param {Number} endRow The index of the last row in the range
36363 deselectRange : function(startRow, endRow, preventViewNotify){
36367 for(var i = startRow; i <= endRow; i++){
36368 this.deselectRow(i, preventViewNotify);
36374 * @param {Number} row The index of the row to select
36375 * @param {Boolean} keepExisting (optional) True to keep existing selections
36377 selectRow : function(index, keepExisting, preventViewNotify){
36378 if(this.locked || (index < 0 || index >= this.grid.dataSource.getCount())) {
36381 if(this.fireEvent("beforerowselect", this, index, keepExisting) !== false){
36382 if(!keepExisting || this.singleSelect){
36383 this.clearSelections();
36385 var r = this.grid.dataSource.getAt(index);
36386 this.selections.add(r);
36387 this.last = this.lastActive = index;
36388 if(!preventViewNotify){
36389 this.grid.getView().onRowSelect(index);
36391 this.fireEvent("rowselect", this, index, r);
36392 this.fireEvent("selectionchange", this);
36398 * @param {Number} row The index of the row to deselect
36400 deselectRow : function(index, preventViewNotify){
36404 if(this.last == index){
36407 if(this.lastActive == index){
36408 this.lastActive = false;
36410 var r = this.grid.dataSource.getAt(index);
36411 this.selections.remove(r);
36412 if(!preventViewNotify){
36413 this.grid.getView().onRowDeselect(index);
36415 this.fireEvent("rowdeselect", this, index);
36416 this.fireEvent("selectionchange", this);
36420 restoreLast : function(){
36422 this.last = this._last;
36427 acceptsNav : function(row, col, cm){
36428 return !cm.isHidden(col) && cm.isCellEditable(col, row);
36432 onEditorKey : function(field, e){
36433 var k = e.getKey(), newCell, g = this.grid, ed = g.activeEditor;
36438 newCell = g.walkCells(ed.row, ed.col-1, -1, this.acceptsNav, this);
36440 newCell = g.walkCells(ed.row, ed.col+1, 1, this.acceptsNav, this);
36442 }else if(k == e.ENTER && !e.ctrlKey){
36446 newCell = g.walkCells(ed.row-1, ed.col, -1, this.acceptsNav, this);
36448 newCell = g.walkCells(ed.row+1, ed.col, 1, this.acceptsNav, this);
36450 }else if(k == e.ESC){
36454 g.startEditing(newCell[0], newCell[1]);
36459 * Ext JS Library 1.1.1
36460 * Copyright(c) 2006-2007, Ext JS, LLC.
36462 * Originally Released Under LGPL - original licence link has changed is not relivant.
36465 * <script type="text/javascript">
36468 * @class Roo.grid.CellSelectionModel
36469 * @extends Roo.grid.AbstractSelectionModel
36470 * This class provides the basic implementation for cell selection in a grid.
36472 * @param {Object} config The object containing the configuration of this model.
36473 * @cfg {Boolean} enter_is_tab Enter behaves the same as tab. (eg. goes to next cell) default: false
36475 Roo.grid.CellSelectionModel = function(config){
36476 Roo.apply(this, config);
36478 this.selection = null;
36482 * @event beforerowselect
36483 * Fires before a cell is selected.
36484 * @param {SelectionModel} this
36485 * @param {Number} rowIndex The selected row index
36486 * @param {Number} colIndex The selected cell index
36488 "beforecellselect" : true,
36490 * @event cellselect
36491 * Fires when a cell is selected.
36492 * @param {SelectionModel} this
36493 * @param {Number} rowIndex The selected row index
36494 * @param {Number} colIndex The selected cell index
36496 "cellselect" : true,
36498 * @event selectionchange
36499 * Fires when the active selection changes.
36500 * @param {SelectionModel} this
36501 * @param {Object} selection null for no selection or an object (o) with two properties
36503 <li>o.record: the record object for the row the selection is in</li>
36504 <li>o.cell: An array of [rowIndex, columnIndex]</li>
36507 "selectionchange" : true,
36510 * Fires when the tab (or enter) was pressed on the last editable cell
36511 * You can use this to trigger add new row.
36512 * @param {SelectionModel} this
36516 * @event beforeeditnext
36517 * Fires before the next editable sell is made active
36518 * You can use this to skip to another cell or fire the tabend
36519 * if you set cell to false
36520 * @param {Object} eventdata object : { cell : [ row, col ] }
36522 "beforeeditnext" : true
36524 Roo.grid.CellSelectionModel.superclass.constructor.call(this);
36527 Roo.extend(Roo.grid.CellSelectionModel, Roo.grid.AbstractSelectionModel, {
36529 enter_is_tab: false,
36532 initEvents : function(){
36533 this.grid.on("mousedown", this.handleMouseDown, this);
36534 this.grid.getGridEl().on(Roo.isIE ? "keydown" : "keypress", this.handleKeyDown, this);
36535 var view = this.grid.view;
36536 view.on("refresh", this.onViewChange, this);
36537 view.on("rowupdated", this.onRowUpdated, this);
36538 view.on("beforerowremoved", this.clearSelections, this);
36539 view.on("beforerowsinserted", this.clearSelections, this);
36540 if(this.grid.isEditor){
36541 this.grid.on("beforeedit", this.beforeEdit, this);
36546 beforeEdit : function(e){
36547 this.select(e.row, e.column, false, true, e.record);
36551 onRowUpdated : function(v, index, r){
36552 if(this.selection && this.selection.record == r){
36553 v.onCellSelect(index, this.selection.cell[1]);
36558 onViewChange : function(){
36559 this.clearSelections(true);
36563 * Returns the currently selected cell,.
36564 * @return {Array} The selected cell (row, column) or null if none selected.
36566 getSelectedCell : function(){
36567 return this.selection ? this.selection.cell : null;
36571 * Clears all selections.
36572 * @param {Boolean} true to prevent the gridview from being notified about the change.
36574 clearSelections : function(preventNotify){
36575 var s = this.selection;
36577 if(preventNotify !== true){
36578 this.grid.view.onCellDeselect(s.cell[0], s.cell[1]);
36580 this.selection = null;
36581 this.fireEvent("selectionchange", this, null);
36586 * Returns true if there is a selection.
36587 * @return {Boolean}
36589 hasSelection : function(){
36590 return this.selection ? true : false;
36594 handleMouseDown : function(e, t){
36595 var v = this.grid.getView();
36596 if(this.isLocked()){
36599 var row = v.findRowIndex(t);
36600 var cell = v.findCellIndex(t);
36601 if(row !== false && cell !== false){
36602 this.select(row, cell);
36608 * @param {Number} rowIndex
36609 * @param {Number} collIndex
36611 select : function(rowIndex, colIndex, preventViewNotify, preventFocus, /*internal*/ r){
36612 if(this.fireEvent("beforecellselect", this, rowIndex, colIndex) !== false){
36613 this.clearSelections();
36614 r = r || this.grid.dataSource.getAt(rowIndex);
36617 cell : [rowIndex, colIndex]
36619 if(!preventViewNotify){
36620 var v = this.grid.getView();
36621 v.onCellSelect(rowIndex, colIndex);
36622 if(preventFocus !== true){
36623 v.focusCell(rowIndex, colIndex);
36626 this.fireEvent("cellselect", this, rowIndex, colIndex);
36627 this.fireEvent("selectionchange", this, this.selection);
36632 isSelectable : function(rowIndex, colIndex, cm){
36633 return !cm.isHidden(colIndex);
36637 handleKeyDown : function(e){
36638 //Roo.log('Cell Sel Model handleKeyDown');
36639 if(!e.isNavKeyPress()){
36642 var g = this.grid, s = this.selection;
36645 var cell = g.walkCells(0, 0, 1, this.isSelectable, this);
36647 this.select(cell[0], cell[1]);
36652 var walk = function(row, col, step){
36653 return g.walkCells(row, col, step, sm.isSelectable, sm);
36655 var k = e.getKey(), r = s.cell[0], c = s.cell[1];
36662 // handled by onEditorKey
36663 if (g.isEditor && g.editing) {
36667 newCell = walk(r, c-1, -1);
36669 newCell = walk(r, c+1, 1);
36674 newCell = walk(r+1, c, 1);
36678 newCell = walk(r-1, c, -1);
36682 newCell = walk(r, c+1, 1);
36686 newCell = walk(r, c-1, -1);
36691 if(g.isEditor && !g.editing){
36692 g.startEditing(r, c);
36701 this.select(newCell[0], newCell[1]);
36707 acceptsNav : function(row, col, cm){
36708 return !cm.isHidden(col) && cm.isCellEditable(col, row);
36712 * @param {Number} field (not used) - as it's normally used as a listener
36713 * @param {Number} e - event - fake it by using
36715 * var e = Roo.EventObjectImpl.prototype;
36716 * e.keyCode = e.TAB
36720 onEditorKey : function(field, e){
36722 var k = e.getKey(),
36725 ed = g.activeEditor,
36727 ///Roo.log('onEditorKey' + k);
36730 if (this.enter_is_tab && k == e.ENTER) {
36736 newCell = g.walkCells(ed.row, ed.col-1, -1, this.acceptsNav, this);
36738 newCell = g.walkCells(ed.row, ed.col+1, 1, this.acceptsNav, this);
36744 } else if(k == e.ENTER && !e.ctrlKey){
36747 newCell = g.walkCells(ed.row, ed.col+1, 1, this.acceptsNav, this);
36749 } else if(k == e.ESC){
36754 var ecall = { cell : newCell, forward : forward };
36755 this.fireEvent('beforeeditnext', ecall );
36756 newCell = ecall.cell;
36757 forward = ecall.forward;
36761 //Roo.log('next cell after edit');
36762 g.startEditing.defer(100, g, [newCell[0], newCell[1]]);
36763 } else if (forward) {
36764 // tabbed past last
36765 this.fireEvent.defer(100, this, ['tabend',this]);
36770 * Ext JS Library 1.1.1
36771 * Copyright(c) 2006-2007, Ext JS, LLC.
36773 * Originally Released Under LGPL - original licence link has changed is not relivant.
36776 * <script type="text/javascript">
36780 * @class Roo.grid.EditorGrid
36781 * @extends Roo.grid.Grid
36782 * Class for creating and editable grid.
36783 * @param {String/HTMLElement/Roo.Element} container The element into which this grid will be rendered -
36784 * The container MUST have some type of size defined for the grid to fill. The container will be
36785 * automatically set to position relative if it isn't already.
36786 * @param {Object} dataSource The data model to bind to
36787 * @param {Object} colModel The column model with info about this grid's columns
36789 Roo.grid.EditorGrid = function(container, config){
36790 Roo.grid.EditorGrid.superclass.constructor.call(this, container, config);
36791 this.getGridEl().addClass("xedit-grid");
36793 if(!this.selModel){
36794 this.selModel = new Roo.grid.CellSelectionModel();
36797 this.activeEditor = null;
36801 * @event beforeedit
36802 * Fires before cell editing is triggered. The edit event object has the following properties <br />
36803 * <ul style="padding:5px;padding-left:16px;">
36804 * <li>grid - This grid</li>
36805 * <li>record - The record being edited</li>
36806 * <li>field - The field name being edited</li>
36807 * <li>value - The value for the field being edited.</li>
36808 * <li>row - The grid row index</li>
36809 * <li>column - The grid column index</li>
36810 * <li>cancel - Set this to true to cancel the edit or return false from your handler.</li>
36812 * @param {Object} e An edit event (see above for description)
36814 "beforeedit" : true,
36817 * Fires after a cell is edited. <br />
36818 * <ul style="padding:5px;padding-left:16px;">
36819 * <li>grid - This grid</li>
36820 * <li>record - The record being edited</li>
36821 * <li>field - The field name being edited</li>
36822 * <li>value - The value being set</li>
36823 * <li>originalValue - The original value for the field, before the edit.</li>
36824 * <li>row - The grid row index</li>
36825 * <li>column - The grid column index</li>
36827 * @param {Object} e An edit event (see above for description)
36829 "afteredit" : true,
36831 * @event validateedit
36832 * Fires after a cell is edited, but before the value is set in the record.
36833 * You can use this to modify the value being set in the field, Return false
36834 * to cancel the change. The edit event object has the following properties <br />
36835 * <ul style="padding:5px;padding-left:16px;">
36836 * <li>editor - This editor</li>
36837 * <li>grid - This grid</li>
36838 * <li>record - The record being edited</li>
36839 * <li>field - The field name being edited</li>
36840 * <li>value - The value being set</li>
36841 * <li>originalValue - The original value for the field, before the edit.</li>
36842 * <li>row - The grid row index</li>
36843 * <li>column - The grid column index</li>
36844 * <li>cancel - Set this to true to cancel the edit or return false from your handler.</li>
36846 * @param {Object} e An edit event (see above for description)
36848 "validateedit" : true
36850 this.on("bodyscroll", this.stopEditing, this);
36851 this.on(this.clicksToEdit == 1 ? "cellclick" : "celldblclick", this.onCellDblClick, this);
36854 Roo.extend(Roo.grid.EditorGrid, Roo.grid.Grid, {
36856 * @cfg {Number} clicksToEdit
36857 * The number of clicks on a cell required to display the cell's editor (defaults to 2)
36864 trackMouseOver: false, // causes very odd FF errors
36866 onCellDblClick : function(g, row, col){
36867 this.startEditing(row, col);
36870 onEditComplete : function(ed, value, startValue){
36871 this.editing = false;
36872 this.activeEditor = null;
36873 ed.un("specialkey", this.selModel.onEditorKey, this.selModel);
36875 var field = this.colModel.getDataIndex(ed.col);
36880 originalValue: startValue,
36887 var cell = Roo.get(this.view.getCell(ed.row,ed.col));
36890 if(String(value) !== String(startValue)){
36892 if(this.fireEvent("validateedit", e) !== false && !e.cancel){
36893 r.set(field, e.value);
36894 // if we are dealing with a combo box..
36895 // then we also set the 'name' colum to be the displayField
36896 if (ed.field.displayField && ed.field.name) {
36897 r.set(ed.field.name, ed.field.el.dom.value);
36900 delete e.cancel; //?? why!!!
36901 this.fireEvent("afteredit", e);
36904 this.fireEvent("afteredit", e); // always fire it!
36906 this.view.focusCell(ed.row, ed.col);
36910 * Starts editing the specified for the specified row/column
36911 * @param {Number} rowIndex
36912 * @param {Number} colIndex
36914 startEditing : function(row, col){
36915 this.stopEditing();
36916 if(this.colModel.isCellEditable(col, row)){
36917 this.view.ensureVisible(row, col, true);
36919 var r = this.dataSource.getAt(row);
36920 var field = this.colModel.getDataIndex(col);
36921 var cell = Roo.get(this.view.getCell(row,col));
36926 value: r.data[field],
36931 if(this.fireEvent("beforeedit", e) !== false && !e.cancel){
36932 this.editing = true;
36933 var ed = this.colModel.getCellEditor(col, row);
36939 ed.render(ed.parentEl || document.body);
36945 (function(){ // complex but required for focus issues in safari, ie and opera
36949 ed.on("complete", this.onEditComplete, this, {single: true});
36950 ed.on("specialkey", this.selModel.onEditorKey, this.selModel);
36951 this.activeEditor = ed;
36952 var v = r.data[field];
36953 ed.startEdit(this.view.getCell(row, col), v);
36954 // combo's with 'displayField and name set
36955 if (ed.field.displayField && ed.field.name) {
36956 ed.field.el.dom.value = r.data[ed.field.name];
36960 }).defer(50, this);
36966 * Stops any active editing
36968 stopEditing : function(){
36969 if(this.activeEditor){
36970 this.activeEditor.completeEdit();
36972 this.activeEditor = null;
36976 * Called to get grid's drag proxy text, by default returns this.ddText.
36979 getDragDropText : function(){
36980 var count = this.selModel.getSelectedCell() ? 1 : 0;
36981 return String.format(this.ddText, count, count == 1 ? '' : 's');
36986 * Ext JS Library 1.1.1
36987 * Copyright(c) 2006-2007, Ext JS, LLC.
36989 * Originally Released Under LGPL - original licence link has changed is not relivant.
36992 * <script type="text/javascript">
36995 // private - not really -- you end up using it !
36996 // This is a support class used internally by the Grid components
36999 * @class Roo.grid.GridEditor
37000 * @extends Roo.Editor
37001 * Class for creating and editable grid elements.
37002 * @param {Object} config any settings (must include field)
37004 Roo.grid.GridEditor = function(field, config){
37005 if (!config && field.field) {
37007 field = Roo.factory(config.field, Roo.form);
37009 Roo.grid.GridEditor.superclass.constructor.call(this, field, config);
37010 field.monitorTab = false;
37013 Roo.extend(Roo.grid.GridEditor, Roo.Editor, {
37016 * @cfg {Roo.form.Field} field Field to wrap (or xtyped)
37019 alignment: "tl-tl",
37022 cls: "x-small-editor x-grid-editor",
37027 * Ext JS Library 1.1.1
37028 * Copyright(c) 2006-2007, Ext JS, LLC.
37030 * Originally Released Under LGPL - original licence link has changed is not relivant.
37033 * <script type="text/javascript">
37038 Roo.grid.PropertyRecord = Roo.data.Record.create([
37039 {name:'name',type:'string'}, 'value'
37043 Roo.grid.PropertyStore = function(grid, source){
37045 this.store = new Roo.data.Store({
37046 recordType : Roo.grid.PropertyRecord
37048 this.store.on('update', this.onUpdate, this);
37050 this.setSource(source);
37052 Roo.grid.PropertyStore.superclass.constructor.call(this);
37057 Roo.extend(Roo.grid.PropertyStore, Roo.util.Observable, {
37058 setSource : function(o){
37060 this.store.removeAll();
37063 if(this.isEditableValue(o[k])){
37064 data.push(new Roo.grid.PropertyRecord({name: k, value: o[k]}, k));
37067 this.store.loadRecords({records: data}, {}, true);
37070 onUpdate : function(ds, record, type){
37071 if(type == Roo.data.Record.EDIT){
37072 var v = record.data['value'];
37073 var oldValue = record.modified['value'];
37074 if(this.grid.fireEvent('beforepropertychange', this.source, record.id, v, oldValue) !== false){
37075 this.source[record.id] = v;
37077 this.grid.fireEvent('propertychange', this.source, record.id, v, oldValue);
37084 getProperty : function(row){
37085 return this.store.getAt(row);
37088 isEditableValue: function(val){
37089 if(val && val instanceof Date){
37091 }else if(typeof val == 'object' || typeof val == 'function'){
37097 setValue : function(prop, value){
37098 this.source[prop] = value;
37099 this.store.getById(prop).set('value', value);
37102 getSource : function(){
37103 return this.source;
37107 Roo.grid.PropertyColumnModel = function(grid, store){
37110 g.PropertyColumnModel.superclass.constructor.call(this, [
37111 {header: this.nameText, sortable: true, dataIndex:'name', id: 'name'},
37112 {header: this.valueText, resizable:false, dataIndex: 'value', id: 'value'}
37114 this.store = store;
37115 this.bselect = Roo.DomHelper.append(document.body, {
37116 tag: 'select', style:'display:none', cls: 'x-grid-editor', children: [
37117 {tag: 'option', value: 'true', html: 'true'},
37118 {tag: 'option', value: 'false', html: 'false'}
37121 Roo.id(this.bselect);
37124 'date' : new g.GridEditor(new f.DateField({selectOnFocus:true})),
37125 'string' : new g.GridEditor(new f.TextField({selectOnFocus:true})),
37126 'number' : new g.GridEditor(new f.NumberField({selectOnFocus:true, style:'text-align:left;'})),
37127 'int' : new g.GridEditor(new f.NumberField({selectOnFocus:true, allowDecimals:false, style:'text-align:left;'})),
37128 'boolean' : new g.GridEditor(new f.Field({el:this.bselect,selectOnFocus:true}))
37130 this.renderCellDelegate = this.renderCell.createDelegate(this);
37131 this.renderPropDelegate = this.renderProp.createDelegate(this);
37134 Roo.extend(Roo.grid.PropertyColumnModel, Roo.grid.ColumnModel, {
37138 valueText : 'Value',
37140 dateFormat : 'm/j/Y',
37143 renderDate : function(dateVal){
37144 return dateVal.dateFormat(this.dateFormat);
37147 renderBool : function(bVal){
37148 return bVal ? 'true' : 'false';
37151 isCellEditable : function(colIndex, rowIndex){
37152 return colIndex == 1;
37155 getRenderer : function(col){
37157 this.renderCellDelegate : this.renderPropDelegate;
37160 renderProp : function(v){
37161 return this.getPropertyName(v);
37164 renderCell : function(val){
37166 if(val instanceof Date){
37167 rv = this.renderDate(val);
37168 }else if(typeof val == 'boolean'){
37169 rv = this.renderBool(val);
37171 return Roo.util.Format.htmlEncode(rv);
37174 getPropertyName : function(name){
37175 var pn = this.grid.propertyNames;
37176 return pn && pn[name] ? pn[name] : name;
37179 getCellEditor : function(colIndex, rowIndex){
37180 var p = this.store.getProperty(rowIndex);
37181 var n = p.data['name'], val = p.data['value'];
37183 if(typeof(this.grid.customEditors[n]) == 'string'){
37184 return this.editors[this.grid.customEditors[n]];
37186 if(typeof(this.grid.customEditors[n]) != 'undefined'){
37187 return this.grid.customEditors[n];
37189 if(val instanceof Date){
37190 return this.editors['date'];
37191 }else if(typeof val == 'number'){
37192 return this.editors['number'];
37193 }else if(typeof val == 'boolean'){
37194 return this.editors['boolean'];
37196 return this.editors['string'];
37202 * @class Roo.grid.PropertyGrid
37203 * @extends Roo.grid.EditorGrid
37204 * This class represents the interface of a component based property grid control.
37205 * <br><br>Usage:<pre><code>
37206 var grid = new Roo.grid.PropertyGrid("my-container-id", {
37214 * @param {String/HTMLElement/Roo.Element} container The element into which this grid will be rendered -
37215 * The container MUST have some type of size defined for the grid to fill. The container will be
37216 * automatically set to position relative if it isn't already.
37217 * @param {Object} config A config object that sets properties on this grid.
37219 Roo.grid.PropertyGrid = function(container, config){
37220 config = config || {};
37221 var store = new Roo.grid.PropertyStore(this);
37222 this.store = store;
37223 var cm = new Roo.grid.PropertyColumnModel(this, store);
37224 store.store.sort('name', 'ASC');
37225 Roo.grid.PropertyGrid.superclass.constructor.call(this, container, Roo.apply({
37228 enableColLock:false,
37229 enableColumnMove:false,
37231 trackMouseOver: false,
37234 this.getGridEl().addClass('x-props-grid');
37235 this.lastEditRow = null;
37236 this.on('columnresize', this.onColumnResize, this);
37239 * @event beforepropertychange
37240 * Fires before a property changes (return false to stop?)
37241 * @param {Roo.grid.PropertyGrid} grid property grid? (check could be store)
37242 * @param {String} id Record Id
37243 * @param {String} newval New Value
37244 * @param {String} oldval Old Value
37246 "beforepropertychange": true,
37248 * @event propertychange
37249 * Fires after a property changes
37250 * @param {Roo.grid.PropertyGrid} grid property grid? (check could be store)
37251 * @param {String} id Record Id
37252 * @param {String} newval New Value
37253 * @param {String} oldval Old Value
37255 "propertychange": true
37257 this.customEditors = this.customEditors || {};
37259 Roo.extend(Roo.grid.PropertyGrid, Roo.grid.EditorGrid, {
37262 * @cfg {Object} customEditors map of colnames=> custom editors.
37263 * the custom editor can be one of the standard ones (date|string|number|int|boolean), or a
37264 * grid editor eg. Roo.grid.GridEditor(new Roo.form.TextArea({selectOnFocus:true})),
37265 * false disables editing of the field.
37269 * @cfg {Object} propertyNames map of property Names to their displayed value
37272 render : function(){
37273 Roo.grid.PropertyGrid.superclass.render.call(this);
37274 this.autoSize.defer(100, this);
37277 autoSize : function(){
37278 Roo.grid.PropertyGrid.superclass.autoSize.call(this);
37280 this.view.fitColumns();
37284 onColumnResize : function(){
37285 this.colModel.setColumnWidth(1, this.container.getWidth(true)-this.colModel.getColumnWidth(0));
37289 * Sets the data for the Grid
37290 * accepts a Key => Value object of all the elements avaiable.
37291 * @param {Object} data to appear in grid.
37293 setSource : function(source){
37294 this.store.setSource(source);
37298 * Gets all the data from the grid.
37299 * @return {Object} data data stored in grid
37301 getSource : function(){
37302 return this.store.getSource();
37311 * @class Roo.grid.Calendar
37312 * @extends Roo.util.Grid
37313 * This class extends the Grid to provide a calendar widget
37314 * <br><br>Usage:<pre><code>
37315 var grid = new Roo.grid.Calendar("my-container-id", {
37318 selModel: mySelectionModel,
37319 autoSizeColumns: true,
37320 monitorWindowResize: false,
37321 trackMouseOver: true
37322 eventstore : real data store..
37328 * @param {String/HTMLElement/Roo.Element} container The element into which this grid will be rendered -
37329 * The container MUST have some type of size defined for the grid to fill. The container will be
37330 * automatically set to position relative if it isn't already.
37331 * @param {Object} config A config object that sets properties on this grid.
37333 Roo.grid.Calendar = function(container, config){
37334 // initialize the container
37335 this.container = Roo.get(container);
37336 this.container.update("");
37337 this.container.setStyle("overflow", "hidden");
37338 this.container.addClass('x-grid-container');
37340 this.id = this.container.id;
37342 Roo.apply(this, config);
37343 // check and correct shorthanded configs
37347 for (var r = 0;r < 6;r++) {
37350 for (var c =0;c < 7;c++) {
37354 if (this.eventStore) {
37355 this.eventStore= Roo.factory(this.eventStore, Roo.data);
37356 this.eventStore.on('load',this.onLoad, this);
37357 this.eventStore.on('beforeload',this.clearEvents, this);
37361 this.dataSource = new Roo.data.Store({
37362 proxy: new Roo.data.MemoryProxy(rows),
37363 reader: new Roo.data.ArrayReader({}, [
37364 'weekday0', 'weekday1', 'weekday2', 'weekday3', 'weekday4', 'weekday5', 'weekday6' ])
37367 this.dataSource.load();
37368 this.ds = this.dataSource;
37369 this.ds.xmodule = this.xmodule || false;
37372 var cellRender = function(v,x,r)
37374 return String.format(
37375 '<div class="fc-day fc-widget-content"><div>' +
37376 '<div class="fc-event-container"></div>' +
37377 '<div class="fc-day-number">{0}</div>'+
37379 '<div class="fc-day-content"><div style="position:relative"></div></div>' +
37380 '</div></div>', v);
37385 this.colModel = new Roo.grid.ColumnModel( [
37387 xtype: 'ColumnModel',
37389 dataIndex : 'weekday0',
37391 renderer : cellRender
37394 xtype: 'ColumnModel',
37396 dataIndex : 'weekday1',
37398 renderer : cellRender
37401 xtype: 'ColumnModel',
37403 dataIndex : 'weekday2',
37404 header : 'Tuesday',
37405 renderer : cellRender
37408 xtype: 'ColumnModel',
37410 dataIndex : 'weekday3',
37411 header : 'Wednesday',
37412 renderer : cellRender
37415 xtype: 'ColumnModel',
37417 dataIndex : 'weekday4',
37418 header : 'Thursday',
37419 renderer : cellRender
37422 xtype: 'ColumnModel',
37424 dataIndex : 'weekday5',
37426 renderer : cellRender
37429 xtype: 'ColumnModel',
37431 dataIndex : 'weekday6',
37432 header : 'Saturday',
37433 renderer : cellRender
37436 this.cm = this.colModel;
37437 this.cm.xmodule = this.xmodule || false;
37441 //this.selModel = new Roo.grid.CellSelectionModel();
37442 //this.sm = this.selModel;
37443 //this.selModel.init(this);
37447 this.container.setWidth(this.width);
37451 this.container.setHeight(this.height);
37458 * The raw click event for the entire grid.
37459 * @param {Roo.EventObject} e
37464 * The raw dblclick event for the entire grid.
37465 * @param {Roo.EventObject} e
37469 * @event contextmenu
37470 * The raw contextmenu event for the entire grid.
37471 * @param {Roo.EventObject} e
37473 "contextmenu" : true,
37476 * The raw mousedown event for the entire grid.
37477 * @param {Roo.EventObject} e
37479 "mousedown" : true,
37482 * The raw mouseup event for the entire grid.
37483 * @param {Roo.EventObject} e
37488 * The raw mouseover event for the entire grid.
37489 * @param {Roo.EventObject} e
37491 "mouseover" : true,
37494 * The raw mouseout event for the entire grid.
37495 * @param {Roo.EventObject} e
37500 * The raw keypress event for the entire grid.
37501 * @param {Roo.EventObject} e
37506 * The raw keydown event for the entire grid.
37507 * @param {Roo.EventObject} e
37515 * Fires when a cell is clicked
37516 * @param {Grid} this
37517 * @param {Number} rowIndex
37518 * @param {Number} columnIndex
37519 * @param {Roo.EventObject} e
37521 "cellclick" : true,
37523 * @event celldblclick
37524 * Fires when a cell is double clicked
37525 * @param {Grid} this
37526 * @param {Number} rowIndex
37527 * @param {Number} columnIndex
37528 * @param {Roo.EventObject} e
37530 "celldblclick" : true,
37533 * Fires when a row is clicked
37534 * @param {Grid} this
37535 * @param {Number} rowIndex
37536 * @param {Roo.EventObject} e
37540 * @event rowdblclick
37541 * Fires when a row is double clicked
37542 * @param {Grid} this
37543 * @param {Number} rowIndex
37544 * @param {Roo.EventObject} e
37546 "rowdblclick" : true,
37548 * @event headerclick
37549 * Fires when a header is clicked
37550 * @param {Grid} this
37551 * @param {Number} columnIndex
37552 * @param {Roo.EventObject} e
37554 "headerclick" : true,
37556 * @event headerdblclick
37557 * Fires when a header cell is double clicked
37558 * @param {Grid} this
37559 * @param {Number} columnIndex
37560 * @param {Roo.EventObject} e
37562 "headerdblclick" : true,
37564 * @event rowcontextmenu
37565 * Fires when a row is right clicked
37566 * @param {Grid} this
37567 * @param {Number} rowIndex
37568 * @param {Roo.EventObject} e
37570 "rowcontextmenu" : true,
37572 * @event cellcontextmenu
37573 * Fires when a cell is right clicked
37574 * @param {Grid} this
37575 * @param {Number} rowIndex
37576 * @param {Number} cellIndex
37577 * @param {Roo.EventObject} e
37579 "cellcontextmenu" : true,
37581 * @event headercontextmenu
37582 * Fires when a header is right clicked
37583 * @param {Grid} this
37584 * @param {Number} columnIndex
37585 * @param {Roo.EventObject} e
37587 "headercontextmenu" : true,
37589 * @event bodyscroll
37590 * Fires when the body element is scrolled
37591 * @param {Number} scrollLeft
37592 * @param {Number} scrollTop
37594 "bodyscroll" : true,
37596 * @event columnresize
37597 * Fires when the user resizes a column
37598 * @param {Number} columnIndex
37599 * @param {Number} newSize
37601 "columnresize" : true,
37603 * @event columnmove
37604 * Fires when the user moves a column
37605 * @param {Number} oldIndex
37606 * @param {Number} newIndex
37608 "columnmove" : true,
37611 * Fires when row(s) start being dragged
37612 * @param {Grid} this
37613 * @param {Roo.GridDD} dd The drag drop object
37614 * @param {event} e The raw browser event
37616 "startdrag" : true,
37619 * Fires when a drag operation is complete
37620 * @param {Grid} this
37621 * @param {Roo.GridDD} dd The drag drop object
37622 * @param {event} e The raw browser event
37627 * Fires when dragged row(s) are dropped on a valid DD target
37628 * @param {Grid} this
37629 * @param {Roo.GridDD} dd The drag drop object
37630 * @param {String} targetId The target drag drop object
37631 * @param {event} e The raw browser event
37636 * Fires while row(s) are being dragged. "targetId" is the id of the Yahoo.util.DD object the selected rows are being dragged over.
37637 * @param {Grid} this
37638 * @param {Roo.GridDD} dd The drag drop object
37639 * @param {String} targetId The target drag drop object
37640 * @param {event} e The raw browser event
37645 * Fires when the dragged row(s) first cross another DD target while being dragged
37646 * @param {Grid} this
37647 * @param {Roo.GridDD} dd The drag drop object
37648 * @param {String} targetId The target drag drop object
37649 * @param {event} e The raw browser event
37651 "dragenter" : true,
37654 * Fires when the dragged row(s) leave another DD target while being dragged
37655 * @param {Grid} this
37656 * @param {Roo.GridDD} dd The drag drop object
37657 * @param {String} targetId The target drag drop object
37658 * @param {event} e The raw browser event
37663 * Fires when a row is rendered, so you can change add a style to it.
37664 * @param {GridView} gridview The grid view
37665 * @param {Object} rowcfg contains record rowIndex and rowClass - set rowClass to add a style.
37671 * Fires when the grid is rendered
37672 * @param {Grid} grid
37677 * Fires when a date is selected
37678 * @param {DatePicker} this
37679 * @param {Date} date The selected date
37683 * @event monthchange
37684 * Fires when the displayed month changes
37685 * @param {DatePicker} this
37686 * @param {Date} date The selected month
37688 'monthchange': true,
37690 * @event evententer
37691 * Fires when mouse over an event
37692 * @param {Calendar} this
37693 * @param {event} Event
37695 'evententer': true,
37697 * @event eventleave
37698 * Fires when the mouse leaves an
37699 * @param {Calendar} this
37702 'eventleave': true,
37704 * @event eventclick
37705 * Fires when the mouse click an
37706 * @param {Calendar} this
37709 'eventclick': true,
37711 * @event eventrender
37712 * Fires before each cell is rendered, so you can modify the contents, like cls / title / qtip
37713 * @param {Calendar} this
37714 * @param {data} data to be modified
37716 'eventrender': true
37720 Roo.grid.Grid.superclass.constructor.call(this);
37721 this.on('render', function() {
37722 this.view.el.addClass('x-grid-cal');
37724 (function() { this.setDate(new Date()); }).defer(100,this); //default today..
37728 if (!Roo.grid.Calendar.style) {
37729 Roo.grid.Calendar.style = Roo.util.CSS.createStyleSheet({
37732 '.x-grid-cal .x-grid-col' : {
37733 height: 'auto !important',
37734 'vertical-align': 'top'
37736 '.x-grid-cal .fc-event-hori' : {
37747 Roo.extend(Roo.grid.Calendar, Roo.grid.Grid, {
37749 * @cfg {Store} eventStore The store that loads events.
37754 activeDate : false,
37757 monitorWindowResize : false,
37760 resizeColumns : function() {
37761 var col = (this.view.el.getWidth() / 7) - 3;
37762 // loop through cols, and setWidth
37763 for(var i =0 ; i < 7 ; i++){
37764 this.cm.setColumnWidth(i, col);
37767 setDate :function(date) {
37769 Roo.log('setDate?');
37771 this.resizeColumns();
37772 var vd = this.activeDate;
37773 this.activeDate = date;
37774 // if(vd && this.el){
37775 // var t = date.getTime();
37776 // if(vd.getMonth() == date.getMonth() && vd.getFullYear() == date.getFullYear()){
37777 // Roo.log('using add remove');
37779 // this.fireEvent('monthchange', this, date);
37781 // this.cells.removeClass("fc-state-highlight");
37782 // this.cells.each(function(c){
37783 // if(c.dateValue == t){
37784 // c.addClass("fc-state-highlight");
37785 // setTimeout(function(){
37786 // try{c.dom.firstChild.focus();}catch(e){}
37796 var days = date.getDaysInMonth();
37798 var firstOfMonth = date.getFirstDateOfMonth();
37799 var startingPos = firstOfMonth.getDay()-this.startDay;
37801 if(startingPos < this.startDay){
37805 var pm = date.add(Date.MONTH, -1);
37806 var prevStart = pm.getDaysInMonth()-startingPos;
37810 this.cells = this.view.el.select('.x-grid-row .x-grid-col',true);
37812 this.textNodes = this.view.el.query('.x-grid-row .x-grid-col .x-grid-cell-text');
37813 //this.cells.addClassOnOver('fc-state-hover');
37815 var cells = this.cells.elements;
37816 var textEls = this.textNodes;
37818 //Roo.each(cells, function(cell){
37819 // cell.removeClass([ 'fc-past', 'fc-other-month', 'fc-future', 'fc-state-highlight', 'fc-state-disabled']);
37822 days += startingPos;
37824 // convert everything to numbers so it's fast
37825 var day = 86400000;
37826 var d = (new Date(pm.getFullYear(), pm.getMonth(), prevStart)).clearTime();
37829 //Roo.log(prevStart);
37831 var today = new Date().clearTime().getTime();
37832 var sel = date.clearTime().getTime();
37833 var min = this.minDate ? this.minDate.clearTime() : Number.NEGATIVE_INFINITY;
37834 var max = this.maxDate ? this.maxDate.clearTime() : Number.POSITIVE_INFINITY;
37835 var ddMatch = this.disabledDatesRE;
37836 var ddText = this.disabledDatesText;
37837 var ddays = this.disabledDays ? this.disabledDays.join("") : false;
37838 var ddaysText = this.disabledDaysText;
37839 var format = this.format;
37841 var setCellClass = function(cal, cell){
37843 //Roo.log('set Cell Class');
37845 var t = d.getTime();
37850 cell.dateValue = t;
37852 cell.className += " fc-today";
37853 cell.className += " fc-state-highlight";
37854 cell.title = cal.todayText;
37857 // disable highlight in other month..
37858 cell.className += " fc-state-highlight";
37863 //cell.className = " fc-state-disabled";
37864 cell.title = cal.minText;
37868 //cell.className = " fc-state-disabled";
37869 cell.title = cal.maxText;
37873 if(ddays.indexOf(d.getDay()) != -1){
37874 // cell.title = ddaysText;
37875 // cell.className = " fc-state-disabled";
37878 if(ddMatch && format){
37879 var fvalue = d.dateFormat(format);
37880 if(ddMatch.test(fvalue)){
37881 cell.title = ddText.replace("%0", fvalue);
37882 cell.className = " fc-state-disabled";
37886 if (!cell.initialClassName) {
37887 cell.initialClassName = cell.dom.className;
37890 cell.dom.className = cell.initialClassName + ' ' + cell.className;
37895 for(; i < startingPos; i++) {
37896 cells[i].dayName = (++prevStart);
37897 Roo.log(textEls[i]);
37898 d.setDate(d.getDate()+1);
37900 //cells[i].className = "fc-past fc-other-month";
37901 setCellClass(this, cells[i]);
37906 for(; i < days; i++){
37907 intDay = i - startingPos + 1;
37908 cells[i].dayName = (intDay);
37909 d.setDate(d.getDate()+1);
37911 cells[i].className = ''; // "x-date-active";
37912 setCellClass(this, cells[i]);
37916 for(; i < 42; i++) {
37917 //textEls[i].innerHTML = (++extraDays);
37919 d.setDate(d.getDate()+1);
37920 cells[i].dayName = (++extraDays);
37921 cells[i].className = "fc-future fc-other-month";
37922 setCellClass(this, cells[i]);
37925 //this.el.select('.fc-header-title h2',true).update(Date.monthNames[date.getMonth()] + " " + date.getFullYear());
37927 var totalRows = Math.ceil((date.getDaysInMonth() + date.getFirstDateOfMonth().getDay()) / 7);
37929 // this will cause all the cells to mis
37932 for (var r = 0;r < 6;r++) {
37933 for (var c =0;c < 7;c++) {
37934 this.ds.getAt(r).set('weekday' + c ,cells[i++].dayName );
37938 this.cells = this.view.el.select('.x-grid-row .x-grid-col',true);
37939 for(i=0;i<cells.length;i++) {
37941 this.cells.elements[i].dayName = cells[i].dayName ;
37942 this.cells.elements[i].className = cells[i].className;
37943 this.cells.elements[i].initialClassName = cells[i].initialClassName ;
37944 this.cells.elements[i].title = cells[i].title ;
37945 this.cells.elements[i].dateValue = cells[i].dateValue ;
37951 //this.el.select('tr.fc-week.fc-prev-last',true).removeClass('fc-last');
37952 //this.el.select('tr.fc-week.fc-next-last',true).addClass('fc-last').show();
37954 ////if(totalRows != 6){
37955 //this.el.select('tr.fc-week.fc-last',true).removeClass('fc-last').addClass('fc-next-last').hide();
37956 // this.el.select('tr.fc-week.fc-prev-last',true).addClass('fc-last');
37959 this.fireEvent('monthchange', this, date);
37964 * Returns the grid's SelectionModel.
37965 * @return {SelectionModel}
37967 getSelectionModel : function(){
37968 if(!this.selModel){
37969 this.selModel = new Roo.grid.CellSelectionModel();
37971 return this.selModel;
37975 this.eventStore.load()
37981 findCell : function(dt) {
37982 dt = dt.clearTime().getTime();
37984 this.cells.each(function(c){
37985 //Roo.log("check " +c.dateValue + '?=' + dt);
37986 if(c.dateValue == dt){
37996 findCells : function(rec) {
37997 var s = rec.data.start_dt.clone().clearTime().getTime();
37999 var e= rec.data.end_dt.clone().clearTime().getTime();
38002 this.cells.each(function(c){
38003 ////Roo.log("check " +c.dateValue + '<' + e + ' > ' + s);
38005 if(c.dateValue > e){
38008 if(c.dateValue < s){
38017 findBestRow: function(cells)
38021 for (var i =0 ; i < cells.length;i++) {
38022 ret = Math.max(cells[i].rows || 0,ret);
38029 addItem : function(rec)
38031 // look for vertical location slot in
38032 var cells = this.findCells(rec);
38034 rec.row = this.findBestRow(cells);
38036 // work out the location.
38040 for(var i =0; i < cells.length; i++) {
38048 if (crow.start.getY() == cells[i].getY()) {
38050 crow.end = cells[i];
38066 for (var i = 0; i < cells.length;i++) {
38067 cells[i].rows = Math.max(cells[i].rows || 0 , rec.row + 1 );
38074 clearEvents: function() {
38076 if (!this.eventStore.getCount()) {
38079 // reset number of rows in cells.
38080 Roo.each(this.cells.elements, function(c){
38084 this.eventStore.each(function(e) {
38085 this.clearEvent(e);
38090 clearEvent : function(ev)
38093 Roo.each(ev.els, function(el) {
38094 el.un('mouseenter' ,this.onEventEnter, this);
38095 el.un('mouseleave' ,this.onEventLeave, this);
38103 renderEvent : function(ev,ctr) {
38105 ctr = this.view.el.select('.fc-event-container',true).first();
38109 this.clearEvent(ev);
38115 var cells = ev.cells;
38116 var rows = ev.rows;
38117 this.fireEvent('eventrender', this, ev);
38119 for(var i =0; i < rows.length; i++) {
38123 cls += ' fc-event-start';
38125 if ((i+1) == rows.length) {
38126 cls += ' fc-event-end';
38129 //Roo.log(ev.data);
38130 // how many rows should it span..
38131 var cg = this.eventTmpl.append(ctr,Roo.apply({
38134 }, ev.data) , true);
38137 cg.on('mouseenter' ,this.onEventEnter, this, ev);
38138 cg.on('mouseleave' ,this.onEventLeave, this, ev);
38139 cg.on('click', this.onEventClick, this, ev);
38143 var sbox = rows[i].start.select('.fc-day-content',true).first().getBox();
38144 var ebox = rows[i].end.select('.fc-day-content',true).first().getBox();
38147 cg.setXY([sbox.x +2, sbox.y +(ev.row * 20)]);
38148 cg.setWidth(ebox.right - sbox.x -2);
38152 renderEvents: function()
38154 // first make sure there is enough space..
38156 if (!this.eventTmpl) {
38157 this.eventTmpl = new Roo.Template(
38158 '<div class="roo-dynamic fc-event fc-event-hori fc-event-draggable ui-draggable {fccls} {cls}" style="position: absolute" unselectable="on">' +
38159 '<div class="fc-event-inner">' +
38160 '<span class="fc-event-time">{time}</span>' +
38161 '<span class="fc-event-title" qtip="{qtip}">{title}</span>' +
38163 '<div class="ui-resizable-heandle ui-resizable-e"> </div>' +
38171 this.cells.each(function(c) {
38172 //Roo.log(c.select('.fc-day-content div',true).first());
38173 c.select('.fc-day-content div',true).first().setHeight(Math.max(34, (c.rows || 1) * 20));
38176 var ctr = this.view.el.select('.fc-event-container',true).first();
38179 this.eventStore.each(function(ev){
38181 this.renderEvent(ev);
38185 this.view.layout();
38189 onEventEnter: function (e, el,event,d) {
38190 this.fireEvent('evententer', this, el, event);
38193 onEventLeave: function (e, el,event,d) {
38194 this.fireEvent('eventleave', this, el, event);
38197 onEventClick: function (e, el,event,d) {
38198 this.fireEvent('eventclick', this, el, event);
38201 onMonthChange: function () {
38205 onLoad: function () {
38207 //Roo.log('calendar onload');
38209 if(this.eventStore.getCount() > 0){
38213 this.eventStore.each(function(d){
38218 if (typeof(add.end_dt) == 'undefined') {
38219 Roo.log("Missing End time in calendar data: ");
38223 if (typeof(add.start_dt) == 'undefined') {
38224 Roo.log("Missing Start time in calendar data: ");
38228 add.start_dt = typeof(add.start_dt) == 'string' ? Date.parseDate(add.start_dt,'Y-m-d H:i:s') : add.start_dt,
38229 add.end_dt = typeof(add.end_dt) == 'string' ? Date.parseDate(add.end_dt,'Y-m-d H:i:s') : add.end_dt,
38230 add.id = add.id || d.id;
38231 add.title = add.title || '??';
38239 this.renderEvents();
38249 render : function ()
38253 if (!this.view.el.hasClass('course-timesheet')) {
38254 this.view.el.addClass('course-timesheet');
38256 if (this.tsStyle) {
38261 Roo.log(_this.grid.view.el.getWidth());
38264 this.tsStyle = Roo.util.CSS.createStyleSheet({
38265 '.course-timesheet .x-grid-row' : {
38268 '.x-grid-row td' : {
38269 'vertical-align' : 0
38271 '.course-edit-link' : {
38273 'text-overflow' : 'ellipsis',
38274 'overflow' : 'hidden',
38275 'white-space' : 'nowrap',
38276 'cursor' : 'pointer'
38281 '.de-act-sup-link' : {
38282 'color' : 'purple',
38283 'text-decoration' : 'line-through'
38287 'text-decoration' : 'line-through'
38289 '.course-timesheet .course-highlight' : {
38290 'border-top-style': 'dashed !important',
38291 'border-bottom-bottom': 'dashed !important'
38293 '.course-timesheet .course-item' : {
38294 'font-family' : 'tahoma, arial, helvetica',
38295 'font-size' : '11px',
38296 'overflow' : 'hidden',
38297 'padding-left' : '10px',
38298 'padding-right' : '10px',
38299 'padding-top' : '10px'
38307 monitorWindowResize : false,
38308 cellrenderer : function(v,x,r)
38313 xtype: 'CellSelectionModel',
38320 beforeload : function (_self, options)
38322 options.params = options.params || {};
38323 options.params._month = _this.monthField.getValue();
38324 options.params.limit = 9999;
38325 options.params['sort'] = 'when_dt';
38326 options.params['dir'] = 'ASC';
38327 this.proxy.loadResponse = this.loadResponse;
38329 //this.addColumns();
38331 load : function (_self, records, options)
38333 _this.grid.view.el.select('.course-edit-link', true).on('click', function() {
38334 // if you click on the translation.. you can edit it...
38335 var el = Roo.get(this);
38336 var id = el.dom.getAttribute('data-id');
38337 var d = el.dom.getAttribute('data-date');
38338 var t = el.dom.getAttribute('data-time');
38339 //var id = this.child('span').dom.textContent;
38342 Pman.Dialog.CourseCalendar.show({
38346 productitem_active : id ? 1 : 0
38348 _this.grid.ds.load({});
38353 _this.panel.fireEvent('resize', [ '', '' ]);
38356 loadResponse : function(o, success, response){
38357 // this is overridden on before load..
38359 Roo.log("our code?");
38360 //Roo.log(success);
38361 //Roo.log(response)
38362 delete this.activeRequest;
38364 this.fireEvent("loadexception", this, o, response);
38365 o.request.callback.call(o.request.scope, null, o.request.arg, false);
38370 result = o.reader.read(response);
38372 Roo.log("load exception?");
38373 this.fireEvent("loadexception", this, o, response, e);
38374 o.request.callback.call(o.request.scope, null, o.request.arg, false);
38377 Roo.log("ready...");
38378 // loop through result.records;
38379 // and set this.tdate[date] = [] << array of records..
38381 Roo.each(result.records, function(r){
38383 if(typeof(_this.tdata[r.data.when_dt.format('j')]) == 'undefined'){
38384 _this.tdata[r.data.when_dt.format('j')] = [];
38386 _this.tdata[r.data.when_dt.format('j')].push(r.data);
38389 //Roo.log(_this.tdata);
38391 result.records = [];
38392 result.totalRecords = 6;
38394 // let's generate some duumy records for the rows.
38395 //var st = _this.dateField.getValue();
38397 // work out monday..
38398 //st = st.add(Date.DAY, -1 * st.format('w'));
38400 var date = Date.parseDate(_this.monthField.getValue(), "Y-m-d");
38402 var firstOfMonth = date.getFirstDayOfMonth();
38403 var days = date.getDaysInMonth();
38405 var firstAdded = false;
38406 for (var i = 0; i < result.totalRecords ; i++) {
38407 //var d= st.add(Date.DAY, i);
38410 for(var w = 0 ; w < 7 ; w++){
38411 if(!firstAdded && firstOfMonth != w){
38418 var dd = (d > 0 && d < 10) ? "0"+d : d;
38419 row['weekday'+w] = String.format(
38420 '<span style="font-size: 16px;"><b>{0}</b></span>'+
38421 '<span class="course-edit-link" style="color:blue;" data-id="0" data-date="{1}"> Add New</span>',
38423 date.format('Y-m-')+dd
38426 if(typeof(_this.tdata[d]) != 'undefined'){
38427 Roo.each(_this.tdata[d], function(r){
38431 var desc = (r.productitem_id_descrip) ? r.productitem_id_descrip : '';
38432 if(r.parent_id*1>0){
38433 is_sub = (r.productitem_id_visible*1 < 1) ? 'de-act-sup-link' :'sub-link';
38436 if(r.productitem_id_visible*1 < 1 && r.parent_id*1 < 1){
38437 deactive = 'de-act-link';
38440 row['weekday'+w] += String.format(
38441 '<br /><span class="course-edit-link {3} {4}" qtip="{5}" data-id="{0}">{2} - {1}</span>',
38443 r.product_id_name, //1
38444 r.when_dt.format('h:ia'), //2
38454 // only do this if something added..
38456 result.records.push(_this.grid.dataSource.reader.newRow(row));
38460 // push it twice. (second one with an hour..
38464 this.fireEvent("load", this, o, o.request.arg);
38465 o.request.callback.call(o.request.scope, result, o.request.arg, true);
38467 sortInfo : {field: 'when_dt', direction : 'ASC' },
38469 xtype: 'HttpProxy',
38472 url : baseURL + '/Roo/Shop_course.php'
38475 xtype: 'JsonReader',
38492 'name': 'parent_id',
38496 'name': 'product_id',
38500 'name': 'productitem_id',
38518 click : function (_self, e)
38520 var sd = Date.parseDate(_this.monthField.getValue(), "Y-m-d");
38521 sd.setMonth(sd.getMonth()-1);
38522 _this.monthField.setValue(sd.format('Y-m-d'));
38523 _this.grid.ds.load({});
38529 xtype: 'Separator',
38533 xtype: 'MonthField',
38536 render : function (_self)
38538 _this.monthField = _self;
38539 // _this.monthField.set today
38541 select : function (combo, date)
38543 _this.grid.ds.load({});
38546 value : (function() { return new Date(); })()
38549 xtype: 'Separator',
38555 text : "Blue: in-active, green: in-active sup-event, red: de-active, purple: de-active sup-event"
38565 click : function (_self, e)
38567 var sd = Date.parseDate(_this.monthField.getValue(), "Y-m-d");
38568 sd.setMonth(sd.getMonth()+1);
38569 _this.monthField.setValue(sd.format('Y-m-d'));
38570 _this.grid.ds.load({});
38583 * Ext JS Library 1.1.1
38584 * Copyright(c) 2006-2007, Ext JS, LLC.
38586 * Originally Released Under LGPL - original licence link has changed is not relivant.
38589 * <script type="text/javascript">
38593 * @class Roo.LoadMask
38594 * A simple utility class for generically masking elements while loading data. If the element being masked has
38595 * an underlying {@link Roo.data.Store}, the masking will be automatically synchronized with the store's loading
38596 * process and the mask element will be cached for reuse. For all other elements, this mask will replace the
38597 * element's UpdateManager load indicator and will be destroyed after the initial load.
38599 * Create a new LoadMask
38600 * @param {String/HTMLElement/Roo.Element} el The element or DOM node, or its id
38601 * @param {Object} config The config object
38603 Roo.LoadMask = function(el, config){
38604 this.el = Roo.get(el);
38605 Roo.apply(this, config);
38607 this.store.on('beforeload', this.onBeforeLoad, this);
38608 this.store.on('load', this.onLoad, this);
38609 this.store.on('loadexception', this.onLoadException, this);
38610 this.removeMask = false;
38612 var um = this.el.getUpdateManager();
38613 um.showLoadIndicator = false; // disable the default indicator
38614 um.on('beforeupdate', this.onBeforeLoad, this);
38615 um.on('update', this.onLoad, this);
38616 um.on('failure', this.onLoad, this);
38617 this.removeMask = true;
38621 Roo.LoadMask.prototype = {
38623 * @cfg {Boolean} removeMask
38624 * True to create a single-use mask that is automatically destroyed after loading (useful for page loads),
38625 * False to persist the mask element reference for multiple uses (e.g., for paged data widgets). Defaults to false.
38628 * @cfg {String} msg
38629 * The text to display in a centered loading message box (defaults to 'Loading...')
38631 msg : 'Loading...',
38633 * @cfg {String} msgCls
38634 * The CSS class to apply to the loading message element (defaults to "x-mask-loading")
38636 msgCls : 'x-mask-loading',
38639 * Read-only. True if the mask is currently disabled so that it will not be displayed (defaults to false)
38645 * Disables the mask to prevent it from being displayed
38647 disable : function(){
38648 this.disabled = true;
38652 * Enables the mask so that it can be displayed
38654 enable : function(){
38655 this.disabled = false;
38658 onLoadException : function()
38660 Roo.log(arguments);
38662 if (typeof(arguments[3]) != 'undefined') {
38663 Roo.MessageBox.alert("Error loading",arguments[3]);
38667 if (this.store && typeof(this.store.reader.jsonData.errorMsg) != 'undefined') {
38668 Roo.MessageBox.alert("Error loading",this.store.reader.jsonData.errorMsg);
38675 (function() { this.el.unmask(this.removeMask); }).defer(50, this);
38678 onLoad : function()
38680 (function() { this.el.unmask(this.removeMask); }).defer(50, this);
38684 onBeforeLoad : function(){
38685 if(!this.disabled){
38686 (function() { this.el.mask(this.msg, this.msgCls); }).defer(50, this);
38691 destroy : function(){
38693 this.store.un('beforeload', this.onBeforeLoad, this);
38694 this.store.un('load', this.onLoad, this);
38695 this.store.un('loadexception', this.onLoadException, this);
38697 var um = this.el.getUpdateManager();
38698 um.un('beforeupdate', this.onBeforeLoad, this);
38699 um.un('update', this.onLoad, this);
38700 um.un('failure', this.onLoad, this);
38705 * Ext JS Library 1.1.1
38706 * Copyright(c) 2006-2007, Ext JS, LLC.
38708 * Originally Released Under LGPL - original licence link has changed is not relivant.
38711 * <script type="text/javascript">
38716 * @class Roo.XTemplate
38717 * @extends Roo.Template
38718 * Provides a template that can have nested templates for loops or conditionals. The syntax is:
38720 var t = new Roo.XTemplate(
38721 '<select name="{name}">',
38722 '<tpl for="options"><option value="{value:trim}">{text:ellipsis(10)}</option></tpl>',
38726 // then append, applying the master template values
38729 * Supported features:
38734 {a_variable} - output encoded.
38735 {a_variable.format:("Y-m-d")} - call a method on the variable
38736 {a_variable:raw} - unencoded output
38737 {a_variable:toFixed(1,2)} - Roo.util.Format."toFixed"
38738 {a_variable:this.method_on_template(...)} - call a method on the template object.
38743 <tpl for="a_variable or condition.."></tpl>
38744 <tpl if="a_variable or condition"></tpl>
38745 <tpl exec="some javascript"></tpl>
38746 <tpl name="named_template"></tpl> (experimental)
38748 <tpl for="."></tpl> - just iterate the property..
38749 <tpl for=".."></tpl> - iterates with the parent (probably the template)
38753 Roo.XTemplate = function()
38755 Roo.XTemplate.superclass.constructor.apply(this, arguments);
38762 Roo.extend(Roo.XTemplate, Roo.Template, {
38765 * The various sub templates
38770 * basic tag replacing syntax
38773 * // you can fake an object call by doing this
38777 re : /\{([\w-\.]+)(?:\:([\w\.]*)(?:\((.*?)?\))?)?\}/g,
38780 * compile the template
38782 * This is not recursive, so I'm not sure how nested templates are really going to be handled..
38785 compile: function()
38789 s = ['<tpl>', s, '</tpl>'].join('');
38791 var re = /<tpl\b[^>]*>((?:(?=([^<]+))\2|<(?!tpl\b[^>]*>))*?)<\/tpl>/,
38792 nameRe = /^<tpl\b[^>]*?for="(.*?)"/,
38793 ifRe = /^<tpl\b[^>]*?if="(.*?)"/,
38794 execRe = /^<tpl\b[^>]*?exec="(.*?)"/,
38795 namedRe = /^<tpl\b[^>]*?name="(\w+)"/, // named templates..
38800 while(true == !!(m = s.match(re))){
38801 var forMatch = m[0].match(nameRe),
38802 ifMatch = m[0].match(ifRe),
38803 execMatch = m[0].match(execRe),
38804 namedMatch = m[0].match(namedRe),
38809 name = forMatch && forMatch[1] ? forMatch[1] : '';
38812 // if - puts fn into test..
38813 exp = ifMatch && ifMatch[1] ? ifMatch[1] : null;
38815 fn = new Function('values', 'parent', 'with(values){ return '+(Roo.util.Format.htmlDecode(exp))+'; }');
38820 // exec - calls a function... returns empty if true is returned.
38821 exp = execMatch && execMatch[1] ? execMatch[1] : null;
38823 exec = new Function('values', 'parent', 'with(values){ '+(Roo.util.Format.htmlDecode(exp))+'; }');
38831 case '.': name = new Function('values', 'parent', 'with(values){ return values; }'); break;
38832 case '..': name = new Function('values', 'parent', 'with(values){ return parent; }'); break;
38833 default: name = new Function('values', 'parent', 'with(values){ return '+name+'; }');
38836 var uid = namedMatch ? namedMatch[1] : id;
38840 id: namedMatch ? namedMatch[1] : id,
38847 s = s.replace(m[0], '');
38849 s = s.replace(m[0], '{xtpl'+ id + '}');
38854 for(var i = tpls.length-1; i >= 0; --i){
38855 this.compileTpl(tpls[i]);
38856 this.tpls[tpls[i].id] = tpls[i];
38858 this.master = tpls[tpls.length-1];
38862 * same as applyTemplate, except it's done to one of the subTemplates
38863 * when using named templates, you can do:
38865 * var str = pl.applySubTemplate('your-name', values);
38868 * @param {Number} id of the template
38869 * @param {Object} values to apply to template
38870 * @param {Object} parent (normaly the instance of this object)
38872 applySubTemplate : function(id, values, parent)
38876 var t = this.tpls[id];
38880 if(t.test && !t.test.call(this, values, parent)){
38884 Roo.log("Xtemplate.applySubTemplate 'test': Exception thrown");
38885 Roo.log(e.toString());
38891 if(t.exec && t.exec.call(this, values, parent)){
38895 Roo.log("Xtemplate.applySubTemplate 'exec': Exception thrown");
38896 Roo.log(e.toString());
38901 var vs = t.target ? t.target.call(this, values, parent) : values;
38902 parent = t.target ? values : parent;
38903 if(t.target && vs instanceof Array){
38905 for(var i = 0, len = vs.length; i < len; i++){
38906 buf[buf.length] = t.compiled.call(this, vs[i], parent);
38908 return buf.join('');
38910 return t.compiled.call(this, vs, parent);
38912 Roo.log("Xtemplate.applySubTemplate : Exception thrown");
38913 Roo.log(e.toString());
38914 Roo.log(t.compiled);
38919 compileTpl : function(tpl)
38921 var fm = Roo.util.Format;
38922 var useF = this.disableFormats !== true;
38923 var sep = Roo.isGecko ? "+" : ",";
38924 var undef = function(str) {
38925 Roo.log("Property not found :" + str);
38929 var fn = function(m, name, format, args)
38931 //Roo.log(arguments);
38932 args = args ? args.replace(/\\'/g,"'") : args;
38933 //["{TEST:(a,b,c)}", "TEST", "", "a,b,c", 0, "{TEST:(a,b,c)}"]
38934 if (typeof(format) == 'undefined') {
38935 format= 'htmlEncode';
38937 if (format == 'raw' ) {
38941 if(name.substr(0, 4) == 'xtpl'){
38942 return "'"+ sep +'this.applySubTemplate('+name.substr(4)+', values, parent)'+sep+"'";
38945 // build an array of options to determine if value is undefined..
38947 // basically get 'xxxx.yyyy' then do
38948 // (typeof(xxxx) == 'undefined' || typeof(xxx.yyyy) == 'undefined') ?
38949 // (function () { Roo.log("Property not found"); return ''; })() :
38954 Roo.each(name.split('.'), function(st) {
38955 lookfor += (lookfor.length ? '.': '') + st;
38956 udef_ar.push( "(typeof(" + lookfor + ") == 'undefined')" );
38959 var udef_st = '((' + udef_ar.join(" || ") +") ? undef('" + name + "') : "; // .. needs )
38962 if(format && useF){
38964 args = args ? ',' + args : "";
38966 if(format.substr(0, 5) != "this."){
38967 format = "fm." + format + '(';
38969 format = 'this.call("'+ format.substr(5) + '", ';
38973 return "'"+ sep + udef_st + format + name + args + "))"+sep+"'";
38977 // called with xxyx.yuu:(test,test)
38979 return "'"+ sep + udef_st + name + '(' + args + "))"+sep+"'";
38981 // raw.. - :raw modifier..
38982 return "'"+ sep + udef_st + name + ")"+sep+"'";
38986 // branched to use + in gecko and [].join() in others
38988 body = "tpl.compiled = function(values, parent){ with(values) { return '" +
38989 tpl.body.replace(/(\r\n|\n)/g, '\\n').replace(/'/g, "\\'").replace(this.re, fn) +
38992 body = ["tpl.compiled = function(values, parent){ with (values) { return ['"];
38993 body.push(tpl.body.replace(/(\r\n|\n)/g,
38994 '\\n').replace(/'/g, "\\'").replace(this.re, fn));
38995 body.push("'].join('');};};");
38996 body = body.join('');
38999 Roo.debug && Roo.log(body.replace(/\\n/,'\n'));
39001 /** eval:var:tpl eval:var:fm eval:var:useF eval:var:undef */
39007 applyTemplate : function(values){
39008 return this.master.compiled.call(this, values, {});
39009 //var s = this.subs;
39012 apply : function(){
39013 return this.applyTemplate.apply(this, arguments);
39018 Roo.XTemplate.from = function(el){
39019 el = Roo.getDom(el);
39020 return new Roo.XTemplate(el.value || el.innerHTML);