4 * base class for bootstrap elements.
8 Roo.bootstrap = Roo.bootstrap || {};
10 * @class Roo.bootstrap.Component
11 * @extends Roo.Component
12 * Bootstrap Component base class
13 * @cfg {String} cls css class
14 * @cfg {String} style any extra css
15 * @cfg {Object} xattr extra attributes to add to 'element' (used by builder to store stuff.)
16 * @cfg {Boolean} can_build_overlaid True if element can be rebuild from a HTML page
17 * @cfg {string} dataId cutomer id
18 * @cfg {string} name Specifies name attribute
19 * @cfg {string} tooltip Text for the tooltip
20 * @cfg {string} container_method method to fetch parents container element (used by NavHeaderbar - getHeaderChildContainer)
21 * @cfg {string|object} visibilityEl (el|parent) What element to use for visibility (@see getVisibilityEl())
24 * Do not use directly - it does not do anything..
25 * @param {Object} config The config object
30 Roo.bootstrap.Component = function(config){
31 Roo.bootstrap.Component.superclass.constructor.call(this, config);
35 * @event childrenrendered
36 * Fires when the children have been rendered..
37 * @param {Roo.bootstrap.Component} this
39 "childrenrendered" : true
48 Roo.extend(Roo.bootstrap.Component, Roo.BoxComponent, {
51 allowDomMove : false, // to stop relocations in parent onRender...
61 * Initialize Events for the element
63 initEvents : function() { },
69 can_build_overlaid : true,
71 container_method : false,
78 // returns the parent component..
79 return Roo.ComponentMgr.get(this.parentId)
85 onRender : function(ct, position)
87 // Roo.log("Call onRender: " + this.xtype);
89 Roo.bootstrap.Component.superclass.onRender.call(this, ct, position);
92 if (this.el.attr('xtype')) {
93 this.el.attr('xtypex', this.el.attr('xtype'));
94 this.el.dom.removeAttribute('xtype');
104 var cfg = Roo.apply({}, this.getAutoCreate());
106 cfg.id = this.id || Roo.id();
108 // fill in the extra attributes
109 if (this.xattr && typeof(this.xattr) =='object') {
110 for (var i in this.xattr) {
111 cfg[i] = this.xattr[i];
116 cfg.dataId = this.dataId;
120 cfg.cls = (typeof(cfg.cls) == 'undefined') ? this.cls : cfg.cls + ' ' + this.cls;
123 if (this.style) { // fixme needs to support more complex style data.
124 cfg.style = this.style;
128 cfg.name = this.name;
131 this.el = ct.createChild(cfg, position);
134 this.tooltipEl().attr('tooltip', this.tooltip);
137 if(this.tabIndex !== undefined){
138 this.el.dom.setAttribute('tabIndex', this.tabIndex);
145 * Fetch the element to add children to
146 * @return {Roo.Element} defaults to this.el
148 getChildContainer : function()
153 * Fetch the element to display the tooltip on.
154 * @return {Roo.Element} defaults to this.el
156 tooltipEl : function()
161 addxtype : function(tree,cntr)
165 cn = Roo.factory(tree);
166 //Roo.log(['addxtype', cn]);
168 cn.parentType = this.xtype; //??
169 cn.parentId = this.id;
171 cntr = (typeof(cntr) == 'undefined' ) ? 'getChildContainer' : cntr;
172 if (typeof(cn.container_method) == 'string') {
173 cntr = cn.container_method;
177 var has_flexy_each = (typeof(tree['flexy:foreach']) != 'undefined');
179 var has_flexy_if = (typeof(tree['flexy:if']) != 'undefined');
181 var build_from_html = Roo.XComponent.build_from_html;
183 var is_body = (tree.xtype == 'Body') ;
185 var page_has_body = (Roo.get(document.body).attr('xtype') == 'Roo.bootstrap.Body');
187 var self_cntr_el = Roo.get(this[cntr](false));
189 // do not try and build conditional elements
190 if ((has_flexy_each || has_flexy_if || this.can_build_overlaid == false ) && build_from_html) {
194 if (!has_flexy_each || !build_from_html || is_body || !page_has_body) {
195 if(!has_flexy_if || typeof(tree.name) == 'undefined' || !build_from_html || is_body || !page_has_body){
196 return this.addxtypeChild(tree,cntr, is_body);
199 var echild =self_cntr_el ? self_cntr_el.child('>*[name=' + tree.name + ']') : false;
202 return this.addxtypeChild(Roo.apply({}, tree),cntr);
205 Roo.log('skipping render');
211 if (!build_from_html) {
215 // this i think handles overlaying multiple children of the same type
216 // with the sam eelement.. - which might be buggy..
218 var echild =self_cntr_el ? self_cntr_el.child('>*[xtype]') : false;
224 if (echild && echild.attr('xtype').split('.').pop() != cn.xtype) {
228 ret = this.addxtypeChild(Roo.apply({}, tree),cntr);
235 addxtypeChild : function (tree, cntr, is_body)
237 Roo.debug && Roo.log('addxtypeChild:' + cntr);
239 cntr = (typeof(cntr) == 'undefined' ) ? 'getChildContainer' : cntr;
242 var has_flexy = (typeof(tree['flexy:if']) != 'undefined') ||
243 (typeof(tree['flexy:foreach']) != 'undefined');
247 skip_children = false;
248 // render the element if it's not BODY.
251 // if parent was disabled, then do not try and create the children..
252 if(!this[cntr](true)){
257 cn = Roo.factory(tree);
259 cn.parentType = this.xtype; //??
260 cn.parentId = this.id;
262 var build_from_html = Roo.XComponent.build_from_html;
265 // does the container contain child eleemnts with 'xtype' attributes.
266 // that match this xtype..
267 // note - when we render we create these as well..
268 // so we should check to see if body has xtype set.
269 if (build_from_html && Roo.get(document.body).attr('xtype') == 'Roo.bootstrap.Body') {
271 var self_cntr_el = Roo.get(this[cntr](false));
272 var echild =self_cntr_el ? self_cntr_el.child('>*[xtype]') : false;
274 //Roo.log(Roo.XComponent.build_from_html);
275 //Roo.log("got echild:");
278 // there is a scenario where some of the child elements are flexy:if (and all of the same type)
279 // and are not displayed -this causes this to use up the wrong element when matching.
280 // at present the only work around for this is to nest flexy:if elements in another element that is always rendered.
283 if (echild && echild.attr('xtype').split('.').pop() == cn.xtype) {
284 // Roo.log("found child for " + this.xtype +": " + echild.attr('xtype') );
290 //echild.dom.removeAttribute('xtype');
292 Roo.debug && Roo.log("MISSING " + cn.xtype + " on child of " + (this.el ? this.el.attr('xbuilderid') : 'no parent'));
293 Roo.debug && Roo.log(self_cntr_el);
294 Roo.debug && Roo.log(echild);
295 Roo.debug && Roo.log(cn);
301 // if object has flexy:if - then it may or may not be rendered.
302 if (build_from_html && has_flexy && !cn.el && cn.can_build_overlaid) {
303 // skip a flexy if element.
304 Roo.debug && Roo.log('skipping render');
305 Roo.debug && Roo.log(tree);
307 Roo.debug && Roo.log('skipping all children');
308 skip_children = true;
313 // actually if flexy:foreach is found, we really want to create
314 // multiple copies here...
316 //Roo.log(this[cntr]());
317 // some elements do not have render methods.. like the layouts...
319 if(this[cntr](true) === false){
324 cn.render && cn.render(this[cntr](true));
327 // then add the element..
334 if (typeof (tree.menu) != 'undefined') {
335 tree.menu.parentType = cn.xtype;
336 tree.menu.triggerEl = cn.el;
337 nitems.push(cn.addxtype(Roo.apply({}, tree.menu)));
341 if (!tree.items || !tree.items.length) {
343 //Roo.log(["no children", this]);
348 var items = tree.items;
351 //Roo.log(items.length);
353 if (!skip_children) {
354 for(var i =0;i < items.length;i++) {
355 // Roo.log(['add child', items[i]]);
356 nitems.push(cn.addxtype(Roo.apply({}, items[i])));
362 //Roo.log("fire childrenrendered");
364 cn.fireEvent('childrenrendered', this);
370 * Set the element that will be used to show or hide
372 setVisibilityEl : function(el)
374 this.visibilityEl = el;
378 * Get the element that will be used to show or hide
380 getVisibilityEl : function()
382 if (typeof(this.visibilityEl) == 'object') {
383 return this.visibilityEl;
386 if (typeof(this.visibilityEl) == 'string') {
387 return this.visibilityEl == 'parent' ? this.parent().getEl() : this.getEl();
394 * Show a component - removes 'hidden' class
398 if(!this.getVisibilityEl()){
402 this.getVisibilityEl().removeClass('hidden');
404 this.fireEvent('show', this);
409 * Hide a component - adds 'hidden' class
413 if(!this.getVisibilityEl()){
417 this.getVisibilityEl().addClass('hidden');
419 this.fireEvent('hide', this);
432 * @class Roo.bootstrap.Body
433 * @extends Roo.bootstrap.Component
434 * Bootstrap Body class
438 * @param {Object} config The config object
441 Roo.bootstrap.Body = function(config){
443 config = config || {};
445 Roo.bootstrap.Body.superclass.constructor.call(this, config);
446 this.el = Roo.get(config.el ? config.el : document.body );
447 if (this.cls && this.cls.length) {
448 Roo.get(document.body).addClass(this.cls);
452 Roo.extend(Roo.bootstrap.Body, Roo.bootstrap.Component, {
454 is_body : true,// just to make sure it's constructed?
459 onRender : function(ct, position)
461 /* Roo.log("Roo.bootstrap.Body - onRender");
462 if (this.cls && this.cls.length) {
463 Roo.get(document.body).addClass(this.cls);
482 * @class Roo.bootstrap.ButtonGroup
483 * @extends Roo.bootstrap.Component
484 * Bootstrap ButtonGroup class
485 * @cfg {String} size lg | sm | xs (default empty normal)
486 * @cfg {String} align vertical | justified (default none)
487 * @cfg {String} direction up | down (default down)
488 * @cfg {Boolean} toolbar false | true
489 * @cfg {Boolean} btn true | false
494 * @param {Object} config The config object
497 Roo.bootstrap.ButtonGroup = function(config){
498 Roo.bootstrap.ButtonGroup.superclass.constructor.call(this, config);
501 Roo.extend(Roo.bootstrap.ButtonGroup, Roo.bootstrap.Component, {
509 getAutoCreate : function(){
515 cfg.html = this.html || cfg.html;
526 if (['vertical','justified'].indexOf(this.align)!==-1) {
527 cfg.cls = 'btn-group-' + this.align;
529 if (this.align == 'justified') {
530 console.log(this.items);
534 if (['lg','sm','xs'].indexOf(this.size)!==-1) {
535 cfg.cls += ' btn-group-' + this.size;
538 if (this.direction == 'up') {
539 cfg.cls += ' dropup' ;
555 * @class Roo.bootstrap.Button
556 * @extends Roo.bootstrap.Component
557 * Bootstrap Button class
558 * @cfg {String} html The button content
559 * @cfg {String} weight (default | primary | success | info | warning | danger | link ) default
560 * @cfg {String} size ( lg | sm | xs)
561 * @cfg {String} tag ( a | input | submit)
562 * @cfg {String} href empty or href
563 * @cfg {Boolean} disabled default false;
564 * @cfg {Boolean} isClose default false;
565 * @cfg {String} glyphicon (| adjust | align-center | align-justify | align-left | align-right | arrow-down | arrow-left | arrow-right | arrow-up | asterisk | backward | ban-circle | barcode | bell | bold | book | bookmark | briefcase | bullhorn | calendar | camera | certificate | check | chevron-down | chevron-left | chevron-right | chevron-up | circle-arrow-down | circle-arrow-left | circle-arrow-right | circle-arrow-up | cloud | cloud-download | cloud-upload | cog | collapse-down | collapse-up | comment | compressed | copyright-mark | credit-card | cutlery | dashboard | download | download-alt | earphone | edit | eject | envelope | euro | exclamation-sign | expand | export | eye-close | eye-open | facetime-video | fast-backward | fast-forward | file | film | filter | fire | flag | flash | floppy-disk | floppy-open | floppy-remove | floppy-save | floppy-saved | folder-close | folder-open | font | forward | fullscreen | gbp | gift | glass | globe | hand-down | hand-left | hand-right | hand-up | hd-video | hdd | header | headphones | heart | heart-empty | home | import | inbox | indent-left | indent-right | info-sign | italic | leaf | link | list | list-alt | lock | log-in | log-out | magnet | map-marker | minus | minus-sign | move | music | new-window | off | ok | ok-circle | ok-sign | open | paperclip | pause | pencil | phone | phone-alt | picture | plane | play | play-circle | plus | plus-sign | print | pushpin | qrcode | question-sign | random | record | refresh | registration-mark | remove | remove-circle | remove-sign | repeat | resize-full | resize-horizontal | resize-small | resize-vertical | retweet | road | save | saved | screenshot | sd-video | search | send | share | share-alt | shopping-cart | signal | sort | sort-by-alphabet | sort-by-alphabet-alt | sort-by-attributes | sort-by-attributes-alt | sort-by-order | sort-by-order-alt | sound-5-1 | sound-6-1 | sound-7-1 | sound-dolby | sound-stereo | star | star-empty | stats | step-backward | step-forward | stop | subtitles | tag | tags | tasks | text-height | text-width | th | th-large | th-list | thumbs-down | thumbs-up | time | tint | tower | transfer | trash | tree-conifer | tree-deciduous | unchecked | upload | usd | user | volume-down | volume-off | volume-up | warning-sign | wrench | zoom-in | zoom-out)
566 * @cfg {String} badge text for badge
567 * @cfg {String} theme (default|glow)
568 * @cfg {Boolean} inverse dark themed version
569 * @cfg {Boolean} toggle is it a slidy toggle button
570 * @cfg {Boolean} pressed (true|false) default null - if the button ahs active state
571 * @cfg {String} ontext text for on slidy toggle state
572 * @cfg {String} offtext text for off slidy toggle state
573 * @cfg {Boolean} preventDefault default true (stop click event triggering the URL if it's a link.)
574 * @cfg {Boolean} removeClass remove the standard class..
575 * @cfg {String} target target for a href. (_self|_blank|_parent|_top| other)
578 * Create a new button
579 * @param {Object} config The config object
583 Roo.bootstrap.Button = function(config){
584 Roo.bootstrap.Button.superclass.constructor.call(this, config);
585 this.weightClass = ["btn-default",
597 * When a butotn is pressed
598 * @param {Roo.bootstrap.Button} btn
599 * @param {Roo.EventObject} e
604 * After the button has been toggles
605 * @param {Roo.bootstrap.Button} btn
606 * @param {Roo.EventObject} e
607 * @param {boolean} pressed (also available as button.pressed)
613 Roo.extend(Roo.bootstrap.Button, Roo.bootstrap.Component, {
631 preventDefault: true,
639 getAutoCreate : function(){
647 if (['a', 'button', 'input', 'submit'].indexOf(this.tag) < 0) {
648 throw "Invalid value for tag: " + this.tag + ". must be a, button, input or submit.";
653 cfg.html = '<span class="roo-button-text">' + (this.html || cfg.html) + '</span>';
655 if (this.toggle == true) {
658 cls: 'slider-frame roo-button',
663 'data-off-text':'OFF',
664 cls: 'slider-button',
670 if (['default', 'primary', 'success', 'info', 'warning', 'danger', 'link'].indexOf(this.weight) > -1) {
671 cfg.cls += ' '+this.weight;
680 cfg["aria-hidden"] = true;
682 cfg.html = "×";
688 if (this.theme==='default') {
689 cfg.cls = 'btn roo-button';
691 //if (this.parentType != 'Navbar') {
692 this.weight = this.weight.length ? this.weight : 'default';
694 if (['default', 'primary', 'success', 'info', 'warning', 'danger', 'link'].indexOf(this.weight) > -1) {
696 cfg.cls += ' btn-' + this.weight;
698 } else if (this.theme==='glow') {
701 cfg.cls = 'btn-glow roo-button';
703 if (['default', 'primary', 'success', 'info', 'warning', 'danger', 'link'].indexOf(this.weight) > -1) {
705 cfg.cls += ' ' + this.weight;
711 this.cls += ' inverse';
715 if (this.active || this.pressed === true) {
716 cfg.cls += ' active';
720 cfg.disabled = 'disabled';
724 Roo.log('changing to ul' );
726 this.glyphicon = 'caret';
729 cfg.cls += this.size.length ? (' btn-' + this.size) : '';
731 //gsRoo.log(this.parentType);
732 if (this.parentType === 'Navbar' && !this.parent().bar) {
733 Roo.log('changing to li?');
742 href : this.href || '#'
745 cfg.cn[0].html = this.html + ' <span class="caret"></span>';
746 cfg.cls += ' dropdown';
753 cfg.cls += this.parentType === 'Navbar' ? ' navbar-btn' : '';
755 if (this.glyphicon) {
756 cfg.html = ' ' + cfg.html;
761 cls: 'glyphicon glyphicon-' + this.glyphicon
771 // cfg.cls='btn roo-button';
775 var value = cfg.html;
780 cls: 'glyphicon glyphicon-' + this.glyphicon,
799 cfg.cls += ' dropdown';
800 cfg.html = typeof(cfg.html) != 'undefined' ?
801 cfg.html + ' <span class="caret"></span>' : '<span class="caret"></span>';
804 if (cfg.tag !== 'a' && this.href !== '') {
805 throw "Tag must be a to set href.";
806 } else if (this.href.length > 0) {
807 cfg.href = this.href;
810 if(this.removeClass){
815 cfg.target = this.target;
820 initEvents: function() {
821 // Roo.log('init events?');
822 // Roo.log(this.el.dom);
825 if (typeof (this.menu) != 'undefined') {
826 this.menu.parentType = this.xtype;
827 this.menu.triggerEl = this.el;
828 this.addxtype(Roo.apply({}, this.menu));
832 if (this.el.hasClass('roo-button')) {
833 this.el.on('click', this.onClick, this);
835 this.el.select('.roo-button').on('click', this.onClick, this);
838 if(this.removeClass){
839 this.el.on('click', this.onClick, this);
842 this.el.enableDisplayMode();
845 onClick : function(e)
851 Roo.log('button on click ');
852 if(this.preventDefault){
856 if (this.pressed === true || this.pressed === false) {
857 this.toggleActive(e);
861 this.fireEvent('click', this, e);
865 * Enables this button
869 this.disabled = false;
870 this.el.removeClass('disabled');
874 * Disable this button
878 this.disabled = true;
879 this.el.addClass('disabled');
882 * sets the active state on/off,
883 * @param {Boolean} state (optional) Force a particular state
885 setActive : function(v) {
887 this.el[v ? 'addClass' : 'removeClass']('active');
891 * toggles the current active state
893 toggleActive : function(e)
895 this.setActive(!this.pressed);
896 this.fireEvent('toggle', this, e, !this.pressed);
899 * get the current active state
900 * @return {boolean} true if it's active
902 isActive : function()
904 return this.el.hasClass('active');
907 * set the text of the first selected button
909 setText : function(str)
911 this.el.select('.roo-button-text',true).first().dom.innerHTML = str;
914 * get the text of the first selected button
918 return this.el.select('.roo-button-text',true).first().dom.innerHTML;
921 setWeight : function(str)
923 this.el.removeClass(this.weightClass);
924 this.el.addClass('btn-' + str);
938 * @class Roo.bootstrap.Column
939 * @extends Roo.bootstrap.Component
940 * Bootstrap Column class
941 * @cfg {Number} xs colspan out of 12 for mobile-sized screens or 0 for hidden
942 * @cfg {Number} sm colspan out of 12 for tablet-sized screens or 0 for hidden
943 * @cfg {Number} md colspan out of 12 for computer-sized screens or 0 for hidden
944 * @cfg {Number} lg colspan out of 12 for large computer-sized screens or 0 for hidden
945 * @cfg {Number} xsoff colspan offset out of 12 for mobile-sized screens or 0 for hidden
946 * @cfg {Number} smoff colspan offset out of 12 for tablet-sized screens or 0 for hidden
947 * @cfg {Number} mdoff colspan offset out of 12 for computer-sized screens or 0 for hidden
948 * @cfg {Number} lgoff colspan offset out of 12 for large computer-sized screens or 0 for hidden
951 * @cfg {Boolean} hidden (true|false) hide the element
952 * @cfg {String} alert (success|info|warning|danger) type alert (changes background / border...)
953 * @cfg {String} fa (ban|check|...) font awesome icon
954 * @cfg {Number} fasize (1|2|....) font awsome size
956 * @cfg {String} icon (info-sign|check|...) glyphicon name
958 * @cfg {String} html content of column.
961 * Create a new Column
962 * @param {Object} config The config object
965 Roo.bootstrap.Column = function(config){
966 Roo.bootstrap.Column.superclass.constructor.call(this, config);
969 Roo.extend(Roo.bootstrap.Column, Roo.bootstrap.Component, {
987 getAutoCreate : function(){
988 var cfg = Roo.apply({}, Roo.bootstrap.Column.superclass.getAutoCreate.call(this));
996 ['xs','sm','md','lg'].map(function(size){
997 //Roo.log( size + ':' + settings[size]);
999 if (settings[size+'off'] !== false) {
1000 cfg.cls += ' col-' + size + '-offset-' + settings[size+'off'] ;
1003 if (settings[size] === false) {
1007 if (!settings[size]) { // 0 = hidden
1008 cfg.cls += ' hidden-' + size;
1011 cfg.cls += ' col-' + size + '-' + settings[size];
1016 cfg.cls += ' hidden';
1019 if (this.alert && ["success","info","warning", "danger"].indexOf(this.alert) > -1) {
1020 cfg.cls +=' alert alert-' + this.alert;
1024 if (this.html.length) {
1025 cfg.html = this.html;
1029 if (this.fasize > 1) {
1030 fasize = ' fa-' + this.fasize + 'x';
1032 cfg.html = '<i class="fa fa-'+this.fa + fasize + '"></i>' + (cfg.html || '');
1037 cfg.html = '<i class="glyphicon glyphicon-'+this.icon + '"></i>' + (cfg.html || '');
1056 * @class Roo.bootstrap.Container
1057 * @extends Roo.bootstrap.Component
1058 * Bootstrap Container class
1059 * @cfg {Boolean} jumbotron is it a jumbotron element
1060 * @cfg {String} html content of element
1061 * @cfg {String} well (lg|sm|md) a well, large, small or medium.
1062 * @cfg {String} panel (default|primary|success|info|warning|danger) render as panel - type - primary/success.....
1063 * @cfg {String} header content of header (for panel)
1064 * @cfg {String} footer content of footer (for panel)
1065 * @cfg {String} sticky (footer|wrap|push) block to use as footer or body- needs css-bootstrap/sticky-footer.css
1066 * @cfg {String} tag (header|aside|section) type of HTML tag.
1067 * @cfg {String} alert (success|info|warning|danger) type alert (changes background / border...)
1068 * @cfg {String} fa font awesome icon
1069 * @cfg {String} icon (info-sign|check|...) glyphicon name
1070 * @cfg {Boolean} hidden (true|false) hide the element
1071 * @cfg {Boolean} expandable (true|false) default false
1072 * @cfg {Boolean} expanded (true|false) default true
1073 * @cfg {String} rheader contet on the right of header
1074 * @cfg {Boolean} clickable (true|false) default false
1078 * Create a new Container
1079 * @param {Object} config The config object
1082 Roo.bootstrap.Container = function(config){
1083 Roo.bootstrap.Container.superclass.constructor.call(this, config);
1089 * After the panel has been expand
1091 * @param {Roo.bootstrap.Container} this
1096 * After the panel has been collapsed
1098 * @param {Roo.bootstrap.Container} this
1103 * When a element is chick
1104 * @param {Roo.bootstrap.Container} this
1105 * @param {Roo.EventObject} e
1111 Roo.extend(Roo.bootstrap.Container, Roo.bootstrap.Component, {
1129 getChildContainer : function() {
1135 if (this.panel.length) {
1136 return this.el.select('.panel-body',true).first();
1143 getAutoCreate : function(){
1146 tag : this.tag || 'div',
1150 if (this.jumbotron) {
1151 cfg.cls = 'jumbotron';
1156 // - this is applied by the parent..
1158 // cfg.cls = this.cls + '';
1161 if (this.sticky.length) {
1163 var bd = Roo.get(document.body);
1164 if (!bd.hasClass('bootstrap-sticky')) {
1165 bd.addClass('bootstrap-sticky');
1166 Roo.select('html',true).setStyle('height', '100%');
1169 cfg.cls += 'bootstrap-sticky-' + this.sticky;
1173 if (this.well.length) {
1174 switch (this.well) {
1177 cfg.cls +=' well well-' +this.well;
1186 cfg.cls += ' hidden';
1190 if (this.alert && ["success","info","warning", "danger"].indexOf(this.alert) > -1) {
1191 cfg.cls +=' alert alert-' + this.alert;
1196 if (this.panel.length) {
1197 cfg.cls += ' panel panel-' + this.panel;
1199 if (this.header.length) {
1203 if(this.expandable){
1205 cfg.cls = cfg.cls + ' expandable';
1209 cls: (this.expanded ? 'fa fa-minus' : 'fa fa-plus')
1217 cls : 'panel-title',
1218 html : (this.expandable ? ' ' : '') + this.header
1222 cls: 'panel-header-right',
1228 cls : 'panel-heading',
1229 style : this.expandable ? 'cursor: pointer' : '',
1237 cls : 'panel-body' + (this.expanded ? '' : ' hide'),
1242 if (this.footer.length) {
1244 cls : 'panel-footer',
1253 body.html = this.html || cfg.html;
1254 // prefix with the icons..
1256 body.html = '<i class="fa fa-'+this.fa + '"></i>' + body.html ;
1259 body.html = '<i class="glyphicon glyphicon-'+this.icon + '"></i>' + body.html ;
1264 if ((!this.cls || !this.cls.length) && (!cfg.cls || !cfg.cls.length)) {
1265 cfg.cls = 'container';
1271 initEvents: function()
1273 if(this.expandable){
1274 var headerEl = this.headerEl();
1277 headerEl.on('click', this.onToggleClick, this);
1282 this.el.on('click', this.onClick, this);
1287 onToggleClick : function()
1289 var headerEl = this.headerEl();
1305 if(this.fireEvent('expand', this)) {
1307 this.expanded = true;
1309 //this.el.select('.panel-body',true).first().setVisibilityMode(Roo.Element.DISPLAY).show();
1311 this.el.select('.panel-body',true).first().removeClass('hide');
1313 var toggleEl = this.toggleEl();
1319 toggleEl.removeClass(['fa-minus', 'fa-plus']).addClass(['fa-minus']);
1324 collapse : function()
1326 if(this.fireEvent('collapse', this)) {
1328 this.expanded = false;
1330 //this.el.select('.panel-body',true).first().setVisibilityMode(Roo.Element.DISPLAY).hide();
1331 this.el.select('.panel-body',true).first().addClass('hide');
1333 var toggleEl = this.toggleEl();
1339 toggleEl.removeClass(['fa-minus', 'fa-plus']).addClass(['fa-plus']);
1343 toggleEl : function()
1345 if(!this.el || !this.panel.length || !this.header.length || !this.expandable){
1349 return this.el.select('.panel-heading .fa',true).first();
1352 headerEl : function()
1354 if(!this.el || !this.panel.length || !this.header.length){
1358 return this.el.select('.panel-heading',true).first()
1363 if(!this.el || !this.panel.length){
1367 return this.el.select('.panel-body',true).first()
1370 titleEl : function()
1372 if(!this.el || !this.panel.length || !this.header.length){
1376 return this.el.select('.panel-title',true).first();
1379 setTitle : function(v)
1381 var titleEl = this.titleEl();
1387 titleEl.dom.innerHTML = v;
1390 getTitle : function()
1393 var titleEl = this.titleEl();
1399 return titleEl.dom.innerHTML;
1402 setRightTitle : function(v)
1404 var t = this.el.select('.panel-header-right',true).first();
1410 t.dom.innerHTML = v;
1413 onClick : function(e)
1417 this.fireEvent('click', this, e);
1430 * @class Roo.bootstrap.Img
1431 * @extends Roo.bootstrap.Component
1432 * Bootstrap Img class
1433 * @cfg {Boolean} imgResponsive false | true
1434 * @cfg {String} border rounded | circle | thumbnail
1435 * @cfg {String} src image source
1436 * @cfg {String} alt image alternative text
1437 * @cfg {String} href a tag href
1438 * @cfg {String} target (_self|_blank|_parent|_top)target for a href.
1439 * @cfg {String} xsUrl xs image source
1440 * @cfg {String} smUrl sm image source
1441 * @cfg {String} mdUrl md image source
1442 * @cfg {String} lgUrl lg image source
1445 * Create a new Input
1446 * @param {Object} config The config object
1449 Roo.bootstrap.Img = function(config){
1450 Roo.bootstrap.Img.superclass.constructor.call(this, config);
1456 * The img click event for the img.
1457 * @param {Roo.EventObject} e
1463 Roo.extend(Roo.bootstrap.Img, Roo.bootstrap.Component, {
1465 imgResponsive: true,
1475 getAutoCreate : function()
1477 if(this.src || (!this.xsUrl && !this.smUrl && !this.mdUrl && !this.lgUrl)){
1478 return this.createSingleImg();
1483 cls: 'roo-image-responsive-group',
1488 Roo.each(['xs', 'sm', 'md', 'lg'], function(size){
1490 if(!_this[size + 'Url']){
1496 cls: (_this.imgResponsive) ? 'img-responsive' : '',
1497 html: _this.html || cfg.html,
1498 src: _this[size + 'Url']
1501 img.cls += ' roo-image-responsive-' + size;
1503 var s = ['xs', 'sm', 'md', 'lg'];
1505 s.splice(s.indexOf(size), 1);
1507 Roo.each(s, function(ss){
1508 img.cls += ' hidden-' + ss;
1511 if (['rounded','circle','thumbnail'].indexOf(_this.border)>-1) {
1512 cfg.cls += ' img-' + _this.border;
1516 cfg.alt = _this.alt;
1529 a.target = _this.target;
1533 cfg.cn.push((_this.href) ? a : img);
1540 createSingleImg : function()
1544 cls: (this.imgResponsive) ? 'img-responsive' : '',
1546 src : 'about:blank' // just incase src get's set to undefined?!?
1549 cfg.html = this.html || cfg.html;
1551 cfg.src = this.src || cfg.src;
1553 if (['rounded','circle','thumbnail'].indexOf(this.border)>-1) {
1554 cfg.cls += ' img-' + this.border;
1571 a.target = this.target;
1576 return (this.href) ? a : cfg;
1579 initEvents: function()
1582 this.el.on('click', this.onClick, this);
1587 onClick : function(e)
1589 Roo.log('img onclick');
1590 this.fireEvent('click', this, e);
1593 * Sets the url of the image - used to update it
1594 * @param {String} url the url of the image
1597 setSrc : function(url)
1601 if(this.src || (!this.xsUrl && !this.smUrl && !this.mdUrl && !this.lgUrl)){
1602 this.el.dom.src = url;
1606 this.el.select('img', true).first().dom.src = url;
1622 * @class Roo.bootstrap.Link
1623 * @extends Roo.bootstrap.Component
1624 * Bootstrap Link Class
1625 * @cfg {String} alt image alternative text
1626 * @cfg {String} href a tag href
1627 * @cfg {String} target (_self|_blank|_parent|_top) target for a href.
1628 * @cfg {String} html the content of the link.
1629 * @cfg {String} anchor name for the anchor link
1630 * @cfg {String} fa - favicon
1632 * @cfg {Boolean} preventDefault (true | false) default false
1636 * Create a new Input
1637 * @param {Object} config The config object
1640 Roo.bootstrap.Link = function(config){
1641 Roo.bootstrap.Link.superclass.constructor.call(this, config);
1647 * The img click event for the img.
1648 * @param {Roo.EventObject} e
1654 Roo.extend(Roo.bootstrap.Link, Roo.bootstrap.Component, {
1658 preventDefault: false,
1664 getAutoCreate : function()
1666 var html = this.html || '';
1668 if (this.fa !== false) {
1669 html = '<i class="fa fa-' + this.fa + '"></i>';
1674 // anchor's do not require html/href...
1675 if (this.anchor === false) {
1677 cfg.href = this.href || '#';
1679 cfg.name = this.anchor;
1680 if (this.html !== false || this.fa !== false) {
1683 if (this.href !== false) {
1684 cfg.href = this.href;
1688 if(this.alt !== false){
1693 if(this.target !== false) {
1694 cfg.target = this.target;
1700 initEvents: function() {
1702 if(!this.href || this.preventDefault){
1703 this.el.on('click', this.onClick, this);
1707 onClick : function(e)
1709 if(this.preventDefault){
1712 //Roo.log('img onclick');
1713 this.fireEvent('click', this, e);
1726 * @class Roo.bootstrap.Header
1727 * @extends Roo.bootstrap.Component
1728 * Bootstrap Header class
1729 * @cfg {String} html content of header
1730 * @cfg {Number} level (1|2|3|4|5|6) default 1
1733 * Create a new Header
1734 * @param {Object} config The config object
1738 Roo.bootstrap.Header = function(config){
1739 Roo.bootstrap.Header.superclass.constructor.call(this, config);
1742 Roo.extend(Roo.bootstrap.Header, Roo.bootstrap.Component, {
1750 getAutoCreate : function(){
1755 tag: 'h' + (1 *this.level),
1756 html: this.html || ''
1768 * Ext JS Library 1.1.1
1769 * Copyright(c) 2006-2007, Ext JS, LLC.
1771 * Originally Released Under LGPL - original licence link has changed is not relivant.
1774 * <script type="text/javascript">
1778 * @class Roo.bootstrap.MenuMgr
1779 * Provides a common registry of all menu items on a page so that they can be easily accessed by id.
1782 Roo.bootstrap.MenuMgr = function(){
1783 var menus, active, groups = {}, attached = false, lastShow = new Date();
1785 // private - called when first menu is created
1788 active = new Roo.util.MixedCollection();
1789 Roo.get(document).addKeyListener(27, function(){
1790 if(active.length > 0){
1798 if(active && active.length > 0){
1799 var c = active.clone();
1809 if(active.length < 1){
1810 Roo.get(document).un("mouseup", onMouseDown);
1818 var last = active.last();
1819 lastShow = new Date();
1822 Roo.get(document).on("mouseup", onMouseDown);
1827 //m.getEl().setZIndex(parseInt(m.parentMenu.getEl().getStyle("z-index"), 10) + 3);
1828 m.parentMenu.activeChild = m;
1829 }else if(last && last.isVisible()){
1830 //m.getEl().setZIndex(parseInt(last.getEl().getStyle("z-index"), 10) + 3);
1835 function onBeforeHide(m){
1837 m.activeChild.hide();
1839 if(m.autoHideTimer){
1840 clearTimeout(m.autoHideTimer);
1841 delete m.autoHideTimer;
1846 function onBeforeShow(m){
1847 var pm = m.parentMenu;
1848 if(!pm && !m.allowOtherMenus){
1850 }else if(pm && pm.activeChild && active != m){
1851 pm.activeChild.hide();
1855 // private this should really trigger on mouseup..
1856 function onMouseDown(e){
1857 Roo.log("on Mouse Up");
1859 if(lastShow.getElapsed() > 50 && active.length > 0 && !e.getTarget(".dropdown-menu") && !e.getTarget('.user-menu')){
1860 Roo.log("MenuManager hideAll");
1869 function onBeforeCheck(mi, state){
1871 var g = groups[mi.group];
1872 for(var i = 0, l = g.length; i < l; i++){
1874 g[i].setChecked(false);
1883 * Hides all menus that are currently visible
1885 hideAll : function(){
1890 register : function(menu){
1894 menus[menu.id] = menu;
1895 menu.on("beforehide", onBeforeHide);
1896 menu.on("hide", onHide);
1897 menu.on("beforeshow", onBeforeShow);
1898 menu.on("show", onShow);
1900 if(g && menu.events["checkchange"]){
1904 groups[g].push(menu);
1905 menu.on("checkchange", onCheck);
1910 * Returns a {@link Roo.menu.Menu} object
1911 * @param {String/Object} menu The string menu id, an existing menu object reference, or a Menu config that will
1912 * be used to generate and return a new Menu instance.
1914 get : function(menu){
1915 if(typeof menu == "string"){ // menu id
1917 }else if(menu.events){ // menu instance
1920 /*else if(typeof menu.length == 'number'){ // array of menu items?
1921 return new Roo.bootstrap.Menu({items:menu});
1922 }else{ // otherwise, must be a config
1923 return new Roo.bootstrap.Menu(menu);
1930 unregister : function(menu){
1931 delete menus[menu.id];
1932 menu.un("beforehide", onBeforeHide);
1933 menu.un("hide", onHide);
1934 menu.un("beforeshow", onBeforeShow);
1935 menu.un("show", onShow);
1937 if(g && menu.events["checkchange"]){
1938 groups[g].remove(menu);
1939 menu.un("checkchange", onCheck);
1944 registerCheckable : function(menuItem){
1945 var g = menuItem.group;
1950 groups[g].push(menuItem);
1951 menuItem.on("beforecheckchange", onBeforeCheck);
1956 unregisterCheckable : function(menuItem){
1957 var g = menuItem.group;
1959 groups[g].remove(menuItem);
1960 menuItem.un("beforecheckchange", onBeforeCheck);
1972 * @class Roo.bootstrap.Menu
1973 * @extends Roo.bootstrap.Component
1974 * Bootstrap Menu class - container for MenuItems
1975 * @cfg {String} type (dropdown|treeview|submenu) type of menu
1976 * @cfg {bool} hidden if the menu should be hidden when rendered.
1977 * @cfg {bool} stopEvent (true|false) Stop event after trigger press (default true)
1978 * @cfg {bool} isLink (true|false) the menu has link disable auto expand and collaspe (default false)
1982 * @param {Object} config The config object
1986 Roo.bootstrap.Menu = function(config){
1987 Roo.bootstrap.Menu.superclass.constructor.call(this, config);
1988 if (this.registerMenu && this.type != 'treeview') {
1989 Roo.bootstrap.MenuMgr.register(this);
1994 * Fires before this menu is displayed
1995 * @param {Roo.menu.Menu} this
2000 * Fires before this menu is hidden
2001 * @param {Roo.menu.Menu} this
2006 * Fires after this menu is displayed
2007 * @param {Roo.menu.Menu} this
2012 * Fires after this menu is hidden
2013 * @param {Roo.menu.Menu} this
2018 * Fires when this menu is clicked (or when the enter key is pressed while it is active)
2019 * @param {Roo.menu.Menu} this
2020 * @param {Roo.menu.Item} menuItem The menu item that was clicked
2021 * @param {Roo.EventObject} e
2026 * Fires when the mouse is hovering over this menu
2027 * @param {Roo.menu.Menu} this
2028 * @param {Roo.EventObject} e
2029 * @param {Roo.menu.Item} menuItem The menu item that was clicked
2034 * Fires when the mouse exits this menu
2035 * @param {Roo.menu.Menu} this
2036 * @param {Roo.EventObject} e
2037 * @param {Roo.menu.Item} menuItem The menu item that was clicked
2042 * Fires when a menu item contained in this menu is clicked
2043 * @param {Roo.menu.BaseItem} baseItem The BaseItem that was clicked
2044 * @param {Roo.EventObject} e
2048 this.menuitems = new Roo.util.MixedCollection(false, function(o) { return o.el.id; });
2051 Roo.extend(Roo.bootstrap.Menu, Roo.bootstrap.Component, {
2055 triggerEl : false, // is this set by component builder? -- it should really be fetched from parent()???
2058 * @cfg {Boolean} registerMenu True (default) - means that clicking on screen etc. hides it.
2060 registerMenu : true,
2062 menuItems :false, // stores the menu items..
2072 getChildContainer : function() {
2076 getAutoCreate : function(){
2078 //if (['right'].indexOf(this.align)!==-1) {
2079 // cfg.cn[1].cls += ' pull-right'
2085 cls : 'dropdown-menu' ,
2086 style : 'z-index:1000'
2090 if (this.type === 'submenu') {
2091 cfg.cls = 'submenu active';
2093 if (this.type === 'treeview') {
2094 cfg.cls = 'treeview-menu';
2099 initEvents : function() {
2101 // Roo.log("ADD event");
2102 // Roo.log(this.triggerEl.dom);
2104 this.triggerEl.on('click', this.onTriggerClick, this);
2106 this.triggerEl.on(Roo.isTouch ? 'touchstart' : 'mouseup', this.onTriggerPress, this);
2108 this.triggerEl.addClass('dropdown-toggle');
2111 this.el.on('touchstart' , this.onTouch, this);
2113 this.el.on('click' , this.onClick, this);
2115 this.el.on("mouseover", this.onMouseOver, this);
2116 this.el.on("mouseout", this.onMouseOut, this);
2120 findTargetItem : function(e)
2122 var t = e.getTarget(".dropdown-menu-item", this.el, true);
2126 //Roo.log(t); Roo.log(t.id);
2128 //Roo.log(this.menuitems);
2129 return this.menuitems.get(t.id);
2131 //return this.items.get(t.menuItemId);
2137 onTouch : function(e)
2139 Roo.log("menu.onTouch");
2140 //e.stopEvent(); this make the user popdown broken
2144 onClick : function(e)
2146 Roo.log("menu.onClick");
2148 var t = this.findTargetItem(e);
2149 if(!t || t.isContainer){
2154 if (Roo.isTouch && e.type == 'touchstart' && t.menu && !t.disabled) {
2155 if(t == this.activeItem && t.shouldDeactivate(e)){
2156 this.activeItem.deactivate();
2157 delete this.activeItem;
2161 this.setActiveItem(t, true);
2169 Roo.log('pass click event');
2173 this.fireEvent("click", this, t, e);
2177 if(!t.href.length || t.href == '#'){
2178 (function() { _this.hide(); }).defer(100);
2183 onMouseOver : function(e){
2184 var t = this.findTargetItem(e);
2187 // if(t.canActivate && !t.disabled){
2188 // this.setActiveItem(t, true);
2192 this.fireEvent("mouseover", this, e, t);
2194 isVisible : function(){
2195 return !this.hidden;
2197 onMouseOut : function(e){
2198 var t = this.findTargetItem(e);
2201 // if(t == this.activeItem && t.shouldDeactivate(e)){
2202 // this.activeItem.deactivate();
2203 // delete this.activeItem;
2206 this.fireEvent("mouseout", this, e, t);
2211 * Displays this menu relative to another element
2212 * @param {String/HTMLElement/Roo.Element} element The element to align to
2213 * @param {String} position (optional) The {@link Roo.Element#alignTo} anchor position to use in aligning to
2214 * the element (defaults to this.defaultAlign)
2215 * @param {Roo.menu.Menu} parentMenu (optional) This menu's parent menu, if applicable (defaults to undefined)
2217 show : function(el, pos, parentMenu){
2218 this.parentMenu = parentMenu;
2222 this.fireEvent("beforeshow", this);
2223 this.showAt(this.el.getAlignToXY(el, pos || this.defaultAlign), parentMenu, false);
2226 * Displays this menu at a specific xy position
2227 * @param {Array} xyPosition Contains X & Y [x, y] values for the position at which to show the menu (coordinates are page-based)
2228 * @param {Roo.menu.Menu} parentMenu (optional) This menu's parent menu, if applicable (defaults to undefined)
2230 showAt : function(xy, parentMenu, /* private: */_e){
2231 this.parentMenu = parentMenu;
2236 this.fireEvent("beforeshow", this);
2237 //xy = this.el.adjustForConstraints(xy);
2241 this.hideMenuItems();
2242 this.hidden = false;
2243 this.triggerEl.addClass('open');
2245 // reassign x when hitting right
2246 if(this.el.getWidth() + xy[0] >= Roo.lib.Dom.getViewWidth()){
2247 xy[0] = xy[0] - this.el.getWidth() + this.triggerEl.getWidth();
2250 // reassign y when hitting bottom
2251 if(this.el.getHeight() + xy[1] >= Roo.lib.Dom.getViewHeight()){
2252 xy[1] = xy[1] - this.el.getHeight() - this.triggerEl.getHeight();
2255 // but the list may align on trigger left or trigger top... should it be a properity?
2257 if(this.el.getStyle('top') != 'auto' && this.el.getStyle('top').slice(-1) != "%"){
2262 this.fireEvent("show", this);
2268 this.doFocus.defer(50, this);
2272 doFocus : function(){
2274 this.focusEl.focus();
2279 * Hides this menu and optionally all parent menus
2280 * @param {Boolean} deep (optional) True to hide all parent menus recursively, if any (defaults to false)
2282 hide : function(deep)
2285 this.hideMenuItems();
2286 if(this.el && this.isVisible()){
2287 this.fireEvent("beforehide", this);
2288 if(this.activeItem){
2289 this.activeItem.deactivate();
2290 this.activeItem = null;
2292 this.triggerEl.removeClass('open');;
2294 this.fireEvent("hide", this);
2296 if(deep === true && this.parentMenu){
2297 this.parentMenu.hide(true);
2301 onTriggerClick : function(e)
2303 Roo.log('trigger click');
2305 var target = e.getTarget();
2307 Roo.log(target.nodeName.toLowerCase());
2309 if(target.nodeName.toLowerCase() === 'i'){
2315 onTriggerPress : function(e)
2317 Roo.log('trigger press');
2318 //Roo.log(e.getTarget());
2319 // Roo.log(this.triggerEl.dom);
2321 // trigger only occurs on normal menu's -- if it's a treeview or dropdown... do not hide/show..
2322 var pel = Roo.get(e.getTarget());
2323 if (pel.findParent('.dropdown-menu') || pel.findParent('.treeview-menu') ) {
2324 Roo.log('is treeview or dropdown?');
2328 if(e.getTarget().nodeName.toLowerCase() !== 'i' && this.isLink){
2332 if (this.isVisible()) {
2337 this.show(this.triggerEl, false, false);
2340 if(this.stopEvent || e.getTarget().nodeName.toLowerCase() === 'i'){
2347 hideMenuItems : function()
2349 Roo.log("hide Menu Items");
2353 //$(backdrop).remove()
2354 this.el.select('.open',true).each(function(aa) {
2356 aa.removeClass('open');
2357 //var parent = getParent($(this))
2358 //var relatedTarget = { relatedTarget: this }
2360 //$parent.trigger(e = $.Event('hide.bs.dropdown', relatedTarget))
2361 //if (e.isDefaultPrevented()) return
2362 //$parent.removeClass('open').trigger('hidden.bs.dropdown', relatedTarget)
2365 addxtypeChild : function (tree, cntr) {
2366 var comp= Roo.bootstrap.Menu.superclass.addxtypeChild.call(this, tree, cntr);
2368 this.menuitems.add(comp);
2380 this.getEl().dom.innerHTML = '';
2381 this.menuitems.clear();
2395 * @class Roo.bootstrap.MenuItem
2396 * @extends Roo.bootstrap.Component
2397 * Bootstrap MenuItem class
2398 * @cfg {String} html the menu label
2399 * @cfg {String} href the link
2400 * @cfg {Boolean} preventDefault do not trigger A href on clicks (default false).
2401 * @cfg {Boolean} isContainer is it a container - just returns a drop down item..
2402 * @cfg {Boolean} active used on sidebars to highlight active itesm
2403 * @cfg {String} fa favicon to show on left of menu item.
2404 * @cfg {Roo.bootsrap.Menu} menu the child menu.
2408 * Create a new MenuItem
2409 * @param {Object} config The config object
2413 Roo.bootstrap.MenuItem = function(config){
2414 Roo.bootstrap.MenuItem.superclass.constructor.call(this, config);
2419 * The raw click event for the entire grid.
2420 * @param {Roo.bootstrap.MenuItem} this
2421 * @param {Roo.EventObject} e
2427 Roo.extend(Roo.bootstrap.MenuItem, Roo.bootstrap.Component, {
2431 preventDefault: false,
2432 isContainer : false,
2436 getAutoCreate : function(){
2438 if(this.isContainer){
2441 cls: 'dropdown-menu-item'
2455 if (this.fa !== false) {
2458 cls : 'fa fa-' + this.fa
2467 cls: 'dropdown-menu-item',
2470 if (this.parent().type == 'treeview') {
2471 cfg.cls = 'treeview-menu';
2474 cfg.cls += ' active';
2479 anc.href = this.href || cfg.cn[0].href ;
2480 ctag.html = this.html || cfg.cn[0].html ;
2484 initEvents: function()
2486 if (this.parent().type == 'treeview') {
2487 this.el.select('a').on('click', this.onClick, this);
2491 this.menu.parentType = this.xtype;
2492 this.menu.triggerEl = this.el;
2493 this.menu = this.addxtype(Roo.apply({}, this.menu));
2497 onClick : function(e)
2499 Roo.log('item on click ');
2501 if(this.preventDefault){
2504 //this.parent().hideMenuItems();
2506 this.fireEvent('click', this, e);
2525 * @class Roo.bootstrap.MenuSeparator
2526 * @extends Roo.bootstrap.Component
2527 * Bootstrap MenuSeparator class
2530 * Create a new MenuItem
2531 * @param {Object} config The config object
2535 Roo.bootstrap.MenuSeparator = function(config){
2536 Roo.bootstrap.MenuSeparator.superclass.constructor.call(this, config);
2539 Roo.extend(Roo.bootstrap.MenuSeparator, Roo.bootstrap.Component, {
2541 getAutoCreate : function(){
2560 * @class Roo.bootstrap.Modal
2561 * @extends Roo.bootstrap.Component
2562 * Bootstrap Modal class
2563 * @cfg {String} title Title of dialog
2564 * @cfg {String} html - the body of the dialog (for simple ones) - you can also use template..
2565 * @cfg {Roo.Template} tmpl - a template with variables. to use it, add a handler in show:method adn
2566 * @cfg {Boolean} specificTitle default false
2567 * @cfg {Array} buttons Array of buttons or standard button set..
2568 * @cfg {String} buttonPosition (left|right|center) default right
2569 * @cfg {Boolean} animate default true
2570 * @cfg {Boolean} allow_close default true
2571 * @cfg {Boolean} fitwindow default false
2572 * @cfg {String} size (sm|lg) default empty
2573 * @cfg {Number} max_width set the max width of modal
2577 * Create a new Modal Dialog
2578 * @param {Object} config The config object
2581 Roo.bootstrap.Modal = function(config){
2582 Roo.bootstrap.Modal.superclass.constructor.call(this, config);
2587 * The raw btnclick event for the button
2588 * @param {Roo.EventObject} e
2593 * Fire when dialog resize
2594 * @param {Roo.bootstrap.Modal} this
2595 * @param {Roo.EventObject} e
2599 this.buttons = this.buttons || [];
2602 this.tmpl = Roo.factory(this.tmpl);
2607 Roo.extend(Roo.bootstrap.Modal, Roo.bootstrap.Component, {
2609 title : 'test dialog',
2619 specificTitle: false,
2621 buttonPosition: 'right',
2644 onRender : function(ct, position)
2646 Roo.bootstrap.Component.superclass.onRender.call(this, ct, position);
2649 var cfg = Roo.apply({}, this.getAutoCreate());
2652 // cfg.name = typeof(this.name) == 'undefined' ? this.id : this.name;
2654 //if (!cfg.name.length) {
2658 cfg.cls += ' ' + this.cls;
2661 cfg.style = this.style;
2663 this.el = Roo.get(document.body).createChild(cfg, position);
2665 //var type = this.el.dom.type;
2668 if(this.tabIndex !== undefined){
2669 this.el.dom.setAttribute('tabIndex', this.tabIndex);
2672 this.dialogEl = this.el.select('.modal-dialog',true).first();
2673 this.bodyEl = this.el.select('.modal-body',true).first();
2674 this.closeEl = this.el.select('.modal-header .close', true).first();
2675 this.headerEl = this.el.select('.modal-header',true).first();
2676 this.titleEl = this.el.select('.modal-title',true).first();
2677 this.footerEl = this.el.select('.modal-footer',true).first();
2679 this.maskEl = Roo.DomHelper.append(document.body, {tag: "div", cls:"x-dlg-mask"}, true);
2681 //this.el.addClass("x-dlg-modal");
2683 if (this.buttons.length) {
2684 Roo.each(this.buttons, function(bb) {
2685 var b = Roo.apply({}, bb);
2686 b.xns = b.xns || Roo.bootstrap;
2687 b.xtype = b.xtype || 'Button';
2688 if (typeof(b.listeners) == 'undefined') {
2689 b.listeners = { click : this.onButtonClick.createDelegate(this) };
2692 var btn = Roo.factory(b);
2694 btn.render(this.el.select('.modal-footer div').first());
2698 // render the children.
2701 if(typeof(this.items) != 'undefined'){
2702 var items = this.items;
2705 for(var i =0;i < items.length;i++) {
2706 nitems.push(this.addxtype(Roo.apply({}, items[i])));
2710 this.items = nitems;
2712 // where are these used - they used to be body/close/footer
2716 //this.el.addClass([this.fieldClass, this.cls]);
2720 getAutoCreate : function()
2724 html : this.html || ''
2729 cls : 'modal-title',
2733 if(this.specificTitle){
2739 if (this.allow_close) {
2751 if(this.size.length){
2752 size = 'modal-' + this.size;
2759 cls: "modal-dialog " + size,
2762 cls : "modal-content",
2765 cls : 'modal-header',
2770 cls : 'modal-footer',
2774 cls: 'btn-' + this.buttonPosition
2791 modal.cls += ' fade';
2797 getChildContainer : function() {
2802 getButtonContainer : function() {
2803 return this.el.select('.modal-footer div',true).first();
2806 initEvents : function()
2808 if (this.allow_close) {
2809 this.closeEl.on('click', this.hide, this);
2811 Roo.EventManager.onWindowResize(this.resize, this, true);
2818 this.maskEl.setSize(
2819 Roo.lib.Dom.getViewWidth(true),
2820 Roo.lib.Dom.getViewHeight(true)
2823 if (this.fitwindow) {
2825 this.width || Roo.lib.Dom.getViewportWidth(true) - 30,
2826 this.height || Roo.lib.Dom.getViewportHeight(true) - 60
2831 if(this.max_width !== 0) {
2833 var w = Math.min(this.max_width, Roo.lib.Dom.getViewportWidth(true) - 30);
2836 this.setSize(w, this.height);
2840 if(this.max_height) {
2841 this.setSize(w,Math.min(
2843 Roo.lib.Dom.getViewportHeight(true) - 60
2849 if(!this.fit_content) {
2850 this.setSize(w, Roo.lib.Dom.getViewportHeight(true) - 60);
2854 this.setSize(w, Math.min(
2856 this.headerEl.getHeight() +
2857 this.footerEl.getHeight() +
2858 this.getChildHeight(this.bodyEl.dom.childNodes),
2859 Roo.lib.Dom.getViewportHeight(true) - 60)
2865 setSize : function(w,h)
2876 if (!this.rendered) {
2880 //this.el.setStyle('display', 'block');
2881 this.el.removeClass('hideing');
2882 this.el.addClass('show');
2884 if(this.animate){ // element has 'fade' - so stuff happens after .3s ?- not sure why the delay?
2887 this.el.addClass('in');
2890 this.el.addClass('in');
2893 // not sure how we can show data in here..
2895 // this.getChildContainer().dom.innerHTML = this.tmpl.applyTemplate(this);
2898 Roo.get(document.body).addClass("x-body-masked");
2900 this.maskEl.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
2901 this.maskEl.setStyle('z-index', Roo.bootstrap.Modal.zIndex++);
2902 this.maskEl.addClass('show');
2906 this.fireEvent('show', this);
2908 // set zindex here - otherwise it appears to be ignored...
2909 this.el.setStyle('z-index', Roo.bootstrap.Modal.zIndex++);
2912 this.items.forEach( function(e) {
2913 e.layout ? e.layout() : false;
2921 if(this.fireEvent("beforehide", this) !== false){
2922 this.maskEl.removeClass('show');
2923 Roo.get(document.body).removeClass("x-body-masked");
2924 this.el.removeClass('in');
2925 this.el.select('.modal-dialog', true).first().setStyle('transform','');
2927 if(this.animate){ // why
2928 this.el.addClass('hideing');
2930 if (!this.el.hasClass('hideing')) {
2931 return; // it's been shown again...
2933 this.el.removeClass('show');
2934 this.el.removeClass('hideing');
2938 this.el.removeClass('show');
2940 this.fireEvent('hide', this);
2943 isVisible : function()
2946 return this.el.hasClass('show') && !this.el.hasClass('hideing');
2950 addButton : function(str, cb)
2954 var b = Roo.apply({}, { html : str } );
2955 b.xns = b.xns || Roo.bootstrap;
2956 b.xtype = b.xtype || 'Button';
2957 if (typeof(b.listeners) == 'undefined') {
2958 b.listeners = { click : cb.createDelegate(this) };
2961 var btn = Roo.factory(b);
2963 btn.render(this.el.select('.modal-footer div').first());
2969 setDefaultButton : function(btn)
2971 //this.el.select('.modal-footer').()
2975 resizeTo: function(w,h)
2979 this.dialogEl.setWidth(w);
2980 if (this.diff === false) {
2981 this.diff = this.dialogEl.getHeight() - this.bodyEl.getHeight();
2984 this.bodyEl.setHeight(h - this.diff);
2986 this.fireEvent('resize', this);
2989 setContentSize : function(w, h)
2993 onButtonClick: function(btn,e)
2996 this.fireEvent('btnclick', btn.name, e);
2999 * Set the title of the Dialog
3000 * @param {String} str new Title
3002 setTitle: function(str) {
3003 this.titleEl.dom.innerHTML = str;
3006 * Set the body of the Dialog
3007 * @param {String} str new Title
3009 setBody: function(str) {
3010 this.bodyEl.dom.innerHTML = str;
3013 * Set the body of the Dialog using the template
3014 * @param {Obj} data - apply this data to the template and replace the body contents.
3016 applyBody: function(obj)
3019 Roo.log("Error - using apply Body without a template");
3022 this.tmpl.overwrite(this.bodyEl, obj);
3025 getChildHeight : function(child_nodes)
3029 child_nodes.length == 0
3034 var child_height = 0;
3036 for(var i = 0; i < child_nodes.length; i++) {
3039 * for modal with tabs...
3040 if(child_nodes[i].classList.contains('roo-layout-panel')) {
3042 var layout_childs = child_nodes[i].childNodes;
3044 for(var j = 0; j < layout_childs.length; j++) {
3046 if(layout_childs[j].classList.contains('roo-layout-panel-body')) {
3048 var layout_body_childs = layout_childs[j].childNodes;
3050 for(var k = 0; k < layout_body_childs.length; k++) {
3052 if(layout_body_childs[k].classList.contains('navbar')) {
3053 child_height += layout_body_childs[k].offsetHeight;
3057 if(layout_body_childs[k].classList.contains('roo-layout-tabs-body')) {
3059 var layout_body_tab_childs = layout_body_childs[k].childNodes;
3061 for(var m = 0; m < layout_body_tab_childs.length; m++) {
3063 if(layout_body_tab_childs[m].classList.contains('roo-layout-active-content')) {
3064 child_height += this.getChildHeight(layout_body_tab_childs[m].childNodes);
3079 child_height += child_nodes[i].offsetHeight;
3080 // Roo.log(child_nodes[i].offsetHeight);
3083 return child_height;
3089 Roo.apply(Roo.bootstrap.Modal, {
3091 * Button config that displays a single OK button
3100 * Button config that displays Yes and No buttons
3116 * Button config that displays OK and Cancel buttons
3131 * Button config that displays Yes, No and Cancel buttons
3155 * messagebox - can be used as a replace
3159 * @class Roo.MessageBox
3160 * Utility class for generating different styles of message boxes. The alias Roo.Msg can also be used.
3164 Roo.Msg.alert('Status', 'Changes saved successfully.');
3166 // Prompt for user data:
3167 Roo.Msg.prompt('Name', 'Please enter your name:', function(btn, text){
3169 // process text value...
3173 // Show a dialog using config options:
3175 title:'Save Changes?',
3176 msg: 'Your are closing a tab that has unsaved changes. Would you like to save your changes?',
3177 buttons: Roo.Msg.YESNOCANCEL,
3184 Roo.bootstrap.MessageBox = function(){
3185 var dlg, opt, mask, waitTimer;
3186 var bodyEl, msgEl, textboxEl, textareaEl, progressEl, pp;
3187 var buttons, activeTextEl, bwidth;
3191 var handleButton = function(button){
3193 Roo.callback(opt.fn, opt.scope||window, [button, activeTextEl.dom.value], 1);
3197 var handleHide = function(){
3199 dlg.el.removeClass(opt.cls);
3202 // Roo.TaskMgr.stop(waitTimer);
3203 // waitTimer = null;
3208 var updateButtons = function(b){
3211 buttons["ok"].hide();
3212 buttons["cancel"].hide();
3213 buttons["yes"].hide();
3214 buttons["no"].hide();
3215 //dlg.footer.dom.style.display = 'none';
3218 dlg.footerEl.dom.style.display = '';
3219 for(var k in buttons){
3220 if(typeof buttons[k] != "function"){
3223 buttons[k].setText(typeof b[k] == "string" ? b[k] : Roo.bootstrap.MessageBox.buttonText[k]);
3224 width += buttons[k].el.getWidth()+15;
3234 var handleEsc = function(d, k, e){
3235 if(opt && opt.closable !== false){
3245 * Returns a reference to the underlying {@link Roo.BasicDialog} element
3246 * @return {Roo.BasicDialog} The BasicDialog element
3248 getDialog : function(){
3250 dlg = new Roo.bootstrap.Modal( {
3253 //constraintoviewport:false,
3255 //collapsible : false,
3260 //buttonAlign:"center",
3261 closeClick : function(){
3262 if(opt && opt.buttons && opt.buttons.no && !opt.buttons.cancel){
3265 handleButton("cancel");
3270 dlg.on("hide", handleHide);
3272 //dlg.addKeyListener(27, handleEsc);
3274 this.buttons = buttons;
3275 var bt = this.buttonText;
3276 buttons["ok"] = dlg.addButton(bt["ok"], handleButton.createCallback("ok"));
3277 buttons["yes"] = dlg.addButton(bt["yes"], handleButton.createCallback("yes"));
3278 buttons["no"] = dlg.addButton(bt["no"], handleButton.createCallback("no"));
3279 buttons["cancel"] = dlg.addButton(bt["cancel"], handleButton.createCallback("cancel"));
3281 bodyEl = dlg.bodyEl.createChild({
3283 html:'<span class="roo-mb-text"></span><br /><input type="text" class="roo-mb-input" />' +
3284 '<textarea class="roo-mb-textarea"></textarea>' +
3285 '<div class="roo-mb-progress-wrap"><div class="roo-mb-progress"><div class="roo-mb-progress-bar"> </div></div></div>'
3287 msgEl = bodyEl.dom.firstChild;
3288 textboxEl = Roo.get(bodyEl.dom.childNodes[2]);
3289 textboxEl.enableDisplayMode();
3290 textboxEl.addKeyListener([10,13], function(){
3291 if(dlg.isVisible() && opt && opt.buttons){
3294 }else if(opt.buttons.yes){
3295 handleButton("yes");
3299 textareaEl = Roo.get(bodyEl.dom.childNodes[3]);
3300 textareaEl.enableDisplayMode();
3301 progressEl = Roo.get(bodyEl.dom.childNodes[4]);
3302 progressEl.enableDisplayMode();
3304 // This is supposed to be the progessElement.. but I think it's controlling the height of everything..
3305 var pf = progressEl.dom.firstChild;
3307 pp = Roo.get(pf.firstChild);
3308 pp.setHeight(pf.offsetHeight);
3316 * Updates the message box body text
3317 * @param {String} text (optional) Replaces the message box element's innerHTML with the specified string (defaults to
3318 * the XHTML-compliant non-breaking space character '&#160;')
3319 * @return {Roo.MessageBox} This message box
3321 updateText : function(text)
3323 if(!dlg.isVisible() && !opt.width){
3324 dlg.dialogEl.setStyle({ 'max-width' : this.maxWidth});
3325 // dlg.resizeTo(this.maxWidth, 100); // forcing the height breaks long alerts()
3327 msgEl.innerHTML = text || ' ';
3329 var cw = Math.max(msgEl.offsetWidth, msgEl.parentNode.scrollWidth);
3330 //Roo.log("guesed size: " + JSON.stringify([cw,msgEl.offsetWidth, msgEl.parentNode.scrollWidth]));
3332 Math.min(opt.width || cw , this.maxWidth),
3333 Math.max(opt.minWidth || this.minWidth, bwidth)
3336 activeTextEl.setWidth(w);
3338 if(dlg.isVisible()){
3339 dlg.fixedcenter = false;
3341 // to big, make it scroll. = But as usual stupid IE does not support
3344 if ( bodyEl.getHeight() > (Roo.lib.Dom.getViewHeight() - 100)) {
3345 bodyEl.setHeight ( Roo.lib.Dom.getViewHeight() - 100 );
3346 bodyEl.dom.style.overflowY = 'auto' + ( Roo.isIE ? '' : ' !important');
3348 bodyEl.dom.style.height = '';
3349 bodyEl.dom.style.overflowY = '';
3352 bodyEl.dom.style.get = 'auto' + ( Roo.isIE ? '' : ' !important');
3354 bodyEl.dom.style.overflowX = '';
3357 dlg.setContentSize(w, bodyEl.getHeight());
3358 if(dlg.isVisible()){
3359 dlg.fixedcenter = true;
3365 * Updates a progress-style message box's text and progress bar. Only relevant on message boxes
3366 * initiated via {@link Roo.MessageBox#progress} or by calling {@link Roo.MessageBox#show} with progress: true.
3367 * @param {Number} value Any number between 0 and 1 (e.g., .5)
3368 * @param {String} text (optional) If defined, the message box's body text is replaced with the specified string (defaults to undefined)
3369 * @return {Roo.MessageBox} This message box
3371 updateProgress : function(value, text){
3373 this.updateText(text);
3376 if (pp) { // weird bug on my firefox - for some reason this is not defined
3377 pp.setWidth(Math.floor(value*progressEl.dom.firstChild.offsetWidth));
3378 pp.setHeight(Math.floor(progressEl.dom.firstChild.offsetHeight));
3384 * Returns true if the message box is currently displayed
3385 * @return {Boolean} True if the message box is visible, else false
3387 isVisible : function(){
3388 return dlg && dlg.isVisible();
3392 * Hides the message box if it is displayed
3395 if(this.isVisible()){
3401 * Displays a new message box, or reinitializes an existing message box, based on the config options
3402 * passed in. All functions (e.g. prompt, alert, etc) on MessageBox call this function internally.
3403 * The following config object properties are supported:
3405 Property Type Description
3406 ---------- --------------- ------------------------------------------------------------------------------------
3407 animEl String/Element An id or Element from which the message box should animate as it opens and
3408 closes (defaults to undefined)
3409 buttons Object/Boolean A button config object (e.g., Roo.MessageBox.OKCANCEL or {ok:'Foo',
3410 cancel:'Bar'}), or false to not show any buttons (defaults to false)
3411 closable Boolean False to hide the top-right close button (defaults to true). Note that
3412 progress and wait dialogs will ignore this property and always hide the
3413 close button as they can only be closed programmatically.
3414 cls String A custom CSS class to apply to the message box element
3415 defaultTextHeight Number The default height in pixels of the message box's multiline textarea if
3416 displayed (defaults to 75)
3417 fn Function A callback function to execute after closing the dialog. The arguments to the
3418 function will be btn (the name of the button that was clicked, if applicable,
3419 e.g. "ok"), and text (the value of the active text field, if applicable).
3420 Progress and wait dialogs will ignore this option since they do not respond to
3421 user actions and can only be closed programmatically, so any required function
3422 should be called by the same code after it closes the dialog.
3423 icon String A CSS class that provides a background image to be used as an icon for
3424 the dialog (e.g., Roo.MessageBox.WARNING or 'custom-class', defaults to '')
3425 maxWidth Number The maximum width in pixels of the message box (defaults to 600)
3426 minWidth Number The minimum width in pixels of the message box (defaults to 100)
3427 modal Boolean False to allow user interaction with the page while the message box is
3428 displayed (defaults to true)
3429 msg String A string that will replace the existing message box body text (defaults
3430 to the XHTML-compliant non-breaking space character ' ')
3431 multiline Boolean True to prompt the user to enter multi-line text (defaults to false)
3432 progress Boolean True to display a progress bar (defaults to false)
3433 progressText String The text to display inside the progress bar if progress = true (defaults to '')
3434 prompt Boolean True to prompt the user to enter single-line text (defaults to false)
3435 proxyDrag Boolean True to display a lightweight proxy while dragging (defaults to false)
3436 title String The title text
3437 value String The string value to set into the active textbox element if displayed
3438 wait Boolean True to display a progress bar (defaults to false)
3439 width Number The width of the dialog in pixels
3446 msg: 'Please enter your address:',
3448 buttons: Roo.MessageBox.OKCANCEL,
3451 animEl: 'addAddressBtn'
3454 * @param {Object} config Configuration options
3455 * @return {Roo.MessageBox} This message box
3457 show : function(options)
3460 // this causes nightmares if you show one dialog after another
3461 // especially on callbacks..
3463 if(this.isVisible()){
3466 Roo.log("[Roo.Messagebox] Show called while message displayed:" );
3467 Roo.log("Old Dialog Message:" + msgEl.innerHTML );
3468 Roo.log("New Dialog Message:" + options.msg )
3469 //this.alert("ERROR", "Multiple dialogs where displayed at the same time");
3470 //throw "Roo.MessageBox ERROR : Multiple dialogs where displayed at the same time";
3473 var d = this.getDialog();
3475 d.setTitle(opt.title || " ");
3476 d.closeEl.setDisplayed(opt.closable !== false);
3477 activeTextEl = textboxEl;
3478 opt.prompt = opt.prompt || (opt.multiline ? true : false);
3483 textareaEl.setHeight(typeof opt.multiline == "number" ?
3484 opt.multiline : this.defaultTextHeight);
3485 activeTextEl = textareaEl;
3494 progressEl.setDisplayed(opt.progress === true);
3495 this.updateProgress(0);
3496 activeTextEl.dom.value = opt.value || "";
3498 dlg.setDefaultButton(activeTextEl);
3500 var bs = opt.buttons;
3504 }else if(bs && bs.yes){
3505 db = buttons["yes"];
3507 dlg.setDefaultButton(db);
3509 bwidth = updateButtons(opt.buttons);
3510 this.updateText(opt.msg);
3512 d.el.addClass(opt.cls);
3514 d.proxyDrag = opt.proxyDrag === true;
3515 d.modal = opt.modal !== false;
3516 d.mask = opt.modal !== false ? mask : false;
3518 // force it to the end of the z-index stack so it gets a cursor in FF
3519 document.body.appendChild(dlg.el.dom);
3520 d.animateTarget = null;
3521 d.show(options.animEl);
3527 * Displays a message box with a progress bar. This message box has no buttons and is not closeable by
3528 * the user. You are responsible for updating the progress bar as needed via {@link Roo.MessageBox#updateProgress}
3529 * and closing the message box when the process is complete.
3530 * @param {String} title The title bar text
3531 * @param {String} msg The message box body text
3532 * @return {Roo.MessageBox} This message box
3534 progress : function(title, msg){
3541 minWidth: this.minProgressWidth,
3548 * Displays a standard read-only message box with an OK button (comparable to the basic JavaScript Window.alert).
3549 * If a callback function is passed it will be called after the user clicks the button, and the
3550 * id of the button that was clicked will be passed as the only parameter to the callback
3551 * (could also be the top-right close button).
3552 * @param {String} title The title bar text
3553 * @param {String} msg The message box body text
3554 * @param {Function} fn (optional) The callback function invoked after the message box is closed
3555 * @param {Object} scope (optional) The scope of the callback function
3556 * @return {Roo.MessageBox} This message box
3558 alert : function(title, msg, fn, scope)
3573 * Displays a message box with an infinitely auto-updating progress bar. This can be used to block user
3574 * interaction while waiting for a long-running process to complete that does not have defined intervals.
3575 * You are responsible for closing the message box when the process is complete.
3576 * @param {String} msg The message box body text
3577 * @param {String} title (optional) The title bar text
3578 * @return {Roo.MessageBox} This message box
3580 wait : function(msg, title){
3591 waitTimer = Roo.TaskMgr.start({
3593 Roo.MessageBox.updateProgress(((((i+20)%20)+1)*5)*.01);
3601 * Displays a confirmation message box with Yes and No buttons (comparable to JavaScript's Window.confirm).
3602 * If a callback function is passed it will be called after the user clicks either button, and the id of the
3603 * button that was clicked will be passed as the only parameter to the callback (could also be the top-right close button).
3604 * @param {String} title The title bar text
3605 * @param {String} msg The message box body text
3606 * @param {Function} fn (optional) The callback function invoked after the message box is closed
3607 * @param {Object} scope (optional) The scope of the callback function
3608 * @return {Roo.MessageBox} This message box
3610 confirm : function(title, msg, fn, scope){
3614 buttons: this.YESNO,
3623 * Displays a message box with OK and Cancel buttons prompting the user to enter some text (comparable to
3624 * JavaScript's Window.prompt). The prompt can be a single-line or multi-line textbox. If a callback function
3625 * is passed it will be called after the user clicks either button, and the id of the button that was clicked
3626 * (could also be the top-right close button) and the text that was entered will be passed as the two
3627 * parameters to the callback.
3628 * @param {String} title The title bar text
3629 * @param {String} msg The message box body text
3630 * @param {Function} fn (optional) The callback function invoked after the message box is closed
3631 * @param {Object} scope (optional) The scope of the callback function
3632 * @param {Boolean/Number} multiline (optional) True to create a multiline textbox using the defaultTextHeight
3633 * property, or the height in pixels to create the textbox (defaults to false / single-line)
3634 * @return {Roo.MessageBox} This message box
3636 prompt : function(title, msg, fn, scope, multiline){
3640 buttons: this.OKCANCEL,
3645 multiline: multiline,
3652 * Button config that displays a single OK button
3657 * Button config that displays Yes and No buttons
3660 YESNO : {yes:true, no:true},
3662 * Button config that displays OK and Cancel buttons
3665 OKCANCEL : {ok:true, cancel:true},
3667 * Button config that displays Yes, No and Cancel buttons
3670 YESNOCANCEL : {yes:true, no:true, cancel:true},
3673 * The default height in pixels of the message box's multiline textarea if displayed (defaults to 75)
3676 defaultTextHeight : 75,
3678 * The maximum width in pixels of the message box (defaults to 600)
3683 * The minimum width in pixels of the message box (defaults to 100)
3688 * The minimum width in pixels of the message box if it is a progress-style dialog. This is useful
3689 * for setting a different minimum width than text-only dialogs may need (defaults to 250)
3692 minProgressWidth : 250,
3694 * An object containing the default button text strings that can be overriden for localized language support.
3695 * Supported properties are: ok, cancel, yes and no.
3696 * Customize the default text like so: Roo.MessageBox.buttonText.yes = "S?";
3709 * Shorthand for {@link Roo.MessageBox}
3711 Roo.MessageBox = Roo.MessageBox || Roo.bootstrap.MessageBox;
3712 Roo.Msg = Roo.Msg || Roo.MessageBox;
3721 * @class Roo.bootstrap.Navbar
3722 * @extends Roo.bootstrap.Component
3723 * Bootstrap Navbar class
3726 * Create a new Navbar
3727 * @param {Object} config The config object
3731 Roo.bootstrap.Navbar = function(config){
3732 Roo.bootstrap.Navbar.superclass.constructor.call(this, config);
3736 * @event beforetoggle
3737 * Fire before toggle the menu
3738 * @param {Roo.EventObject} e
3740 "beforetoggle" : true
3744 Roo.extend(Roo.bootstrap.Navbar, Roo.bootstrap.Component, {
3753 getAutoCreate : function(){
3756 throw { message : "nav bar is now a abstract base class - use NavSimplebar / NavHeaderbar / NavSidebar etc..."};
3760 initEvents :function ()
3762 //Roo.log(this.el.select('.navbar-toggle',true));
3763 this.el.select('.navbar-toggle',true).on('click', function() {
3764 if(this.fireEvent('beforetoggle', this) !== false){
3765 this.el.select('.navbar-collapse',true).toggleClass('in');
3775 this.maskEl = Roo.DomHelper.append(this.el, mark, true);
3777 var size = this.el.getSize();
3778 this.maskEl.setSize(size.width, size.height);
3779 this.maskEl.enableDisplayMode("block");
3788 getChildContainer : function()
3790 if (this.el.select('.collapse').getCount()) {
3791 return this.el.select('.collapse',true).first();
3824 * @class Roo.bootstrap.NavSimplebar
3825 * @extends Roo.bootstrap.Navbar
3826 * Bootstrap Sidebar class
3828 * @cfg {Boolean} inverse is inverted color
3830 * @cfg {String} type (nav | pills | tabs)
3831 * @cfg {Boolean} arrangement stacked | justified
3832 * @cfg {String} align (left | right) alignment
3834 * @cfg {Boolean} main (true|false) main nav bar? default false
3835 * @cfg {Boolean} loadMask (true|false) loadMask on the bar
3837 * @cfg {String} tag (header|footer|nav|div) default is nav
3843 * Create a new Sidebar
3844 * @param {Object} config The config object
3848 Roo.bootstrap.NavSimplebar = function(config){
3849 Roo.bootstrap.NavSimplebar.superclass.constructor.call(this, config);
3852 Roo.extend(Roo.bootstrap.NavSimplebar, Roo.bootstrap.Navbar, {
3868 getAutoCreate : function(){
3872 tag : this.tag || 'div',
3885 this.type = this.type || 'nav';
3886 if (['tabs','pills'].indexOf(this.type)!==-1) {
3887 cfg.cn[0].cls += ' nav-' + this.type
3891 if (this.type!=='nav') {
3892 Roo.log('nav type must be nav/tabs/pills')
3894 cfg.cn[0].cls += ' navbar-nav'
3900 if (['stacked','justified'].indexOf(this.arrangement)!==-1) {
3901 cfg.cn[0].cls += ' nav-' + this.arrangement;
3905 if (this.align === 'right') {
3906 cfg.cn[0].cls += ' navbar-right';
3910 cfg.cls += ' navbar-inverse';
3937 * @class Roo.bootstrap.NavHeaderbar
3938 * @extends Roo.bootstrap.NavSimplebar
3939 * Bootstrap Sidebar class
3941 * @cfg {String} brand what is brand
3942 * @cfg {String} position (fixed-top|fixed-bottom|static-top) position
3943 * @cfg {String} brand_href href of the brand
3944 * @cfg {Boolean} srButton generate the (screen reader / mobile) sr-only button default true
3945 * @cfg {Boolean} autohide a top nav bar header that hides on scroll.
3946 * @cfg {Boolean} desktopCenter should the header be centered on desktop using a container class
3947 * @cfg {Roo.bootstrap.Row} mobilerow - a row to display on mobile only..
3950 * Create a new Sidebar
3951 * @param {Object} config The config object
3955 Roo.bootstrap.NavHeaderbar = function(config){
3956 Roo.bootstrap.NavHeaderbar.superclass.constructor.call(this, config);
3960 Roo.extend(Roo.bootstrap.NavHeaderbar, Roo.bootstrap.NavSimplebar, {
3967 desktopCenter : false,
3970 getAutoCreate : function(){
3973 tag: this.nav || 'nav',
3980 if (this.desktopCenter) {
3981 cn.push({cls : 'container', cn : []});
3988 cls: 'navbar-header',
3993 cls: 'navbar-toggle',
3994 'data-toggle': 'collapse',
3999 html: 'Toggle navigation'
4021 cls: 'collapse navbar-collapse',
4025 cfg.cls += this.inverse ? ' navbar-inverse' : ' navbar-default';
4027 if (['fixed-top','fixed-bottom','static-top'].indexOf(this.position)>-1) {
4028 cfg.cls += ' navbar-' + this.position;
4030 // tag can override this..
4032 cfg.tag = this.tag || (this.position == 'fixed-bottom' ? 'footer' : 'header');
4035 if (this.brand !== '') {
4038 href: this.brand_href ? this.brand_href : '#',
4039 cls: 'navbar-brand',
4047 cfg.cls += ' main-nav';
4055 getHeaderChildContainer : function()
4057 if (this.srButton && this.el.select('.navbar-header').getCount()) {
4058 return this.el.select('.navbar-header',true).first();
4061 return this.getChildContainer();
4065 initEvents : function()
4067 Roo.bootstrap.NavHeaderbar.superclass.initEvents.call(this);
4069 if (this.autohide) {
4074 Roo.get(document).on('scroll',function(e) {
4075 var ns = Roo.get(document).getScroll().top;
4076 var os = prevScroll;
4080 ft.removeClass('slideDown');
4081 ft.addClass('slideUp');
4084 ft.removeClass('slideUp');
4085 ft.addClass('slideDown');
4106 * @class Roo.bootstrap.NavSidebar
4107 * @extends Roo.bootstrap.Navbar
4108 * Bootstrap Sidebar class
4111 * Create a new Sidebar
4112 * @param {Object} config The config object
4116 Roo.bootstrap.NavSidebar = function(config){
4117 Roo.bootstrap.NavSidebar.superclass.constructor.call(this, config);
4120 Roo.extend(Roo.bootstrap.NavSidebar, Roo.bootstrap.Navbar, {
4122 sidebar : true, // used by Navbar Item and NavbarGroup at present...
4124 getAutoCreate : function(){
4129 cls: 'sidebar sidebar-nav'
4151 * @class Roo.bootstrap.NavGroup
4152 * @extends Roo.bootstrap.Component
4153 * Bootstrap NavGroup class
4154 * @cfg {String} align (left|right)
4155 * @cfg {Boolean} inverse
4156 * @cfg {String} type (nav|pills|tab) default nav
4157 * @cfg {String} navId - reference Id for navbar.
4161 * Create a new nav group
4162 * @param {Object} config The config object
4165 Roo.bootstrap.NavGroup = function(config){
4166 Roo.bootstrap.NavGroup.superclass.constructor.call(this, config);
4169 Roo.bootstrap.NavGroup.register(this);
4173 * Fires when the active item changes
4174 * @param {Roo.bootstrap.NavGroup} this
4175 * @param {Roo.bootstrap.Navbar.Item} selected The item selected
4176 * @param {Roo.bootstrap.Navbar.Item} prev The previously selected item
4183 Roo.extend(Roo.bootstrap.NavGroup, Roo.bootstrap.Component, {
4194 getAutoCreate : function()
4196 var cfg = Roo.apply({}, Roo.bootstrap.NavGroup.superclass.getAutoCreate.call(this));
4203 if (['tabs','pills'].indexOf(this.type)!==-1) {
4204 cfg.cls += ' nav-' + this.type
4206 if (this.type!=='nav') {
4207 Roo.log('nav type must be nav/tabs/pills')
4209 cfg.cls += ' navbar-nav'
4212 if (this.parent() && this.parent().sidebar) {
4215 cls: 'dashboard-menu sidebar-menu'
4221 if (this.form === true) {
4227 if (this.align === 'right') {
4228 cfg.cls += ' navbar-right';
4230 cfg.cls += ' navbar-left';
4234 if (this.align === 'right') {
4235 cfg.cls += ' navbar-right';
4239 cfg.cls += ' navbar-inverse';
4247 * sets the active Navigation item
4248 * @param {Roo.bootstrap.NavItem} the new current navitem
4250 setActiveItem : function(item)
4253 Roo.each(this.navItems, function(v){
4258 v.setActive(false, true);
4265 item.setActive(true, true);
4266 this.fireEvent('changed', this, item, prev);
4271 * gets the active Navigation item
4272 * @return {Roo.bootstrap.NavItem} the current navitem
4274 getActive : function()
4278 Roo.each(this.navItems, function(v){
4289 indexOfNav : function()
4293 Roo.each(this.navItems, function(v,i){
4304 * adds a Navigation item
4305 * @param {Roo.bootstrap.NavItem} the navitem to add
4307 addItem : function(cfg)
4309 var cn = new Roo.bootstrap.NavItem(cfg);
4311 cn.parentId = this.id;
4312 cn.onRender(this.el, null);
4316 * register a Navigation item
4317 * @param {Roo.bootstrap.NavItem} the navitem to add
4319 register : function(item)
4321 this.navItems.push( item);
4322 item.navId = this.navId;
4327 * clear all the Navigation item
4330 clearAll : function()
4333 this.el.dom.innerHTML = '';
4336 getNavItem: function(tabId)
4339 Roo.each(this.navItems, function(e) {
4340 if (e.tabId == tabId) {
4350 setActiveNext : function()
4352 var i = this.indexOfNav(this.getActive());
4353 if (i > this.navItems.length) {
4356 this.setActiveItem(this.navItems[i+1]);
4358 setActivePrev : function()
4360 var i = this.indexOfNav(this.getActive());
4364 this.setActiveItem(this.navItems[i-1]);
4366 clearWasActive : function(except) {
4367 Roo.each(this.navItems, function(e) {
4368 if (e.tabId != except.tabId && e.was_active) {
4369 e.was_active = false;
4376 getWasActive : function ()
4379 Roo.each(this.navItems, function(e) {
4394 Roo.apply(Roo.bootstrap.NavGroup, {
4398 * register a Navigation Group
4399 * @param {Roo.bootstrap.NavGroup} the navgroup to add
4401 register : function(navgrp)
4403 this.groups[navgrp.navId] = navgrp;
4407 * fetch a Navigation Group based on the navigation ID
4408 * @param {string} the navgroup to add
4409 * @returns {Roo.bootstrap.NavGroup} the navgroup
4411 get: function(navId) {
4412 if (typeof(this.groups[navId]) == 'undefined') {
4414 //this.register(new Roo.bootstrap.NavGroup({ navId : navId }));
4416 return this.groups[navId] ;
4431 * @class Roo.bootstrap.NavItem
4432 * @extends Roo.bootstrap.Component
4433 * Bootstrap Navbar.NavItem class
4434 * @cfg {String} href link to
4435 * @cfg {String} html content of button
4436 * @cfg {String} badge text inside badge
4437 * @cfg {String} badgecls (bg-green|bg-red|bg-yellow)the extra classes for the badge
4438 * @cfg {String} glyphicon name of glyphicon
4439 * @cfg {String} icon name of font awesome icon
4440 * @cfg {Boolean} active Is item active
4441 * @cfg {Boolean} disabled Is item disabled
4443 * @cfg {Boolean} preventDefault (true | false) default false
4444 * @cfg {String} tabId the tab that this item activates.
4445 * @cfg {String} tagtype (a|span) render as a href or span?
4446 * @cfg {Boolean} animateRef (true|false) link to element default false
4449 * Create a new Navbar Item
4450 * @param {Object} config The config object
4452 Roo.bootstrap.NavItem = function(config){
4453 Roo.bootstrap.NavItem.superclass.constructor.call(this, config);
4458 * The raw click event for the entire grid.
4459 * @param {Roo.EventObject} e
4464 * Fires when the active item active state changes
4465 * @param {Roo.bootstrap.NavItem} this
4466 * @param {boolean} state the new state
4472 * Fires when scroll to element
4473 * @param {Roo.bootstrap.NavItem} this
4474 * @param {Object} options
4475 * @param {Roo.EventObject} e
4483 Roo.extend(Roo.bootstrap.NavItem, Roo.bootstrap.Component, {
4491 preventDefault : false,
4498 getAutoCreate : function(){
4507 cfg.cls = typeof(cfg.cls) == 'undefined' ? 'active' : cfg.cls + ' active';
4509 if (this.disabled) {
4510 cfg.cls += ' disabled';
4513 if (this.href || this.html || this.glyphicon || this.icon) {
4517 href : this.href || "#",
4518 html: this.html || ''
4523 cfg.cn[0].html = '<i class="'+this.icon+'"></i> <span>' + cfg.cn[0].html + '</span>'
4526 if(this.glyphicon) {
4527 cfg.cn[0].html = '<span class="glyphicon glyphicon-' + this.glyphicon + '"></span> ' + cfg.cn[0].html;
4532 cfg.cn[0].html += " <span class='caret'></span>";
4536 if (this.badge !== '') {
4538 cfg.cn[0].html += ' <span class="badge">' + this.badge + '</span>';
4546 initEvents: function()
4548 if (typeof (this.menu) != 'undefined') {
4549 this.menu.parentType = this.xtype;
4550 this.menu.triggerEl = this.el;
4551 this.menu = this.addxtype(Roo.apply({}, this.menu));
4554 this.el.select('a',true).on('click', this.onClick, this);
4556 if(this.tagtype == 'span'){
4557 this.el.select('span',true).on('click', this.onClick, this);
4560 // at this point parent should be available..
4561 this.parent().register(this);
4564 onClick : function(e)
4566 if (e.getTarget('.dropdown-menu-item')) {
4567 // did you click on a menu itemm.... - then don't trigger onclick..
4572 this.preventDefault ||
4575 Roo.log("NavItem - prevent Default?");
4579 if (this.disabled) {
4583 var tg = Roo.bootstrap.TabGroup.get(this.navId);
4584 if (tg && tg.transition) {
4585 Roo.log("waiting for the transitionend");
4591 //Roo.log("fire event clicked");
4592 if(this.fireEvent('click', this, e) === false){
4596 if(this.tagtype == 'span'){
4600 //Roo.log(this.href);
4601 var ael = this.el.select('a',true).first();
4604 if(ael && this.animateRef && this.href.indexOf('#') > -1){
4605 //Roo.log(["test:",ael.dom.href.split("#")[0], document.location.toString().split("#")[0]]);
4606 if (ael.dom.href.split("#")[0] != document.location.toString().split("#")[0]) {
4607 return; // ignore... - it's a 'hash' to another page.
4609 Roo.log("NavItem - prevent Default?");
4611 this.scrollToElement(e);
4615 var p = this.parent();
4617 if (['tabs','pills'].indexOf(p.type)!==-1) {
4618 if (typeof(p.setActiveItem) !== 'undefined') {
4619 p.setActiveItem(this);
4623 // if parent is a navbarheader....- and link is probably a '#' page ref.. then remove the expanded menu.
4624 if (p.parentType == 'NavHeaderbar' && !this.menu) {
4625 // remove the collapsed menu expand...
4626 p.parent().el.select('.navbar-collapse',true).removeClass('in');
4630 isActive: function () {
4633 setActive : function(state, fire, is_was_active)
4635 if (this.active && !state && this.navId) {
4636 this.was_active = true;
4637 var nv = Roo.bootstrap.NavGroup.get(this.navId);
4639 nv.clearWasActive(this);
4643 this.active = state;
4646 this.el.removeClass('active');
4647 } else if (!this.el.hasClass('active')) {
4648 this.el.addClass('active');
4651 this.fireEvent('changed', this, state);
4654 // show a panel if it's registered and related..
4656 if (!this.navId || !this.tabId || !state || is_was_active) {
4660 var tg = Roo.bootstrap.TabGroup.get(this.navId);
4664 var pan = tg.getPanelByName(this.tabId);
4668 // if we can not flip to new panel - go back to old nav highlight..
4669 if (false == tg.showPanel(pan)) {
4670 var nv = Roo.bootstrap.NavGroup.get(this.navId);
4672 var onav = nv.getWasActive();
4674 onav.setActive(true, false, true);
4683 // this should not be here...
4684 setDisabled : function(state)
4686 this.disabled = state;
4688 this.el.removeClass('disabled');
4689 } else if (!this.el.hasClass('disabled')) {
4690 this.el.addClass('disabled');
4696 * Fetch the element to display the tooltip on.
4697 * @return {Roo.Element} defaults to this.el
4699 tooltipEl : function()
4701 return this.el.select('' + this.tagtype + '', true).first();
4704 scrollToElement : function(e)
4706 var c = document.body;
4709 * Firefox / IE places the overflow at the html level, unless specifically styled to behave differently.
4711 if(Roo.isFirefox || Roo.isIE || Roo.isIE11){
4712 c = document.documentElement;
4715 var target = Roo.get(c).select('a[name=' + this.href.split('#')[1] +']', true).first();
4721 var o = target.calcOffsetsTo(c);
4728 this.fireEvent('scrollto', this, options, e);
4730 Roo.get(c).scrollTo('top', options.value, true);
4743 * <span> icon </span>
4744 * <span> text </span>
4745 * <span>badge </span>
4749 * @class Roo.bootstrap.NavSidebarItem
4750 * @extends Roo.bootstrap.NavItem
4751 * Bootstrap Navbar.NavSidebarItem class
4752 * {String} badgeWeight (default|primary|success|info|warning|danger)the extra classes for the badge
4753 * {Boolean} open is the menu open
4754 * {Boolean} buttonView use button as the tigger el rather that a (default false)
4755 * {String} buttonWeight (default|primary|success|info|warning|danger)the extra classes for the button
4756 * {String} buttonSize (sm|md|lg)the extra classes for the button
4757 * {Boolean} showArrow show arrow next to the text (default true)
4759 * Create a new Navbar Button
4760 * @param {Object} config The config object
4762 Roo.bootstrap.NavSidebarItem = function(config){
4763 Roo.bootstrap.NavSidebarItem.superclass.constructor.call(this, config);
4768 * The raw click event for the entire grid.
4769 * @param {Roo.EventObject} e
4774 * Fires when the active item active state changes
4775 * @param {Roo.bootstrap.NavSidebarItem} this
4776 * @param {boolean} state the new state
4784 Roo.extend(Roo.bootstrap.NavSidebarItem, Roo.bootstrap.NavItem, {
4786 badgeWeight : 'default',
4792 buttonWeight : 'default',
4798 getAutoCreate : function(){
4803 href : this.href || '#',
4809 if(this.buttonView){
4812 href : this.href || '#',
4813 cls: 'btn btn-' + this.buttonWeight + ' btn-' + this.buttonSize + 'roo-button-dropdown-toggle',
4826 cfg.cls += ' active';
4829 if (this.disabled) {
4830 cfg.cls += ' disabled';
4833 cfg.cls += ' open x-open';
4836 if (this.glyphicon || this.icon) {
4837 var c = this.glyphicon ? ('glyphicon glyphicon-'+this.glyphicon) : this.icon;
4838 a.cn.push({ tag : 'i', cls : c }) ;
4841 if(!this.buttonView){
4844 html : this.html || ''
4851 if (this.badge !== '') {
4852 a.cn.push({ tag: 'span', cls : 'badge pull-right badge-' + this.badgeWeight, html: this.badge });
4858 a.cn.push({ tag : 'i', cls : 'glyphicon glyphicon-chevron-down pull-right'});
4861 a.cls += ' dropdown-toggle treeview' ;
4867 initEvents : function()
4869 if (typeof (this.menu) != 'undefined') {
4870 this.menu.parentType = this.xtype;
4871 this.menu.triggerEl = this.el;
4872 this.menu = this.addxtype(Roo.apply({}, this.menu));
4875 this.el.on('click', this.onClick, this);
4877 if(this.badge !== ''){
4878 this.badgeEl = this.el.select('.badge', true).first().setVisibilityMode(Roo.Element.DISPLAY);
4883 onClick : function(e)
4890 if(this.preventDefault){
4894 this.fireEvent('click', this);
4897 disable : function()
4899 this.setDisabled(true);
4904 this.setDisabled(false);
4907 setDisabled : function(state)
4909 if(this.disabled == state){
4913 this.disabled = state;
4916 this.el.addClass('disabled');
4920 this.el.removeClass('disabled');
4925 setActive : function(state)
4927 if(this.active == state){
4931 this.active = state;
4934 this.el.addClass('active');
4938 this.el.removeClass('active');
4943 isActive: function ()
4948 setBadge : function(str)
4954 this.badgeEl.dom.innerHTML = str;
4971 * @class Roo.bootstrap.Row
4972 * @extends Roo.bootstrap.Component
4973 * Bootstrap Row class (contains columns...)
4977 * @param {Object} config The config object
4980 Roo.bootstrap.Row = function(config){
4981 Roo.bootstrap.Row.superclass.constructor.call(this, config);
4984 Roo.extend(Roo.bootstrap.Row, Roo.bootstrap.Component, {
4986 getAutoCreate : function(){
5005 * @class Roo.bootstrap.Element
5006 * @extends Roo.bootstrap.Component
5007 * Bootstrap Element class
5008 * @cfg {String} html contents of the element
5009 * @cfg {String} tag tag of the element
5010 * @cfg {String} cls class of the element
5011 * @cfg {Boolean} preventDefault (true|false) default false
5012 * @cfg {Boolean} clickable (true|false) default false
5015 * Create a new Element
5016 * @param {Object} config The config object
5019 Roo.bootstrap.Element = function(config){
5020 Roo.bootstrap.Element.superclass.constructor.call(this, config);
5026 * When a element is chick
5027 * @param {Roo.bootstrap.Element} this
5028 * @param {Roo.EventObject} e
5034 Roo.extend(Roo.bootstrap.Element, Roo.bootstrap.Component, {
5039 preventDefault: false,
5042 getAutoCreate : function(){
5046 // cls: this.cls, double assign in parent class Component.js :: onRender
5053 initEvents: function()
5055 Roo.bootstrap.Element.superclass.initEvents.call(this);
5058 this.el.on('click', this.onClick, this);
5063 onClick : function(e)
5065 if(this.preventDefault){
5069 this.fireEvent('click', this, e);
5072 getValue : function()
5074 return this.el.dom.innerHTML;
5077 setValue : function(value)
5079 this.el.dom.innerHTML = value;
5094 * @class Roo.bootstrap.Pagination
5095 * @extends Roo.bootstrap.Component
5096 * Bootstrap Pagination class
5097 * @cfg {String} size xs | sm | md | lg
5098 * @cfg {Boolean} inverse false | true
5101 * Create a new Pagination
5102 * @param {Object} config The config object
5105 Roo.bootstrap.Pagination = function(config){
5106 Roo.bootstrap.Pagination.superclass.constructor.call(this, config);
5109 Roo.extend(Roo.bootstrap.Pagination, Roo.bootstrap.Component, {
5115 getAutoCreate : function(){
5121 cfg.cls += ' inverse';
5127 cfg.cls += " " + this.cls;
5145 * @class Roo.bootstrap.PaginationItem
5146 * @extends Roo.bootstrap.Component
5147 * Bootstrap PaginationItem class
5148 * @cfg {String} html text
5149 * @cfg {String} href the link
5150 * @cfg {Boolean} preventDefault (true | false) default true
5151 * @cfg {Boolean} active (true | false) default false
5152 * @cfg {Boolean} disabled default false
5156 * Create a new PaginationItem
5157 * @param {Object} config The config object
5161 Roo.bootstrap.PaginationItem = function(config){
5162 Roo.bootstrap.PaginationItem.superclass.constructor.call(this, config);
5167 * The raw click event for the entire grid.
5168 * @param {Roo.EventObject} e
5174 Roo.extend(Roo.bootstrap.PaginationItem, Roo.bootstrap.Component, {
5178 preventDefault: true,
5183 getAutoCreate : function(){
5189 href : this.href ? this.href : '#',
5190 html : this.html ? this.html : ''
5200 cfg.cls = typeof(cfg.cls) !== 'undefined' ? cfg.cls + ' disabled' : 'disabled';
5204 cfg.cls = typeof(cfg.cls) !== 'undefined' ? cfg.cls + ' active' : 'active';
5210 initEvents: function() {
5212 this.el.on('click', this.onClick, this);
5215 onClick : function(e)
5217 Roo.log('PaginationItem on click ');
5218 if(this.preventDefault){
5226 this.fireEvent('click', this, e);
5242 * @class Roo.bootstrap.Slider
5243 * @extends Roo.bootstrap.Component
5244 * Bootstrap Slider class
5247 * Create a new Slider
5248 * @param {Object} config The config object
5251 Roo.bootstrap.Slider = function(config){
5252 Roo.bootstrap.Slider.superclass.constructor.call(this, config);
5255 Roo.extend(Roo.bootstrap.Slider, Roo.bootstrap.Component, {
5257 getAutoCreate : function(){
5261 cls: 'slider slider-sample1 vertical-handler ui-slider ui-slider-horizontal ui-widget ui-widget-content ui-corner-all',
5265 cls: 'ui-slider-handle ui-state-default ui-corner-all'
5277 * Ext JS Library 1.1.1
5278 * Copyright(c) 2006-2007, Ext JS, LLC.
5280 * Originally Released Under LGPL - original licence link has changed is not relivant.
5283 * <script type="text/javascript">
5288 * @class Roo.grid.ColumnModel
5289 * @extends Roo.util.Observable
5290 * This is the default implementation of a ColumnModel used by the Grid. It defines
5291 * the columns in the grid.
5294 var colModel = new Roo.grid.ColumnModel([
5295 {header: "Ticker", width: 60, sortable: true, locked: true},
5296 {header: "Company Name", width: 150, sortable: true},
5297 {header: "Market Cap.", width: 100, sortable: true},
5298 {header: "$ Sales", width: 100, sortable: true, renderer: money},
5299 {header: "Employees", width: 100, sortable: true, resizable: false}
5304 * The config options listed for this class are options which may appear in each
5305 * individual column definition.
5306 * <br/>RooJS Fix - column id's are not sequential but use Roo.id() - fixes bugs with layouts.
5308 * @param {Object} config An Array of column config objects. See this class's
5309 * config objects for details.
5311 Roo.grid.ColumnModel = function(config){
5313 * The config passed into the constructor
5315 this.config = config;
5318 // if no id, create one
5319 // if the column does not have a dataIndex mapping,
5320 // map it to the order it is in the config
5321 for(var i = 0, len = config.length; i < len; i++){
5323 if(typeof c.dataIndex == "undefined"){
5326 if(typeof c.renderer == "string"){
5327 c.renderer = Roo.util.Format[c.renderer];
5329 if(typeof c.id == "undefined"){
5332 if(c.editor && c.editor.xtype){
5333 c.editor = Roo.factory(c.editor, Roo.grid);
5335 if(c.editor && c.editor.isFormField){
5336 c.editor = new Roo.grid.GridEditor(c.editor);
5338 this.lookup[c.id] = c;
5342 * The width of columns which have no width specified (defaults to 100)
5345 this.defaultWidth = 100;
5348 * Default sortable of columns which have no sortable specified (defaults to false)
5351 this.defaultSortable = false;
5355 * @event widthchange
5356 * Fires when the width of a column changes.
5357 * @param {ColumnModel} this
5358 * @param {Number} columnIndex The column index
5359 * @param {Number} newWidth The new width
5361 "widthchange": true,
5363 * @event headerchange
5364 * Fires when the text of a header changes.
5365 * @param {ColumnModel} this
5366 * @param {Number} columnIndex The column index
5367 * @param {Number} newText The new header text
5369 "headerchange": true,
5371 * @event hiddenchange
5372 * Fires when a column is hidden or "unhidden".
5373 * @param {ColumnModel} this
5374 * @param {Number} columnIndex The column index
5375 * @param {Boolean} hidden true if hidden, false otherwise
5377 "hiddenchange": true,
5379 * @event columnmoved
5380 * Fires when a column is moved.
5381 * @param {ColumnModel} this
5382 * @param {Number} oldIndex
5383 * @param {Number} newIndex
5385 "columnmoved" : true,
5387 * @event columlockchange
5388 * Fires when a column's locked state is changed
5389 * @param {ColumnModel} this
5390 * @param {Number} colIndex
5391 * @param {Boolean} locked true if locked
5393 "columnlockchange" : true
5395 Roo.grid.ColumnModel.superclass.constructor.call(this);
5397 Roo.extend(Roo.grid.ColumnModel, Roo.util.Observable, {
5399 * @cfg {String} header The header text to display in the Grid view.
5402 * @cfg {String} dataIndex (Optional) The name of the field in the grid's {@link Roo.data.Store}'s
5403 * {@link Roo.data.Record} definition from which to draw the column's value. If not
5404 * specified, the column's index is used as an index into the Record's data Array.
5407 * @cfg {Number} width (Optional) The initial width in pixels of the column. Using this
5408 * instead of {@link Roo.grid.Grid#autoSizeColumns} is more efficient.
5411 * @cfg {Boolean} sortable (Optional) True if sorting is to be allowed on this column.
5412 * Defaults to the value of the {@link #defaultSortable} property.
5413 * Whether local/remote sorting is used is specified in {@link Roo.data.Store#remoteSort}.
5416 * @cfg {Boolean} locked (Optional) True to lock the column in place while scrolling the Grid. Defaults to false.
5419 * @cfg {Boolean} fixed (Optional) True if the column width cannot be changed. Defaults to false.
5422 * @cfg {Boolean} resizable (Optional) False to disable column resizing. Defaults to true.
5425 * @cfg {Boolean} hidden (Optional) True to hide the column. Defaults to false.
5428 * @cfg {Function} renderer (Optional) A function used to generate HTML markup for a cell
5429 * given the cell's data value. See {@link #setRenderer}. If not specified, the
5430 * default renderer returns the escaped data value. If an object is returned (bootstrap only)
5431 * then it is treated as a Roo Component object instance, and it is rendered after the initial row is rendered
5434 * @cfg {Roo.grid.GridEditor} editor (Optional) For grid editors - returns the grid editor
5437 * @cfg {String} align (Optional) Set the CSS text-align property of the column. Defaults to undefined.
5440 * @cfg {String} valign (Optional) Set the CSS vertical-align property of the column (eg. middle, top, bottom etc). Defaults to undefined.
5443 * @cfg {String} cursor (Optional)
5446 * @cfg {String} tooltip (Optional)
5449 * @cfg {Number} xs (Optional)
5452 * @cfg {Number} sm (Optional)
5455 * @cfg {Number} md (Optional)
5458 * @cfg {Number} lg (Optional)
5461 * Returns the id of the column at the specified index.
5462 * @param {Number} index The column index
5463 * @return {String} the id
5465 getColumnId : function(index){
5466 return this.config[index].id;
5470 * Returns the column for a specified id.
5471 * @param {String} id The column id
5472 * @return {Object} the column
5474 getColumnById : function(id){
5475 return this.lookup[id];
5480 * Returns the column for a specified dataIndex.
5481 * @param {String} dataIndex The column dataIndex
5482 * @return {Object|Boolean} the column or false if not found
5484 getColumnByDataIndex: function(dataIndex){
5485 var index = this.findColumnIndex(dataIndex);
5486 return index > -1 ? this.config[index] : false;
5490 * Returns the index for a specified column id.
5491 * @param {String} id The column id
5492 * @return {Number} the index, or -1 if not found
5494 getIndexById : function(id){
5495 for(var i = 0, len = this.config.length; i < len; i++){
5496 if(this.config[i].id == id){
5504 * Returns the index for a specified column dataIndex.
5505 * @param {String} dataIndex The column dataIndex
5506 * @return {Number} the index, or -1 if not found
5509 findColumnIndex : function(dataIndex){
5510 for(var i = 0, len = this.config.length; i < len; i++){
5511 if(this.config[i].dataIndex == dataIndex){
5519 moveColumn : function(oldIndex, newIndex){
5520 var c = this.config[oldIndex];
5521 this.config.splice(oldIndex, 1);
5522 this.config.splice(newIndex, 0, c);
5523 this.dataMap = null;
5524 this.fireEvent("columnmoved", this, oldIndex, newIndex);
5527 isLocked : function(colIndex){
5528 return this.config[colIndex].locked === true;
5531 setLocked : function(colIndex, value, suppressEvent){
5532 if(this.isLocked(colIndex) == value){
5535 this.config[colIndex].locked = value;
5537 this.fireEvent("columnlockchange", this, colIndex, value);
5541 getTotalLockedWidth : function(){
5543 for(var i = 0; i < this.config.length; i++){
5544 if(this.isLocked(i) && !this.isHidden(i)){
5545 this.totalWidth += this.getColumnWidth(i);
5551 getLockedCount : function(){
5552 for(var i = 0, len = this.config.length; i < len; i++){
5553 if(!this.isLocked(i)){
5558 return this.config.length;
5562 * Returns the number of columns.
5565 getColumnCount : function(visibleOnly){
5566 if(visibleOnly === true){
5568 for(var i = 0, len = this.config.length; i < len; i++){
5569 if(!this.isHidden(i)){
5575 return this.config.length;
5579 * Returns the column configs that return true by the passed function that is called with (columnConfig, index)
5580 * @param {Function} fn
5581 * @param {Object} scope (optional)
5582 * @return {Array} result
5584 getColumnsBy : function(fn, scope){
5586 for(var i = 0, len = this.config.length; i < len; i++){
5587 var c = this.config[i];
5588 if(fn.call(scope||this, c, i) === true){
5596 * Returns true if the specified column is sortable.
5597 * @param {Number} col The column index
5600 isSortable : function(col){
5601 if(typeof this.config[col].sortable == "undefined"){
5602 return this.defaultSortable;
5604 return this.config[col].sortable;
5608 * Returns the rendering (formatting) function defined for the column.
5609 * @param {Number} col The column index.
5610 * @return {Function} The function used to render the cell. See {@link #setRenderer}.
5612 getRenderer : function(col){
5613 if(!this.config[col].renderer){
5614 return Roo.grid.ColumnModel.defaultRenderer;
5616 return this.config[col].renderer;
5620 * Sets the rendering (formatting) function for a column.
5621 * @param {Number} col The column index
5622 * @param {Function} fn The function to use to process the cell's raw data
5623 * to return HTML markup for the grid view. The render function is called with
5624 * the following parameters:<ul>
5625 * <li>Data value.</li>
5626 * <li>Cell metadata. An object in which you may set the following attributes:<ul>
5627 * <li>css A CSS style string to apply to the table cell.</li>
5628 * <li>attr An HTML attribute definition string to apply to the data container element <i>within</i> the table cell.</li></ul>
5629 * <li>The {@link Roo.data.Record} from which the data was extracted.</li>
5630 * <li>Row index</li>
5631 * <li>Column index</li>
5632 * <li>The {@link Roo.data.Store} object from which the Record was extracted</li></ul>
5634 setRenderer : function(col, fn){
5635 this.config[col].renderer = fn;
5639 * Returns the width for the specified column.
5640 * @param {Number} col The column index
5643 getColumnWidth : function(col){
5644 return this.config[col].width * 1 || this.defaultWidth;
5648 * Sets the width for a column.
5649 * @param {Number} col The column index
5650 * @param {Number} width The new width
5652 setColumnWidth : function(col, width, suppressEvent){
5653 this.config[col].width = width;
5654 this.totalWidth = null;
5656 this.fireEvent("widthchange", this, col, width);
5661 * Returns the total width of all columns.
5662 * @param {Boolean} includeHidden True to include hidden column widths
5665 getTotalWidth : function(includeHidden){
5666 if(!this.totalWidth){
5667 this.totalWidth = 0;
5668 for(var i = 0, len = this.config.length; i < len; i++){
5669 if(includeHidden || !this.isHidden(i)){
5670 this.totalWidth += this.getColumnWidth(i);
5674 return this.totalWidth;
5678 * Returns the header for the specified column.
5679 * @param {Number} col The column index
5682 getColumnHeader : function(col){
5683 return this.config[col].header;
5687 * Sets the header for a column.
5688 * @param {Number} col The column index
5689 * @param {String} header The new header
5691 setColumnHeader : function(col, header){
5692 this.config[col].header = header;
5693 this.fireEvent("headerchange", this, col, header);
5697 * Returns the tooltip for the specified column.
5698 * @param {Number} col The column index
5701 getColumnTooltip : function(col){
5702 return this.config[col].tooltip;
5705 * Sets the tooltip for a column.
5706 * @param {Number} col The column index
5707 * @param {String} tooltip The new tooltip
5709 setColumnTooltip : function(col, tooltip){
5710 this.config[col].tooltip = tooltip;
5714 * Returns the dataIndex for the specified column.
5715 * @param {Number} col The column index
5718 getDataIndex : function(col){
5719 return this.config[col].dataIndex;
5723 * Sets the dataIndex for a column.
5724 * @param {Number} col The column index
5725 * @param {Number} dataIndex The new dataIndex
5727 setDataIndex : function(col, dataIndex){
5728 this.config[col].dataIndex = dataIndex;
5734 * Returns true if the cell is editable.
5735 * @param {Number} colIndex The column index
5736 * @param {Number} rowIndex The row index - this is nto actually used..?
5739 isCellEditable : function(colIndex, rowIndex){
5740 return (this.config[colIndex].editable || (typeof this.config[colIndex].editable == "undefined" && this.config[colIndex].editor)) ? true : false;
5744 * Returns the editor defined for the cell/column.
5745 * return false or null to disable editing.
5746 * @param {Number} colIndex The column index
5747 * @param {Number} rowIndex The row index
5750 getCellEditor : function(colIndex, rowIndex){
5751 return this.config[colIndex].editor;
5755 * Sets if a column is editable.
5756 * @param {Number} col The column index
5757 * @param {Boolean} editable True if the column is editable
5759 setEditable : function(col, editable){
5760 this.config[col].editable = editable;
5765 * Returns true if the column is hidden.
5766 * @param {Number} colIndex The column index
5769 isHidden : function(colIndex){
5770 return this.config[colIndex].hidden;
5775 * Returns true if the column width cannot be changed
5777 isFixed : function(colIndex){
5778 return this.config[colIndex].fixed;
5782 * Returns true if the column can be resized
5785 isResizable : function(colIndex){
5786 return colIndex >= 0 && this.config[colIndex].resizable !== false && this.config[colIndex].fixed !== true;
5789 * Sets if a column is hidden.
5790 * @param {Number} colIndex The column index
5791 * @param {Boolean} hidden True if the column is hidden
5793 setHidden : function(colIndex, hidden){
5794 this.config[colIndex].hidden = hidden;
5795 this.totalWidth = null;
5796 this.fireEvent("hiddenchange", this, colIndex, hidden);
5800 * Sets the editor for a column.
5801 * @param {Number} col The column index
5802 * @param {Object} editor The editor object
5804 setEditor : function(col, editor){
5805 this.config[col].editor = editor;
5809 Roo.grid.ColumnModel.defaultRenderer = function(value)
5811 if(typeof value == "object") {
5814 if(typeof value == "string" && value.length < 1){
5818 return String.format("{0}", value);
5821 // Alias for backwards compatibility
5822 Roo.grid.DefaultColumnModel = Roo.grid.ColumnModel;
5825 * Ext JS Library 1.1.1
5826 * Copyright(c) 2006-2007, Ext JS, LLC.
5828 * Originally Released Under LGPL - original licence link has changed is not relivant.
5831 * <script type="text/javascript">
5835 * @class Roo.LoadMask
5836 * A simple utility class for generically masking elements while loading data. If the element being masked has
5837 * an underlying {@link Roo.data.Store}, the masking will be automatically synchronized with the store's loading
5838 * process and the mask element will be cached for reuse. For all other elements, this mask will replace the
5839 * element's UpdateManager load indicator and will be destroyed after the initial load.
5841 * Create a new LoadMask
5842 * @param {String/HTMLElement/Roo.Element} el The element or DOM node, or its id
5843 * @param {Object} config The config object
5845 Roo.LoadMask = function(el, config){
5846 this.el = Roo.get(el);
5847 Roo.apply(this, config);
5849 this.store.on('beforeload', this.onBeforeLoad, this);
5850 this.store.on('load', this.onLoad, this);
5851 this.store.on('loadexception', this.onLoadException, this);
5852 this.removeMask = false;
5854 var um = this.el.getUpdateManager();
5855 um.showLoadIndicator = false; // disable the default indicator
5856 um.on('beforeupdate', this.onBeforeLoad, this);
5857 um.on('update', this.onLoad, this);
5858 um.on('failure', this.onLoad, this);
5859 this.removeMask = true;
5863 Roo.LoadMask.prototype = {
5865 * @cfg {Boolean} removeMask
5866 * True to create a single-use mask that is automatically destroyed after loading (useful for page loads),
5867 * False to persist the mask element reference for multiple uses (e.g., for paged data widgets). Defaults to false.
5871 * The text to display in a centered loading message box (defaults to 'Loading...')
5875 * @cfg {String} msgCls
5876 * The CSS class to apply to the loading message element (defaults to "x-mask-loading")
5878 msgCls : 'x-mask-loading',
5881 * Read-only. True if the mask is currently disabled so that it will not be displayed (defaults to false)
5887 * Disables the mask to prevent it from being displayed
5889 disable : function(){
5890 this.disabled = true;
5894 * Enables the mask so that it can be displayed
5896 enable : function(){
5897 this.disabled = false;
5900 onLoadException : function()
5904 if (typeof(arguments[3]) != 'undefined') {
5905 Roo.MessageBox.alert("Error loading",arguments[3]);
5909 if (this.store && typeof(this.store.reader.jsonData.errorMsg) != 'undefined') {
5910 Roo.MessageBox.alert("Error loading",this.store.reader.jsonData.errorMsg);
5917 (function() { this.el.unmask(this.removeMask); }).defer(50, this);
5922 (function() { this.el.unmask(this.removeMask); }).defer(50, this);
5926 onBeforeLoad : function(){
5928 (function() { this.el.mask(this.msg, this.msgCls); }).defer(50, this);
5933 destroy : function(){
5935 this.store.un('beforeload', this.onBeforeLoad, this);
5936 this.store.un('load', this.onLoad, this);
5937 this.store.un('loadexception', this.onLoadException, this);
5939 var um = this.el.getUpdateManager();
5940 um.un('beforeupdate', this.onBeforeLoad, this);
5941 um.un('update', this.onLoad, this);
5942 um.un('failure', this.onLoad, this);
5953 * @class Roo.bootstrap.Table
5954 * @extends Roo.bootstrap.Component
5955 * Bootstrap Table class
5956 * @cfg {String} cls table class
5957 * @cfg {String} align (left|center|right) Specifies the alignment of a table according to surrounding text
5958 * @cfg {String} bgcolor Specifies the background color for a table
5959 * @cfg {Number} border Specifies whether the table cells should have borders or not
5960 * @cfg {Number} cellpadding Specifies the space between the cell wall and the cell content
5961 * @cfg {Number} cellspacing Specifies the space between cells
5962 * @cfg {String} frame Specifies which parts of the outside borders that should be visible
5963 * @cfg {String} rules Specifies which parts of the inside borders that should be visible
5964 * @cfg {String} sortable Specifies that the table should be sortable
5965 * @cfg {String} summary Specifies a summary of the content of a table
5966 * @cfg {Number} width Specifies the width of a table
5967 * @cfg {String} layout table layout (auto | fixed | initial | inherit)
5969 * @cfg {boolean} striped Should the rows be alternative striped
5970 * @cfg {boolean} bordered Add borders to the table
5971 * @cfg {boolean} hover Add hover highlighting
5972 * @cfg {boolean} condensed Format condensed
5973 * @cfg {boolean} responsive Format condensed
5974 * @cfg {Boolean} loadMask (true|false) default false
5975 * @cfg {Boolean} footerShow (true|false) generate tfoot, default true
5976 * @cfg {Boolean} headerShow (true|false) generate thead, default true
5977 * @cfg {Boolean} rowSelection (true|false) default false
5978 * @cfg {Boolean} cellSelection (true|false) default false
5979 * @cfg {Boolean} scrollBody (true|false) default false - body scrolled / fixed header
5980 * @cfg {Roo.bootstrap.PagingToolbar} footer a paging toolbar
5981 * @cfg {Boolean} lazyLoad auto load data while scrolling to the end (default false)
5982 * @cfg {Boolean} auto_hide_footer auto hide footer if only one page (default false)
5986 * Create a new Table
5987 * @param {Object} config The config object
5990 Roo.bootstrap.Table = function(config){
5991 Roo.bootstrap.Table.superclass.constructor.call(this, config);
5996 this.rowSelection = (typeof(config.rowSelection) != 'undefined') ? config.rowSelection : this.rowSelection;
5997 this.cellSelection = (typeof(config.cellSelection) != 'undefined') ? config.cellSelection : this.cellSelection;
5998 this.headerShow = (typeof(config.thead) != 'undefined') ? config.thead : this.headerShow;
5999 this.footerShow = (typeof(config.tfoot) != 'undefined') ? config.tfoot : this.footerShow;
6001 this.sm = this.sm || {xtype: 'RowSelectionModel'};
6003 this.sm.grid = this;
6004 this.selModel = Roo.factory(this.sm, Roo.bootstrap.Table);
6005 this.sm = this.selModel;
6006 this.sm.xmodule = this.xmodule || false;
6009 if (this.cm && typeof(this.cm.config) == 'undefined') {
6010 this.colModel = new Roo.grid.ColumnModel(this.cm);
6011 this.cm = this.colModel;
6012 this.cm.xmodule = this.xmodule || false;
6015 this.store= Roo.factory(this.store, Roo.data);
6016 this.ds = this.store;
6017 this.ds.xmodule = this.xmodule || false;
6020 if (this.footer && this.store) {
6021 this.footer.dataSource = this.ds;
6022 this.footer = Roo.factory(this.footer);
6029 * Fires when a cell is clicked
6030 * @param {Roo.bootstrap.Table} this
6031 * @param {Roo.Element} el
6032 * @param {Number} rowIndex
6033 * @param {Number} columnIndex
6034 * @param {Roo.EventObject} e
6038 * @event celldblclick
6039 * Fires when a cell is double clicked
6040 * @param {Roo.bootstrap.Table} this
6041 * @param {Roo.Element} el
6042 * @param {Number} rowIndex
6043 * @param {Number} columnIndex
6044 * @param {Roo.EventObject} e
6046 "celldblclick" : true,
6049 * Fires when a row is clicked
6050 * @param {Roo.bootstrap.Table} this
6051 * @param {Roo.Element} el
6052 * @param {Number} rowIndex
6053 * @param {Roo.EventObject} e
6057 * @event rowdblclick
6058 * Fires when a row is double clicked
6059 * @param {Roo.bootstrap.Table} this
6060 * @param {Roo.Element} el
6061 * @param {Number} rowIndex
6062 * @param {Roo.EventObject} e
6064 "rowdblclick" : true,
6067 * Fires when a mouseover occur
6068 * @param {Roo.bootstrap.Table} this
6069 * @param {Roo.Element} el
6070 * @param {Number} rowIndex
6071 * @param {Number} columnIndex
6072 * @param {Roo.EventObject} e
6077 * Fires when a mouseout occur
6078 * @param {Roo.bootstrap.Table} this
6079 * @param {Roo.Element} el
6080 * @param {Number} rowIndex
6081 * @param {Number} columnIndex
6082 * @param {Roo.EventObject} e
6087 * Fires when a row is rendered, so you can change add a style to it.
6088 * @param {Roo.bootstrap.Table} this
6089 * @param {Object} rowcfg contains record rowIndex colIndex and rowClass - set rowClass to add a style.
6093 * @event rowsrendered
6094 * Fires when all the rows have been rendered
6095 * @param {Roo.bootstrap.Table} this
6097 'rowsrendered' : true,
6099 * @event contextmenu
6100 * The raw contextmenu event for the entire grid.
6101 * @param {Roo.EventObject} e
6103 "contextmenu" : true,
6105 * @event rowcontextmenu
6106 * Fires when a row is right clicked
6107 * @param {Roo.bootstrap.Table} this
6108 * @param {Number} rowIndex
6109 * @param {Roo.EventObject} e
6111 "rowcontextmenu" : true,
6113 * @event cellcontextmenu
6114 * Fires when a cell is right clicked
6115 * @param {Roo.bootstrap.Table} this
6116 * @param {Number} rowIndex
6117 * @param {Number} cellIndex
6118 * @param {Roo.EventObject} e
6120 "cellcontextmenu" : true,
6122 * @event headercontextmenu
6123 * Fires when a header is right clicked
6124 * @param {Roo.bootstrap.Table} this
6125 * @param {Number} columnIndex
6126 * @param {Roo.EventObject} e
6128 "headercontextmenu" : true
6132 Roo.extend(Roo.bootstrap.Table, Roo.bootstrap.Component, {
6158 rowSelection : false,
6159 cellSelection : false,
6162 // Roo.Element - the tbody
6164 // Roo.Element - thead element
6167 container: false, // used by gridpanel...
6173 auto_hide_footer : false,
6175 getAutoCreate : function()
6177 var cfg = Roo.apply({}, Roo.bootstrap.Table.superclass.getAutoCreate.call(this));
6184 if (this.scrollBody) {
6185 cfg.cls += ' table-body-fixed';
6188 cfg.cls += ' table-striped';
6192 cfg.cls += ' table-hover';
6194 if (this.bordered) {
6195 cfg.cls += ' table-bordered';
6197 if (this.condensed) {
6198 cfg.cls += ' table-condensed';
6200 if (this.responsive) {
6201 cfg.cls += ' table-responsive';
6205 cfg.cls+= ' ' +this.cls;
6208 // this lot should be simplifed...
6221 ].forEach(function(k) {
6229 cfg.style = (typeof(cfg.style) == 'undefined') ? ('table-layout:' + this.layout + ';') : (cfg.style + ('table-layout:' + this.layout + ';'));
6232 if(this.store || this.cm){
6233 if(this.headerShow){
6234 cfg.cn.push(this.renderHeader());
6237 cfg.cn.push(this.renderBody());
6239 if(this.footerShow){
6240 cfg.cn.push(this.renderFooter());
6242 // where does this come from?
6243 //cfg.cls+= ' TableGrid';
6246 return { cn : [ cfg ] };
6249 initEvents : function()
6251 if(!this.store || !this.cm){
6254 if (this.selModel) {
6255 this.selModel.initEvents();
6259 //Roo.log('initEvents with ds!!!!');
6261 this.mainBody = this.el.select('tbody', true).first();
6262 this.mainHead = this.el.select('thead', true).first();
6263 this.mainFoot = this.el.select('tfoot', true).first();
6269 Roo.each(this.el.select('thead th.sortable', true).elements, function(e){
6270 e.on('click', _this.sort, _this);
6273 this.mainBody.on("click", this.onClick, this);
6274 this.mainBody.on("dblclick", this.onDblClick, this);
6276 // why is this done????? = it breaks dialogs??
6277 //this.parent().el.setStyle('position', 'relative');
6281 this.footer.parentId = this.id;
6282 this.footer.onRender(this.el.select('tfoot tr td').first(), null);
6285 this.el.select('tfoot tr td').first().addClass('hide');
6290 this.maskEl = new Roo.LoadMask(this.el, { store : this.ds, msgCls: 'roo-el-mask-msg' });
6293 this.store.on('load', this.onLoad, this);
6294 this.store.on('beforeload', this.onBeforeLoad, this);
6295 this.store.on('update', this.onUpdate, this);
6296 this.store.on('add', this.onAdd, this);
6297 this.store.on("clear", this.clear, this);
6299 this.el.on("contextmenu", this.onContextMenu, this);
6301 this.mainBody.on('scroll', this.onBodyScroll, this);
6303 this.cm.on("headerchange", this.onHeaderChange, this);
6305 this.cm.on("hiddenchange", this.onHiddenChange, this, arguments);
6309 onContextMenu : function(e, t)
6311 this.processEvent("contextmenu", e);
6314 processEvent : function(name, e)
6316 if (name != 'touchstart' ) {
6317 this.fireEvent(name, e);
6320 var t = e.getTarget();
6322 var cell = Roo.get(t);
6328 if(cell.findParent('tfoot', false, true)){
6332 if(cell.findParent('thead', false, true)){
6334 if(e.getTarget().nodeName.toLowerCase() != 'th'){
6335 cell = Roo.get(t).findParent('th', false, true);
6337 Roo.log("failed to find th in thead?");
6338 Roo.log(e.getTarget());
6343 var cellIndex = cell.dom.cellIndex;
6345 var ename = name == 'touchstart' ? 'click' : name;
6346 this.fireEvent("header" + ename, this, cellIndex, e);
6351 if(e.getTarget().nodeName.toLowerCase() != 'td'){
6352 cell = Roo.get(t).findParent('td', false, true);
6354 Roo.log("failed to find th in tbody?");
6355 Roo.log(e.getTarget());
6360 var row = cell.findParent('tr', false, true);
6361 var cellIndex = cell.dom.cellIndex;
6362 var rowIndex = row.dom.rowIndex - 1;
6366 this.fireEvent("row" + name, this, rowIndex, e);
6370 this.fireEvent("cell" + name, this, rowIndex, cellIndex, e);
6376 onMouseover : function(e, el)
6378 var cell = Roo.get(el);
6384 if(e.getTarget().nodeName.toLowerCase() != 'td'){
6385 cell = cell.findParent('td', false, true);
6388 var row = cell.findParent('tr', false, true);
6389 var cellIndex = cell.dom.cellIndex;
6390 var rowIndex = row.dom.rowIndex - 1; // start from 0
6392 this.fireEvent('mouseover', this, cell, rowIndex, cellIndex, e);
6396 onMouseout : function(e, el)
6398 var cell = Roo.get(el);
6404 if(e.getTarget().nodeName.toLowerCase() != 'td'){
6405 cell = cell.findParent('td', false, true);
6408 var row = cell.findParent('tr', false, true);
6409 var cellIndex = cell.dom.cellIndex;
6410 var rowIndex = row.dom.rowIndex - 1; // start from 0
6412 this.fireEvent('mouseout', this, cell, rowIndex, cellIndex, e);
6416 onClick : function(e, el)
6418 var cell = Roo.get(el);
6420 if(!cell || (!this.cellSelection && !this.rowSelection)){
6424 if(e.getTarget().nodeName.toLowerCase() != 'td'){
6425 cell = cell.findParent('td', false, true);
6428 if(!cell || typeof(cell) == 'undefined'){
6432 var row = cell.findParent('tr', false, true);
6434 if(!row || typeof(row) == 'undefined'){
6438 var cellIndex = cell.dom.cellIndex;
6439 var rowIndex = this.getRowIndex(row);
6441 // why??? - should these not be based on SelectionModel?
6442 if(this.cellSelection){
6443 this.fireEvent('cellclick', this, cell, rowIndex, cellIndex, e);
6446 if(this.rowSelection){
6447 this.fireEvent('rowclick', this, row, rowIndex, e);
6453 onDblClick : function(e,el)
6455 var cell = Roo.get(el);
6457 if(!cell || (!this.cellSelection && !this.rowSelection)){
6461 if(e.getTarget().nodeName.toLowerCase() != 'td'){
6462 cell = cell.findParent('td', false, true);
6465 if(!cell || typeof(cell) == 'undefined'){
6469 var row = cell.findParent('tr', false, true);
6471 if(!row || typeof(row) == 'undefined'){
6475 var cellIndex = cell.dom.cellIndex;
6476 var rowIndex = this.getRowIndex(row);
6478 if(this.cellSelection){
6479 this.fireEvent('celldblclick', this, cell, rowIndex, cellIndex, e);
6482 if(this.rowSelection){
6483 this.fireEvent('rowdblclick', this, row, rowIndex, e);
6487 sort : function(e,el)
6489 var col = Roo.get(el);
6491 if(!col.hasClass('sortable')){
6495 var sort = col.attr('sort');
6498 if(col.select('i', true).first().hasClass('glyphicon-arrow-up')){
6502 this.store.sortInfo = {field : sort, direction : dir};
6505 Roo.log("calling footer first");
6506 this.footer.onClick('first');
6509 this.store.load({ params : { start : 0 } });
6513 renderHeader : function()
6521 this.totalWidth = 0;
6523 for(var i = 0, len = cm.getColumnCount(); i < len; i++){
6525 var config = cm.config[i];
6529 cls : 'x-hcol-' + i,
6531 html: cm.getColumnHeader(i)
6536 if(typeof(config.sortable) != 'undefined' && config.sortable){
6538 c.html = '<i class="glyphicon"></i>' + c.html;
6541 if(typeof(config.lgHeader) != 'undefined'){
6542 hh += '<span class="hidden-xs hidden-sm hidden-md">' + config.lgHeader + '</span>';
6545 if(typeof(config.mdHeader) != 'undefined'){
6546 hh += '<span class="hidden-xs hidden-sm hidden-lg">' + config.mdHeader + '</span>';
6549 if(typeof(config.smHeader) != 'undefined'){
6550 hh += '<span class="hidden-xs hidden-md hidden-lg">' + config.smHeader + '</span>';
6553 if(typeof(config.xsHeader) != 'undefined'){
6554 hh += '<span class="hidden-sm hidden-md hidden-lg">' + config.xsHeader + '</span>';
6561 if(typeof(config.tooltip) != 'undefined'){
6562 c.tooltip = config.tooltip;
6565 if(typeof(config.colspan) != 'undefined'){
6566 c.colspan = config.colspan;
6569 if(typeof(config.hidden) != 'undefined' && config.hidden){
6570 c.style += ' display:none;';
6573 if(typeof(config.dataIndex) != 'undefined'){
6574 c.sort = config.dataIndex;
6579 if(typeof(config.align) != 'undefined' && config.align.length){
6580 c.style += ' text-align:' + config.align + ';';
6583 if(typeof(config.width) != 'undefined'){
6584 c.style += ' width:' + config.width + 'px;';
6585 this.totalWidth += config.width;
6587 this.totalWidth += 100; // assume minimum of 100 per column?
6590 if(typeof(config.cls) != 'undefined'){
6591 c.cls = (typeof(c.cls) == 'undefined') ? config.cls : (c.cls + ' ' + config.cls);
6594 ['xs','sm','md','lg'].map(function(size){
6596 if(typeof(config[size]) == 'undefined'){
6600 if (!config[size]) { // 0 = hidden
6601 c.cls += ' hidden-' + size;
6605 c.cls += ' col-' + size + '-' + config[size];
6615 renderBody : function()
6625 colspan : this.cm.getColumnCount()
6635 renderFooter : function()
6645 colspan : this.cm.getColumnCount()
6659 // Roo.log('ds onload');
6664 var ds = this.store;
6666 Roo.each(this.el.select('thead th.sortable', true).elements, function(e){
6667 e.select('i', true).removeClass(['glyphicon-arrow-up', 'glyphicon-arrow-down']);
6668 if (_this.store.sortInfo) {
6670 if(e.hasClass('sortable') && e.attr('sort') == _this.store.sortInfo.field && _this.store.sortInfo.direction.toUpperCase() == 'ASC'){
6671 e.select('i', true).addClass(['glyphicon-arrow-up']);
6674 if(e.hasClass('sortable') && e.attr('sort') == _this.store.sortInfo.field && _this.store.sortInfo.direction.toUpperCase() == 'DESC'){
6675 e.select('i', true).addClass(['glyphicon-arrow-down']);
6680 var tbody = this.mainBody;
6682 if(ds.getCount() > 0){
6683 ds.data.each(function(d,rowIndex){
6684 var row = this.renderRow(cm, ds, rowIndex);
6686 tbody.createChild(row);
6690 if(row.cellObjects.length){
6691 Roo.each(row.cellObjects, function(r){
6692 _this.renderCellObject(r);
6699 var tfoot = this.el.select('tfoot', true).first();
6701 if(this.footerShow && this.auto_hide_footer && this.mainFoot){
6703 this.mainFoot.setVisibilityMode(Roo.Element.DISPLAY).hide();
6705 var total = this.ds.getTotalCount();
6707 if(this.footer.pageSize < total){
6708 this.mainFoot.show();
6712 Roo.each(this.el.select('tbody td', true).elements, function(e){
6713 e.on('mouseover', _this.onMouseover, _this);
6716 Roo.each(this.el.select('tbody td', true).elements, function(e){
6717 e.on('mouseout', _this.onMouseout, _this);
6719 this.fireEvent('rowsrendered', this);
6725 onUpdate : function(ds,record)
6727 this.refreshRow(record);
6731 onRemove : function(ds, record, index, isUpdate){
6732 if(isUpdate !== true){
6733 this.fireEvent("beforerowremoved", this, index, record);
6735 var bt = this.mainBody.dom;
6737 var rows = this.el.select('tbody > tr', true).elements;
6739 if(typeof(rows[index]) != 'undefined'){
6740 bt.removeChild(rows[index].dom);
6743 // if(bt.rows[index]){
6744 // bt.removeChild(bt.rows[index]);
6747 if(isUpdate !== true){
6748 //this.stripeRows(index);
6749 //this.syncRowHeights(index, index);
6751 this.fireEvent("rowremoved", this, index, record);
6755 onAdd : function(ds, records, rowIndex)
6757 //Roo.log('on Add called');
6758 // - note this does not handle multiple adding very well..
6759 var bt = this.mainBody.dom;
6760 for (var i =0 ; i < records.length;i++) {
6761 //Roo.log('call insert row Add called on ' + rowIndex + ':' + i);
6762 //Roo.log(records[i]);
6763 //Roo.log(this.store.getAt(rowIndex+i));
6764 this.insertRow(this.store, rowIndex + i, false);
6771 refreshRow : function(record){
6772 var ds = this.store, index;
6773 if(typeof record == 'number'){
6775 record = ds.getAt(index);
6777 index = ds.indexOf(record);
6779 this.insertRow(ds, index, true);
6781 this.onRemove(ds, record, index+1, true);
6783 //this.syncRowHeights(index, index);
6785 this.fireEvent("rowupdated", this, index, record);
6788 insertRow : function(dm, rowIndex, isUpdate){
6791 this.fireEvent("beforerowsinserted", this, rowIndex);
6793 //var s = this.getScrollState();
6794 var row = this.renderRow(this.cm, this.store, rowIndex);
6795 // insert before rowIndex..
6796 var e = this.mainBody.createChild(row,this.getRowDom(rowIndex));
6800 if(row.cellObjects.length){
6801 Roo.each(row.cellObjects, function(r){
6802 _this.renderCellObject(r);
6807 this.fireEvent("rowsinserted", this, rowIndex);
6808 //this.syncRowHeights(firstRow, lastRow);
6809 //this.stripeRows(firstRow);
6816 getRowDom : function(rowIndex)
6818 var rows = this.el.select('tbody > tr', true).elements;
6820 return (typeof(rows[rowIndex]) == 'undefined') ? false : rows[rowIndex];
6823 // returns the object tree for a tr..
6826 renderRow : function(cm, ds, rowIndex)
6828 var d = ds.getAt(rowIndex);
6832 cls : 'x-row-' + rowIndex,
6836 var cellObjects = [];
6838 for(var i = 0, len = cm.getColumnCount(); i < len; i++){
6839 var config = cm.config[i];
6841 var renderer = cm.getRenderer(i);
6845 if(typeof(renderer) !== 'undefined'){
6846 value = renderer(d.data[cm.getDataIndex(i)], false, d);
6848 // if object are returned, then they are expected to be Roo.bootstrap.Component instances
6849 // and are rendered into the cells after the row is rendered - using the id for the element.
6851 if(typeof(value) === 'object'){
6861 rowIndex : rowIndex,
6866 this.fireEvent('rowclass', this, rowcfg);
6870 cls : rowcfg.rowClass + ' x-col-' + i,
6872 html: (typeof(value) === 'object') ? '' : value
6879 if(typeof(config.colspan) != 'undefined'){
6880 td.colspan = config.colspan;
6883 if(typeof(config.hidden) != 'undefined' && config.hidden){
6884 td.style += ' display:none;';
6887 if(typeof(config.align) != 'undefined' && config.align.length){
6888 td.style += ' text-align:' + config.align + ';';
6890 if(typeof(config.valign) != 'undefined' && config.valign.length){
6891 td.style += ' vertical-align:' + config.valign + ';';
6894 if(typeof(config.width) != 'undefined'){
6895 td.style += ' width:' + config.width + 'px;';
6898 if(typeof(config.cursor) != 'undefined'){
6899 td.style += ' cursor:' + config.cursor + ';';
6902 if(typeof(config.cls) != 'undefined'){
6903 td.cls = (typeof(td.cls) == 'undefined') ? config.cls : (td.cls + ' ' + config.cls);
6906 ['xs','sm','md','lg'].map(function(size){
6908 if(typeof(config[size]) == 'undefined'){
6912 if (!config[size]) { // 0 = hidden
6913 td.cls += ' hidden-' + size;
6917 td.cls += ' col-' + size + '-' + config[size];
6925 row.cellObjects = cellObjects;
6933 onBeforeLoad : function()
6942 this.el.select('tbody', true).first().dom.innerHTML = '';
6945 * Show or hide a row.
6946 * @param {Number} rowIndex to show or hide
6947 * @param {Boolean} state hide
6949 setRowVisibility : function(rowIndex, state)
6951 var bt = this.mainBody.dom;
6953 var rows = this.el.select('tbody > tr', true).elements;
6955 if(typeof(rows[rowIndex]) == 'undefined'){
6958 rows[rowIndex].dom.style.display = state ? '' : 'none';
6962 getSelectionModel : function(){
6964 this.selModel = new Roo.bootstrap.Table.RowSelectionModel({grid: this});
6966 return this.selModel;
6969 * Render the Roo.bootstrap object from renderder
6971 renderCellObject : function(r)
6975 r.cfg.parentId = (typeof(r.container) == 'string') ? r.container : r.container.id;
6977 var t = r.cfg.render(r.container);
6980 Roo.each(r.cfg.cn, function(c){
6982 container: t.getChildContainer(),
6985 _this.renderCellObject(child);
6990 getRowIndex : function(row)
6994 Roo.each(this.el.select('tbody > tr', true).elements, function(el, index){
7005 * Returns the grid's underlying element = used by panel.Grid
7006 * @return {Element} The element
7008 getGridEl : function(){
7012 * Forces a resize - used by panel.Grid
7013 * @return {Element} The element
7015 autoSize : function()
7017 //var ctr = Roo.get(this.container.dom.parentElement);
7018 var ctr = Roo.get(this.el.dom);
7020 var thd = this.getGridEl().select('thead',true).first();
7021 var tbd = this.getGridEl().select('tbody', true).first();
7022 var tfd = this.getGridEl().select('tfoot', true).first();
7024 var cw = ctr.getWidth();
7028 tbd.setSize(ctr.getWidth(),
7029 ctr.getHeight() - ((thd ? thd.getHeight() : 0) + (tfd ? tfd.getHeight() : 0))
7031 var barsize = (tbd.dom.offsetWidth - tbd.dom.clientWidth);
7034 cw = Math.max(cw, this.totalWidth);
7035 this.getGridEl().select('tr',true).setWidth(cw);
7036 // resize 'expandable coloumn?
7038 return; // we doe not have a view in this design..
7041 onBodyScroll: function()
7043 //Roo.log("body scrolled');" + this.mainBody.dom.scrollLeft);
7045 this.mainHead.setStyle({
7046 'position' : 'relative',
7047 'left': (-1* this.mainBody.dom.scrollLeft) + 'px'
7053 var scrollHeight = this.mainBody.dom.scrollHeight;
7055 var scrollTop = Math.ceil(this.mainBody.getScroll().top);
7057 var height = this.mainBody.getHeight();
7059 if(scrollHeight - height == scrollTop) {
7061 var total = this.ds.getTotalCount();
7063 if(this.footer.cursor + this.footer.pageSize < total){
7065 this.footer.ds.load({
7067 start : this.footer.cursor + this.footer.pageSize,
7068 limit : this.footer.pageSize
7078 onHeaderChange : function()
7080 var header = this.renderHeader();
7081 var table = this.el.select('table', true).first();
7083 this.mainHead.remove();
7084 this.mainHead = table.createChild(header, this.mainBody, false);
7087 onHiddenChange : function(colModel, colIndex, hidden)
7089 var thSelector = '#' + this.id + ' .x-hcol-' + colIndex;
7090 var tdSelector = '#' + this.id + ' .x-col-' + colIndex;
7092 this.CSS.updateRule(thSelector, "display", "");
7093 this.CSS.updateRule(tdSelector, "display", "");
7096 this.CSS.updateRule(thSelector, "display", "none");
7097 this.CSS.updateRule(tdSelector, "display", "none");
7100 this.onHeaderChange();
7104 setColumnWidth: function(col_index, width)
7106 // width = "md-2 xs-2..."
7107 if(!this.colModel.config[col_index]) {
7111 var w = width.split(" ");
7113 var rows = this.el.dom.getElementsByClassName("x-col-"+col_index);
7115 var h_rows = this.el.dom.getElementsByClassName("x-hcol-"+col_index);
7117 if(rows.length != h_rows.length) {
7122 for(var i = 0; i < rows.length; i++) {
7124 for(var j = 0; w.length; j++) {
7126 var size_cls = w[j].split("-");
7128 if(!Number.isInteger(size_cls[1] * 1)) {
7132 if(!this.colModel.config[col_index][size_cls[0]]) {
7136 rows[i].classList.replace(
7137 "col-"+size_cls[0]+"-"+this.colModel.config[col_index][size_cls[0]],
7138 "col-"+size_cls[0]+"-"+size_cls[1]
7141 h_rows[i].classList.replace(
7142 "col-"+size_cls[0]+"-"+this.colModel.config[col_index][size_cls[0]],
7143 "col-"+size_cls[0]+"-"+size_cls[1]
7146 this.colModel.config[col_index][size_cls[0]] = size_cls[1]
7162 * @class Roo.bootstrap.TableCell
7163 * @extends Roo.bootstrap.Component
7164 * Bootstrap TableCell class
7165 * @cfg {String} html cell contain text
7166 * @cfg {String} cls cell class
7167 * @cfg {String} tag cell tag (td|th) default td
7168 * @cfg {String} abbr Specifies an abbreviated version of the content in a cell
7169 * @cfg {String} align Aligns the content in a cell
7170 * @cfg {String} axis Categorizes cells
7171 * @cfg {String} bgcolor Specifies the background color of a cell
7172 * @cfg {Number} charoff Sets the number of characters the content will be aligned from the character specified by the char attribute
7173 * @cfg {Number} colspan Specifies the number of columns a cell should span
7174 * @cfg {String} headers Specifies one or more header cells a cell is related to
7175 * @cfg {Number} height Sets the height of a cell
7176 * @cfg {String} nowrap Specifies that the content inside a cell should not wrap
7177 * @cfg {Number} rowspan Sets the number of rows a cell should span
7178 * @cfg {String} scope Defines a way to associate header cells and data cells in a table
7179 * @cfg {String} valign Vertical aligns the content in a cell
7180 * @cfg {Number} width Specifies the width of a cell
7183 * Create a new TableCell
7184 * @param {Object} config The config object
7187 Roo.bootstrap.TableCell = function(config){
7188 Roo.bootstrap.TableCell.superclass.constructor.call(this, config);
7191 Roo.extend(Roo.bootstrap.TableCell, Roo.bootstrap.Component, {
7211 getAutoCreate : function(){
7212 var cfg = Roo.apply({}, Roo.bootstrap.TableCell.superclass.getAutoCreate.call(this));
7232 cfg.align=this.align
7238 cfg.bgcolor=this.bgcolor
7241 cfg.charoff=this.charoff
7244 cfg.colspan=this.colspan
7247 cfg.headers=this.headers
7250 cfg.height=this.height
7253 cfg.nowrap=this.nowrap
7256 cfg.rowspan=this.rowspan
7259 cfg.scope=this.scope
7262 cfg.valign=this.valign
7265 cfg.width=this.width
7284 * @class Roo.bootstrap.TableRow
7285 * @extends Roo.bootstrap.Component
7286 * Bootstrap TableRow class
7287 * @cfg {String} cls row class
7288 * @cfg {String} align Aligns the content in a table row
7289 * @cfg {String} bgcolor Specifies a background color for a table row
7290 * @cfg {Number} charoff Sets the number of characters the content will be aligned from the character specified by the char attribute
7291 * @cfg {String} valign Vertical aligns the content in a table row
7294 * Create a new TableRow
7295 * @param {Object} config The config object
7298 Roo.bootstrap.TableRow = function(config){
7299 Roo.bootstrap.TableRow.superclass.constructor.call(this, config);
7302 Roo.extend(Roo.bootstrap.TableRow, Roo.bootstrap.Component, {
7310 getAutoCreate : function(){
7311 var cfg = Roo.apply({}, Roo.bootstrap.TableRow.superclass.getAutoCreate.call(this));
7321 cfg.align = this.align;
7324 cfg.bgcolor = this.bgcolor;
7327 cfg.charoff = this.charoff;
7330 cfg.valign = this.valign;
7348 * @class Roo.bootstrap.TableBody
7349 * @extends Roo.bootstrap.Component
7350 * Bootstrap TableBody class
7351 * @cfg {String} cls element class
7352 * @cfg {String} tag element tag (thead|tbody|tfoot) default tbody
7353 * @cfg {String} align Aligns the content inside the element
7354 * @cfg {Number} charoff Sets the number of characters the content inside the element will be aligned from the character specified by the char attribute
7355 * @cfg {String} valign Vertical aligns the content inside the <tbody> element
7358 * Create a new TableBody
7359 * @param {Object} config The config object
7362 Roo.bootstrap.TableBody = function(config){
7363 Roo.bootstrap.TableBody.superclass.constructor.call(this, config);
7366 Roo.extend(Roo.bootstrap.TableBody, Roo.bootstrap.Component, {
7374 getAutoCreate : function(){
7375 var cfg = Roo.apply({}, Roo.bootstrap.TableBody.superclass.getAutoCreate.call(this));
7389 cfg.align = this.align;
7392 cfg.charoff = this.charoff;
7395 cfg.valign = this.valign;
7402 // initEvents : function()
7409 // this.store = Roo.factory(this.store, Roo.data);
7410 // this.store.on('load', this.onLoad, this);
7412 // this.store.load();
7416 // onLoad: function ()
7418 // this.fireEvent('load', this);
7428 * Ext JS Library 1.1.1
7429 * Copyright(c) 2006-2007, Ext JS, LLC.
7431 * Originally Released Under LGPL - original licence link has changed is not relivant.
7434 * <script type="text/javascript">
7437 // as we use this in bootstrap.
7438 Roo.namespace('Roo.form');
7440 * @class Roo.form.Action
7441 * Internal Class used to handle form actions
7443 * @param {Roo.form.BasicForm} el The form element or its id
7444 * @param {Object} config Configuration options
7449 // define the action interface
7450 Roo.form.Action = function(form, options){
7452 this.options = options || {};
7455 * Client Validation Failed
7458 Roo.form.Action.CLIENT_INVALID = 'client';
7460 * Server Validation Failed
7463 Roo.form.Action.SERVER_INVALID = 'server';
7465 * Connect to Server Failed
7468 Roo.form.Action.CONNECT_FAILURE = 'connect';
7470 * Reading Data from Server Failed
7473 Roo.form.Action.LOAD_FAILURE = 'load';
7475 Roo.form.Action.prototype = {
7477 failureType : undefined,
7478 response : undefined,
7482 run : function(options){
7487 success : function(response){
7492 handleResponse : function(response){
7496 // default connection failure
7497 failure : function(response){
7499 this.response = response;
7500 this.failureType = Roo.form.Action.CONNECT_FAILURE;
7501 this.form.afterAction(this, false);
7504 processResponse : function(response){
7505 this.response = response;
7506 if(!response.responseText){
7509 this.result = this.handleResponse(response);
7513 // utility functions used internally
7514 getUrl : function(appendParams){
7515 var url = this.options.url || this.form.url || this.form.el.dom.action;
7517 var p = this.getParams();
7519 url += (url.indexOf('?') != -1 ? '&' : '?') + p;
7525 getMethod : function(){
7526 return (this.options.method || this.form.method || this.form.el.dom.method || 'POST').toUpperCase();
7529 getParams : function(){
7530 var bp = this.form.baseParams;
7531 var p = this.options.params;
7533 if(typeof p == "object"){
7534 p = Roo.urlEncode(Roo.applyIf(p, bp));
7535 }else if(typeof p == 'string' && bp){
7536 p += '&' + Roo.urlEncode(bp);
7539 p = Roo.urlEncode(bp);
7544 createCallback : function(){
7546 success: this.success,
7547 failure: this.failure,
7549 timeout: (this.form.timeout*1000),
7550 upload: this.form.fileUpload ? this.success : undefined
7555 Roo.form.Action.Submit = function(form, options){
7556 Roo.form.Action.Submit.superclass.constructor.call(this, form, options);
7559 Roo.extend(Roo.form.Action.Submit, Roo.form.Action, {
7562 haveProgress : false,
7563 uploadComplete : false,
7565 // uploadProgress indicator.
7566 uploadProgress : function()
7568 if (!this.form.progressUrl) {
7572 if (!this.haveProgress) {
7573 Roo.MessageBox.progress("Uploading", "Uploading");
7575 if (this.uploadComplete) {
7576 Roo.MessageBox.hide();
7580 this.haveProgress = true;
7582 var uid = this.form.findField('UPLOAD_IDENTIFIER').getValue();
7584 var c = new Roo.data.Connection();
7586 url : this.form.progressUrl,
7591 success : function(req){
7592 //console.log(data);
7596 rdata = Roo.decode(req.responseText)
7598 Roo.log("Invalid data from server..");
7602 if (!rdata || !rdata.success) {
7604 Roo.MessageBox.alert(Roo.encode(rdata));
7607 var data = rdata.data;
7609 if (this.uploadComplete) {
7610 Roo.MessageBox.hide();
7615 Roo.MessageBox.updateProgress(data.bytes_uploaded/data.bytes_total,
7616 Math.floor((data.bytes_total - data.bytes_uploaded)/1000) + 'k remaining'
7619 this.uploadProgress.defer(2000,this);
7622 failure: function(data) {
7623 Roo.log('progress url failed ');
7634 // run get Values on the form, so it syncs any secondary forms.
7635 this.form.getValues();
7637 var o = this.options;
7638 var method = this.getMethod();
7639 var isPost = method == 'POST';
7640 if(o.clientValidation === false || this.form.isValid()){
7642 if (this.form.progressUrl) {
7643 this.form.findField('UPLOAD_IDENTIFIER').setValue(
7644 (new Date() * 1) + '' + Math.random());
7649 Roo.Ajax.request(Roo.apply(this.createCallback(), {
7650 form:this.form.el.dom,
7651 url:this.getUrl(!isPost),
7653 params:isPost ? this.getParams() : null,
7654 isUpload: this.form.fileUpload
7657 this.uploadProgress();
7659 }else if (o.clientValidation !== false){ // client validation failed
7660 this.failureType = Roo.form.Action.CLIENT_INVALID;
7661 this.form.afterAction(this, false);
7665 success : function(response)
7667 this.uploadComplete= true;
7668 if (this.haveProgress) {
7669 Roo.MessageBox.hide();
7673 var result = this.processResponse(response);
7674 if(result === true || result.success){
7675 this.form.afterAction(this, true);
7679 this.form.markInvalid(result.errors);
7680 this.failureType = Roo.form.Action.SERVER_INVALID;
7682 this.form.afterAction(this, false);
7684 failure : function(response)
7686 this.uploadComplete= true;
7687 if (this.haveProgress) {
7688 Roo.MessageBox.hide();
7691 this.response = response;
7692 this.failureType = Roo.form.Action.CONNECT_FAILURE;
7693 this.form.afterAction(this, false);
7696 handleResponse : function(response){
7697 if(this.form.errorReader){
7698 var rs = this.form.errorReader.read(response);
7701 for(var i = 0, len = rs.records.length; i < len; i++) {
7702 var r = rs.records[i];
7706 if(errors.length < 1){
7710 success : rs.success,
7716 ret = Roo.decode(response.responseText);
7720 errorMsg: "Failed to read server message: " + (response ? response.responseText : ' - no message'),
7730 Roo.form.Action.Load = function(form, options){
7731 Roo.form.Action.Load.superclass.constructor.call(this, form, options);
7732 this.reader = this.form.reader;
7735 Roo.extend(Roo.form.Action.Load, Roo.form.Action, {
7740 Roo.Ajax.request(Roo.apply(
7741 this.createCallback(), {
7742 method:this.getMethod(),
7743 url:this.getUrl(false),
7744 params:this.getParams()
7748 success : function(response){
7750 var result = this.processResponse(response);
7751 if(result === true || !result.success || !result.data){
7752 this.failureType = Roo.form.Action.LOAD_FAILURE;
7753 this.form.afterAction(this, false);
7756 this.form.clearInvalid();
7757 this.form.setValues(result.data);
7758 this.form.afterAction(this, true);
7761 handleResponse : function(response){
7762 if(this.form.reader){
7763 var rs = this.form.reader.read(response);
7764 var data = rs.records && rs.records[0] ? rs.records[0].data : null;
7766 success : rs.success,
7770 return Roo.decode(response.responseText);
7774 Roo.form.Action.ACTION_TYPES = {
7775 'load' : Roo.form.Action.Load,
7776 'submit' : Roo.form.Action.Submit
7785 * @class Roo.bootstrap.Form
7786 * @extends Roo.bootstrap.Component
7787 * Bootstrap Form class
7788 * @cfg {String} method GET | POST (default POST)
7789 * @cfg {String} labelAlign top | left (default top)
7790 * @cfg {String} align left | right - for navbars
7791 * @cfg {Boolean} loadMask load mask when submit (default true)
7796 * @param {Object} config The config object
7800 Roo.bootstrap.Form = function(config){
7802 Roo.bootstrap.Form.superclass.constructor.call(this, config);
7804 Roo.bootstrap.Form.popover.apply();
7808 * @event clientvalidation
7809 * If the monitorValid config option is true, this event fires repetitively to notify of valid state
7810 * @param {Form} this
7811 * @param {Boolean} valid true if the form has passed client-side validation
7813 clientvalidation: true,
7815 * @event beforeaction
7816 * Fires before any action is performed. Return false to cancel the action.
7817 * @param {Form} this
7818 * @param {Action} action The action to be performed
7822 * @event actionfailed
7823 * Fires when an action fails.
7824 * @param {Form} this
7825 * @param {Action} action The action that failed
7827 actionfailed : true,
7829 * @event actioncomplete
7830 * Fires when an action is completed.
7831 * @param {Form} this
7832 * @param {Action} action The action that completed
7834 actioncomplete : true
7838 Roo.extend(Roo.bootstrap.Form, Roo.bootstrap.Component, {
7841 * @cfg {String} method
7842 * The request method to use (GET or POST) for form actions if one isn't supplied in the action options.
7847 * The URL to use for form actions if one isn't supplied in the action options.
7850 * @cfg {Boolean} fileUpload
7851 * Set to true if this form is a file upload.
7855 * @cfg {Object} baseParams
7856 * Parameters to pass with all requests. e.g. baseParams: {id: '123', foo: 'bar'}.
7860 * @cfg {Number} timeout Timeout for form actions in seconds (default is 30 seconds).
7864 * @cfg {Sting} align (left|right) for navbar forms
7869 activeAction : null,
7872 * By default wait messages are displayed with Roo.MessageBox.wait. You can target a specific
7873 * element by passing it or its id or mask the form itself by passing in true.
7876 waitMsgTarget : false,
7881 * @cfg {Boolean} errorMask (true|false) default false
7886 * @cfg {Number} maskOffset Default 100
7891 * @cfg {Boolean} maskBody
7895 getAutoCreate : function(){
7899 method : this.method || 'POST',
7900 id : this.id || Roo.id(),
7903 if (this.parent().xtype.match(/^Nav/)) {
7904 cfg.cls = 'navbar-form navbar-' + this.align;
7908 if (this.labelAlign == 'left' ) {
7909 cfg.cls += ' form-horizontal';
7915 initEvents : function()
7917 this.el.on('submit', this.onSubmit, this);
7918 // this was added as random key presses on the form where triggering form submit.
7919 this.el.on('keypress', function(e) {
7920 if (e.getCharCode() != 13) {
7923 // we might need to allow it for textareas.. and some other items.
7924 // check e.getTarget().
7926 if(e.getTarget().nodeName.toLowerCase() === 'textarea'){
7930 Roo.log("keypress blocked");
7938 onSubmit : function(e){
7943 * Returns true if client-side validation on the form is successful.
7946 isValid : function(){
7947 var items = this.getItems();
7951 items.each(function(f){
7957 Roo.log('invalid field: ' + f.name);
7961 if(!target && f.el.isVisible(true)){
7967 if(this.errorMask && !valid){
7968 Roo.bootstrap.Form.popover.mask(this, target);
7975 * Returns true if any fields in this form have changed since their original load.
7978 isDirty : function(){
7980 var items = this.getItems();
7981 items.each(function(f){
7991 * Performs a predefined action (submit or load) or custom actions you define on this form.
7992 * @param {String} actionName The name of the action type
7993 * @param {Object} options (optional) The options to pass to the action. All of the config options listed
7994 * below are supported by both the submit and load actions unless otherwise noted (custom actions could also
7995 * accept other config options):
7997 Property Type Description
7998 ---------------- --------------- ----------------------------------------------------------------------------------
7999 url String The url for the action (defaults to the form's url)
8000 method String The form method to use (defaults to the form's method, or POST if not defined)
8001 params String/Object The params to pass (defaults to the form's baseParams, or none if not defined)
8002 clientValidation Boolean Applies to submit only. Pass true to call form.isValid() prior to posting to
8003 validate the form on the client (defaults to false)
8005 * @return {BasicForm} this
8007 doAction : function(action, options){
8008 if(typeof action == 'string'){
8009 action = new Roo.form.Action.ACTION_TYPES[action](this, options);
8011 if(this.fireEvent('beforeaction', this, action) !== false){
8012 this.beforeAction(action);
8013 action.run.defer(100, action);
8019 beforeAction : function(action){
8020 var o = action.options;
8025 Roo.get(document.body).mask(o.waitMsg || "Sending", 'x-mask-loading')
8027 this.el.mask(o.waitMsg || "Sending", 'x-mask-loading');
8030 // not really supported yet.. ??
8032 //if(this.waitMsgTarget === true){
8033 // this.el.mask(o.waitMsg || "Sending", 'x-mask-loading');
8034 //}else if(this.waitMsgTarget){
8035 // this.waitMsgTarget = Roo.get(this.waitMsgTarget);
8036 // this.waitMsgTarget.mask(o.waitMsg || "Sending", 'x-mask-loading');
8038 // Roo.MessageBox.wait(o.waitMsg || "Sending", o.waitTitle || this.waitTitle || 'Please Wait...');
8044 afterAction : function(action, success){
8045 this.activeAction = null;
8046 var o = action.options;
8051 Roo.get(document.body).unmask();
8057 //if(this.waitMsgTarget === true){
8058 // this.el.unmask();
8059 //}else if(this.waitMsgTarget){
8060 // this.waitMsgTarget.unmask();
8062 // Roo.MessageBox.updateProgress(1);
8063 // Roo.MessageBox.hide();
8070 Roo.callback(o.success, o.scope, [this, action]);
8071 this.fireEvent('actioncomplete', this, action);
8075 // failure condition..
8076 // we have a scenario where updates need confirming.
8077 // eg. if a locking scenario exists..
8078 // we look for { errors : { needs_confirm : true }} in the response.
8080 (typeof(action.result) != 'undefined') &&
8081 (typeof(action.result.errors) != 'undefined') &&
8082 (typeof(action.result.errors.needs_confirm) != 'undefined')
8085 Roo.log("not supported yet");
8088 Roo.MessageBox.confirm(
8089 "Change requires confirmation",
8090 action.result.errorMsg,
8095 _t.doAction('submit', { params : { _submit_confirmed : 1 } } );
8105 Roo.callback(o.failure, o.scope, [this, action]);
8106 // show an error message if no failed handler is set..
8107 if (!this.hasListener('actionfailed')) {
8108 Roo.log("need to add dialog support");
8110 Roo.MessageBox.alert("Error",
8111 (typeof(action.result) != 'undefined' && typeof(action.result.errorMsg) != 'undefined') ?
8112 action.result.errorMsg :
8113 "Saving Failed, please check your entries or try again"
8118 this.fireEvent('actionfailed', this, action);
8123 * Find a Roo.form.Field in this form by id, dataIndex, name or hiddenName
8124 * @param {String} id The value to search for
8127 findField : function(id){
8128 var items = this.getItems();
8129 var field = items.get(id);
8131 items.each(function(f){
8132 if(f.isFormField && (f.dataIndex == id || f.id == id || f.getName() == id)){
8139 return field || null;
8142 * Mark fields in this form invalid in bulk.
8143 * @param {Array/Object} errors Either an array in the form [{id:'fieldId', msg:'The message'},...] or an object hash of {id: msg, id2: msg2}
8144 * @return {BasicForm} this
8146 markInvalid : function(errors){
8147 if(errors instanceof Array){
8148 for(var i = 0, len = errors.length; i < len; i++){
8149 var fieldError = errors[i];
8150 var f = this.findField(fieldError.id);
8152 f.markInvalid(fieldError.msg);
8158 if(typeof errors[id] != 'function' && (field = this.findField(id))){
8159 field.markInvalid(errors[id]);
8163 //Roo.each(this.childForms || [], function (f) {
8164 // f.markInvalid(errors);
8171 * Set values for fields in this form in bulk.
8172 * @param {Array/Object} values Either an array in the form [{id:'fieldId', value:'foo'},...] or an object hash of {id: value, id2: value2}
8173 * @return {BasicForm} this
8175 setValues : function(values){
8176 if(values instanceof Array){ // array of objects
8177 for(var i = 0, len = values.length; i < len; i++){
8179 var f = this.findField(v.id);
8181 f.setValue(v.value);
8182 if(this.trackResetOnLoad){
8183 f.originalValue = f.getValue();
8187 }else{ // object hash
8190 if(typeof values[id] != 'function' && (field = this.findField(id))){
8192 if (field.setFromData &&
8194 field.displayField &&
8195 // combos' with local stores can
8196 // be queried via setValue()
8197 // to set their value..
8198 (field.store && !field.store.isLocal)
8202 sd[field.valueField] = typeof(values[field.hiddenName]) == 'undefined' ? '' : values[field.hiddenName];
8203 sd[field.displayField] = typeof(values[field.name]) == 'undefined' ? '' : values[field.name];
8204 field.setFromData(sd);
8206 } else if(field.setFromData && (field.store && !field.store.isLocal)) {
8208 field.setFromData(values);
8211 field.setValue(values[id]);
8215 if(this.trackResetOnLoad){
8216 field.originalValue = field.getValue();
8222 //Roo.each(this.childForms || [], function (f) {
8223 // f.setValues(values);
8230 * Returns the fields in this form as an object with key/value pairs. If multiple fields exist with the same name
8231 * they are returned as an array.
8232 * @param {Boolean} asString
8235 getValues : function(asString){
8236 //if (this.childForms) {
8237 // copy values from the child forms
8238 // Roo.each(this.childForms, function (f) {
8239 // this.setValues(f.getValues());
8245 var fs = Roo.lib.Ajax.serializeForm(this.el.dom);
8246 if(asString === true){
8249 return Roo.urlDecode(fs);
8253 * Returns the fields in this form as an object with key/value pairs.
8254 * This differs from getValues as it calls getValue on each child item, rather than using dom data.
8257 getFieldValues : function(with_hidden)
8259 var items = this.getItems();
8261 items.each(function(f){
8267 var v = f.getValue();
8269 if (f.inputType =='radio') {
8270 if (typeof(ret[f.getName()]) == 'undefined') {
8271 ret[f.getName()] = ''; // empty..
8274 if (!f.el.dom.checked) {
8282 if(f.xtype == 'MoneyField'){
8283 ret[f.currencyName] = f.getCurrency();
8286 // not sure if this supported any more..
8287 if ((typeof(v) == 'object') && f.getRawValue) {
8288 v = f.getRawValue() ; // dates..
8290 // combo boxes where name != hiddenName...
8291 if (f.name !== false && f.name != '' && f.name != f.getName()) {
8292 ret[f.name] = f.getRawValue();
8294 ret[f.getName()] = v;
8301 * Clears all invalid messages in this form.
8302 * @return {BasicForm} this
8304 clearInvalid : function(){
8305 var items = this.getItems();
8307 items.each(function(f){
8316 * @return {BasicForm} this
8319 var items = this.getItems();
8320 items.each(function(f){
8324 Roo.each(this.childForms || [], function (f) {
8332 getItems : function()
8334 var r=new Roo.util.MixedCollection(false, function(o){
8335 return o.id || (o.id = Roo.id());
8337 var iter = function(el) {
8344 Roo.each(el.items,function(e) {
8353 hideFields : function(items)
8355 Roo.each(items, function(i){
8357 var f = this.findField(i);
8368 showFields : function(items)
8370 Roo.each(items, function(i){
8372 var f = this.findField(i);
8385 Roo.apply(Roo.bootstrap.Form, {
8412 top : Roo.DomHelper.append(Roo.get(document.body), { tag: "div", cls:"x-dlg-mask roo-form-top-mask" }, true),
8413 left : Roo.DomHelper.append(Roo.get(document.body), { tag: "div", cls:"x-dlg-mask roo-form-left-mask" }, true),
8414 bottom : Roo.DomHelper.append(Roo.get(document.body), { tag: "div", cls:"x-dlg-mask roo-form-bottom-mask" }, true),
8415 right : Roo.DomHelper.append(Roo.get(document.body), { tag: "div", cls:"x-dlg-mask roo-form-right-mask" }, true)
8418 this.maskEl.top.enableDisplayMode("block");
8419 this.maskEl.left.enableDisplayMode("block");
8420 this.maskEl.bottom.enableDisplayMode("block");
8421 this.maskEl.right.enableDisplayMode("block");
8423 this.toolTip = new Roo.bootstrap.Tooltip({
8424 cls : 'roo-form-error-popover',
8426 'left' : ['r-l', [-2,0], 'right'],
8427 'right' : ['l-r', [2,0], 'left'],
8428 'bottom' : ['tl-bl', [0,2], 'top'],
8429 'top' : [ 'bl-tl', [0,-2], 'bottom']
8433 this.toolTip.render(Roo.get(document.body));
8435 this.toolTip.el.enableDisplayMode("block");
8437 Roo.get(document.body).on('click', function(){
8441 Roo.get(document.body).on('touchstart', function(){
8445 this.isApplied = true
8448 mask : function(form, target)
8452 this.target = target;
8454 if(!this.form.errorMask || !target.el){
8458 var scrollable = this.target.el.findScrollableParent() || this.target.el.findParent('div.modal', 100, true) || Roo.get(document.body);
8460 Roo.log(scrollable);
8462 var ot = this.target.el.calcOffsetsTo(scrollable);
8464 var scrollTo = ot[1] - this.form.maskOffset;
8466 scrollTo = Math.min(scrollTo, scrollable.dom.scrollHeight);
8468 scrollable.scrollTo('top', scrollTo);
8470 var box = this.target.el.getBox();
8472 var zIndex = Roo.bootstrap.Modal.zIndex++;
8475 this.maskEl.top.setStyle('position', 'absolute');
8476 this.maskEl.top.setStyle('z-index', zIndex);
8477 this.maskEl.top.setSize(Roo.lib.Dom.getDocumentWidth(), box.y - this.padding);
8478 this.maskEl.top.setLeft(0);
8479 this.maskEl.top.setTop(0);
8480 this.maskEl.top.show();
8482 this.maskEl.left.setStyle('position', 'absolute');
8483 this.maskEl.left.setStyle('z-index', zIndex);
8484 this.maskEl.left.setSize(box.x - this.padding, box.height + this.padding * 2);
8485 this.maskEl.left.setLeft(0);
8486 this.maskEl.left.setTop(box.y - this.padding);
8487 this.maskEl.left.show();
8489 this.maskEl.bottom.setStyle('position', 'absolute');
8490 this.maskEl.bottom.setStyle('z-index', zIndex);
8491 this.maskEl.bottom.setSize(Roo.lib.Dom.getDocumentWidth(), Roo.lib.Dom.getDocumentHeight() - box.bottom - this.padding);
8492 this.maskEl.bottom.setLeft(0);
8493 this.maskEl.bottom.setTop(box.bottom + this.padding);
8494 this.maskEl.bottom.show();
8496 this.maskEl.right.setStyle('position', 'absolute');
8497 this.maskEl.right.setStyle('z-index', zIndex);
8498 this.maskEl.right.setSize(Roo.lib.Dom.getDocumentWidth() - box.right - this.padding, box.height + this.padding * 2);
8499 this.maskEl.right.setLeft(box.right + this.padding);
8500 this.maskEl.right.setTop(box.y - this.padding);
8501 this.maskEl.right.show();
8503 this.toolTip.bindEl = this.target.el;
8505 this.toolTip.el.setStyle('z-index', Roo.bootstrap.Modal.zIndex++);
8507 var tip = this.target.blankText;
8509 if(this.target.getValue() !== '' ) {
8511 if (this.target.invalidText.length) {
8512 tip = this.target.invalidText;
8513 } else if (this.target.regexText.length){
8514 tip = this.target.regexText;
8518 this.toolTip.show(tip);
8520 this.intervalID = window.setInterval(function() {
8521 Roo.bootstrap.Form.popover.unmask();
8524 window.onwheel = function(){ return false;};
8526 (function(){ this.isMasked = true; }).defer(500, this);
8532 if(!this.isApplied || !this.isMasked || !this.form || !this.target || !this.form.errorMask){
8536 this.maskEl.top.setStyle('position', 'absolute');
8537 this.maskEl.top.setSize(0, 0).setXY([0, 0]);
8538 this.maskEl.top.hide();
8540 this.maskEl.left.setStyle('position', 'absolute');
8541 this.maskEl.left.setSize(0, 0).setXY([0, 0]);
8542 this.maskEl.left.hide();
8544 this.maskEl.bottom.setStyle('position', 'absolute');
8545 this.maskEl.bottom.setSize(0, 0).setXY([0, 0]);
8546 this.maskEl.bottom.hide();
8548 this.maskEl.right.setStyle('position', 'absolute');
8549 this.maskEl.right.setSize(0, 0).setXY([0, 0]);
8550 this.maskEl.right.hide();
8552 this.toolTip.hide();
8554 this.toolTip.el.hide();
8556 window.onwheel = function(){ return true;};
8558 if(this.intervalID){
8559 window.clearInterval(this.intervalID);
8560 this.intervalID = false;
8563 this.isMasked = false;
8573 * Ext JS Library 1.1.1
8574 * Copyright(c) 2006-2007, Ext JS, LLC.
8576 * Originally Released Under LGPL - original licence link has changed is not relivant.
8579 * <script type="text/javascript">
8582 * @class Roo.form.VTypes
8583 * Overridable validation definitions. The validations provided are basic and intended to be easily customizable and extended.
8586 Roo.form.VTypes = function(){
8587 // closure these in so they are only created once.
8588 var alpha = /^[a-zA-Z_]+$/;
8589 var alphanum = /^[a-zA-Z0-9_]+$/;
8590 var email = /^([\w]+)(.[\w]+)*@([\w-]+\.){1,5}([A-Za-z]){2,24}$/;
8591 var url = /(((https?)|(ftp)):\/\/([\-\w]+\.)+\w{2,3}(\/[%\-\w]+(\.\w{2,})?)*(([\w\-\.\?\\\/+@&#;`~=%!]*)(\.\w{2,})?)*\/?)/i;
8593 // All these messages and functions are configurable
8596 * The function used to validate email addresses
8597 * @param {String} value The email address
8599 'email' : function(v){
8600 return email.test(v);
8603 * The error text to display when the email validation function returns false
8606 'emailText' : 'This field should be an e-mail address in the format "user@domain.com"',
8608 * The keystroke filter mask to be applied on email input
8611 'emailMask' : /[a-z0-9_\.\-@]/i,
8614 * The function used to validate URLs
8615 * @param {String} value The URL
8617 'url' : function(v){
8621 * The error text to display when the url validation function returns false
8624 'urlText' : 'This field should be a URL in the format "http:/'+'/www.domain.com"',
8627 * The function used to validate alpha values
8628 * @param {String} value The value
8630 'alpha' : function(v){
8631 return alpha.test(v);
8634 * The error text to display when the alpha validation function returns false
8637 'alphaText' : 'This field should only contain letters and _',
8639 * The keystroke filter mask to be applied on alpha input
8642 'alphaMask' : /[a-z_]/i,
8645 * The function used to validate alphanumeric values
8646 * @param {String} value The value
8648 'alphanum' : function(v){
8649 return alphanum.test(v);
8652 * The error text to display when the alphanumeric validation function returns false
8655 'alphanumText' : 'This field should only contain letters, numbers and _',
8657 * The keystroke filter mask to be applied on alphanumeric input
8660 'alphanumMask' : /[a-z0-9_]/i
8670 * @class Roo.bootstrap.Input
8671 * @extends Roo.bootstrap.Component
8672 * Bootstrap Input class
8673 * @cfg {Boolean} disabled is it disabled
8674 * @cfg {String} inputType button | checkbox | email | file | hidden | image | number | password | radio | range | reset | search | submit | text
8675 * @cfg {String} name name of the input
8676 * @cfg {string} fieldLabel - the label associated
8677 * @cfg {string} placeholder - placeholder to put in text.
8678 * @cfg {string} before - input group add on before
8679 * @cfg {string} after - input group add on after
8680 * @cfg {string} size - (lg|sm) or leave empty..
8681 * @cfg {Number} xs colspan out of 12 for mobile-sized screens
8682 * @cfg {Number} sm colspan out of 12 for tablet-sized screens
8683 * @cfg {Number} md colspan out of 12 for computer-sized screens
8684 * @cfg {Number} lg colspan out of 12 for large computer-sized screens
8685 * @cfg {string} value default value of the input
8686 * @cfg {Number} labelWidth set the width of label
8687 * @cfg {Number} labellg set the width of label (1-12)
8688 * @cfg {Number} labelmd set the width of label (1-12)
8689 * @cfg {Number} labelsm set the width of label (1-12)
8690 * @cfg {Number} labelxs set the width of label (1-12)
8691 * @cfg {String} labelAlign (top|left)
8692 * @cfg {Boolean} readOnly Specifies that the field should be read-only
8693 * @cfg {String} autocomplete - default is new-password see: https://developers.google.com/web/fundamentals/input/form/label-and-name-inputs?hl=en
8694 * @cfg {String} indicatorpos (left|right) default left
8695 * @cfg {String} capture (user|camera) use for file input only. (default empty)
8696 * @cfg {String} accept (image|video|audio) use for file input only. (default empty)
8698 * @cfg {String} align (left|center|right) Default left
8699 * @cfg {Boolean} forceFeedback (true|false) Default false
8702 * Create a new Input
8703 * @param {Object} config The config object
8706 Roo.bootstrap.Input = function(config){
8708 Roo.bootstrap.Input.superclass.constructor.call(this, config);
8713 * Fires when this field receives input focus.
8714 * @param {Roo.form.Field} this
8719 * Fires when this field loses input focus.
8720 * @param {Roo.form.Field} this
8725 * Fires when any key related to navigation (arrows, tab, enter, esc, etc.) is pressed. You can check
8726 * {@link Roo.EventObject#getKey} to determine which key was pressed.
8727 * @param {Roo.form.Field} this
8728 * @param {Roo.EventObject} e The event object
8733 * Fires just before the field blurs if the field value has changed.
8734 * @param {Roo.form.Field} this
8735 * @param {Mixed} newValue The new value
8736 * @param {Mixed} oldValue The original value
8741 * Fires after the field has been marked as invalid.
8742 * @param {Roo.form.Field} this
8743 * @param {String} msg The validation message
8748 * Fires after the field has been validated with no errors.
8749 * @param {Roo.form.Field} this
8754 * Fires after the key up
8755 * @param {Roo.form.Field} this
8756 * @param {Roo.EventObject} e The event Object
8762 Roo.extend(Roo.bootstrap.Input, Roo.bootstrap.Component, {
8764 * @cfg {String/Boolean} validationEvent The event that should initiate field validation. Set to false to disable
8765 automatic validation (defaults to "keyup").
8767 validationEvent : "keyup",
8769 * @cfg {Boolean} validateOnBlur Whether the field should validate when it loses focus (defaults to true).
8771 validateOnBlur : true,
8773 * @cfg {Number} validationDelay The length of time in milliseconds after user input begins until validation is initiated (defaults to 250)
8775 validationDelay : 250,
8777 * @cfg {String} focusClass The CSS class to use when the field receives focus (defaults to "x-form-focus")
8779 focusClass : "x-form-focus", // not needed???
8783 * @cfg {String} invalidClass The CSS class to use when marking a field invalid (defaults to "x-form-invalid")
8785 invalidClass : "has-warning",
8788 * @cfg {String} validClass The CSS class to use when marking a field valid (defaults to "x-form-invalid")
8790 validClass : "has-success",
8793 * @cfg {Boolean} hasFeedback (true|false) default true
8798 * @cfg {String} invalidFeedbackIcon The CSS class to use when create feedback icon (defaults to "x-form-invalid")
8800 invalidFeedbackClass : "glyphicon-warning-sign",
8803 * @cfg {String} validFeedbackIcon The CSS class to use when create feedback icon (defaults to "x-form-invalid")
8805 validFeedbackClass : "glyphicon-ok",
8808 * @cfg {Boolean} selectOnFocus True to automatically select any existing field text when the field receives input focus (defaults to false)
8810 selectOnFocus : false,
8813 * @cfg {String} maskRe An input mask regular expression that will be used to filter keystrokes that don't match (defaults to null)
8817 * @cfg {String} vtype A validation type name as defined in {@link Roo.form.VTypes} (defaults to null)
8822 * @cfg {Boolean} disableKeyFilter True to disable input keystroke filtering (defaults to false)
8824 disableKeyFilter : false,
8827 * @cfg {Boolean} disabled True to disable the field (defaults to false).
8831 * @cfg {Boolean} allowBlank False to validate that the value length > 0 (defaults to true)
8835 * @cfg {String} blankText Error text to display if the allow blank validation fails (defaults to "This field is required")
8837 blankText : "Please complete this mandatory field",
8840 * @cfg {Number} minLength Minimum input field length required (defaults to 0)
8844 * @cfg {Number} maxLength Maximum input field length allowed (defaults to Number.MAX_VALUE)
8846 maxLength : Number.MAX_VALUE,
8848 * @cfg {String} minLengthText Error text to display if the minimum length validation fails (defaults to "The minimum length for this field is {minLength}")
8850 minLengthText : "The minimum length for this field is {0}",
8852 * @cfg {String} maxLengthText Error text to display if the maximum length validation fails (defaults to "The maximum length for this field is {maxLength}")
8854 maxLengthText : "The maximum length for this field is {0}",
8858 * @cfg {Function} validator A custom validation function to be called during field validation (defaults to null).
8859 * If available, this function will be called only after the basic validators all return true, and will be passed the
8860 * current field value and expected to return boolean true if the value is valid or a string error message if invalid.
8864 * @cfg {RegExp} regex A JavaScript RegExp object to be tested against the field value during validation (defaults to null).
8865 * If available, this regex will be evaluated only after the basic validators all return true, and will be passed the
8866 * current field value. If the test fails, the field will be marked invalid using {@link #regexText}.
8870 * @cfg {String} regexText -- Depricated - use Invalid Text
8875 * @cfg {String} invalidText The error text to display if {@link #validator} test fails during validation (defaults to "")
8881 autocomplete: false,
8900 formatedValue : false,
8901 forceFeedback : false,
8903 indicatorpos : 'left',
8913 parentLabelAlign : function()
8916 while (parent.parent()) {
8917 parent = parent.parent();
8918 if (typeof(parent.labelAlign) !='undefined') {
8919 return parent.labelAlign;
8926 getAutoCreate : function()
8928 var align = (!this.labelAlign) ? this.parentLabelAlign() : this.labelAlign;
8934 if(this.inputType != 'hidden'){
8935 cfg.cls = 'form-group' //input-group
8941 type : this.inputType,
8943 cls : 'form-control',
8944 placeholder : this.placeholder || '',
8945 autocomplete : this.autocomplete || 'new-password'
8948 if(this.capture.length){
8949 input.capture = this.capture;
8952 if(this.accept.length){
8953 input.accept = this.accept + "/*";
8957 input.style = (typeof(input.style) == 'undefined') ? ('text-align:' + this.align) : (input.style + 'text-align:' + this.align);
8960 if(this.maxLength && this.maxLength != Number.MAX_VALUE){
8961 input.maxLength = this.maxLength;
8964 if (this.disabled) {
8965 input.disabled=true;
8968 if (this.readOnly) {
8969 input.readonly=true;
8973 input.name = this.name;
8977 input.cls += ' input-' + this.size;
8981 ['xs','sm','md','lg'].map(function(size){
8982 if (settings[size]) {
8983 cfg.cls += ' col-' + size + '-' + settings[size];
8987 var inputblock = input;
8991 cls: 'glyphicon form-control-feedback'
8994 if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank){
8997 cls : 'has-feedback',
9005 if (this.before || this.after) {
9008 cls : 'input-group',
9012 if (this.before && typeof(this.before) == 'string') {
9014 inputblock.cn.push({
9016 cls : 'roo-input-before input-group-addon',
9020 if (this.before && typeof(this.before) == 'object') {
9021 this.before = Roo.factory(this.before);
9023 inputblock.cn.push({
9025 cls : 'roo-input-before input-group-' +
9026 (this.before.xtype == 'Button' ? 'btn' : 'addon') //?? what about checkboxes - that looks like a bit of a hack thought?
9030 inputblock.cn.push(input);
9032 if (this.after && typeof(this.after) == 'string') {
9033 inputblock.cn.push({
9035 cls : 'roo-input-after input-group-addon',
9039 if (this.after && typeof(this.after) == 'object') {
9040 this.after = Roo.factory(this.after);
9042 inputblock.cn.push({
9044 cls : 'roo-input-after input-group-' +
9045 (this.after.xtype == 'Button' ? 'btn' : 'addon') //?? what about checkboxes - that looks like a bit of a hack thought?
9049 if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank){
9050 inputblock.cls += ' has-feedback';
9051 inputblock.cn.push(feedback);
9055 if (align ==='left' && this.fieldLabel.length) {
9057 cfg.cls += ' roo-form-group-label-left';
9062 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
9063 tooltip : 'This field is required'
9068 cls : 'control-label',
9069 html : this.fieldLabel
9080 var labelCfg = cfg.cn[1];
9081 var contentCfg = cfg.cn[2];
9083 if(this.indicatorpos == 'right'){
9088 cls : 'control-label',
9092 html : this.fieldLabel
9096 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
9097 tooltip : 'This field is required'
9110 labelCfg = cfg.cn[0];
9111 contentCfg = cfg.cn[1];
9115 if(this.labelWidth > 12){
9116 labelCfg.style = "width: " + this.labelWidth + 'px';
9119 if(this.labelWidth < 13 && this.labelmd == 0){
9120 this.labelmd = this.labelWidth;
9123 if(this.labellg > 0){
9124 labelCfg.cls += ' col-lg-' + this.labellg;
9125 contentCfg.cls += ' col-lg-' + (12 - this.labellg);
9128 if(this.labelmd > 0){
9129 labelCfg.cls += ' col-md-' + this.labelmd;
9130 contentCfg.cls += ' col-md-' + (12 - this.labelmd);
9133 if(this.labelsm > 0){
9134 labelCfg.cls += ' col-sm-' + this.labelsm;
9135 contentCfg.cls += ' col-sm-' + (12 - this.labelsm);
9138 if(this.labelxs > 0){
9139 labelCfg.cls += ' col-xs-' + this.labelxs;
9140 contentCfg.cls += ' col-xs-' + (12 - this.labelxs);
9144 } else if ( this.fieldLabel.length) {
9149 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
9150 tooltip : 'This field is required'
9154 //cls : 'input-group-addon',
9155 html : this.fieldLabel
9163 if(this.indicatorpos == 'right'){
9168 //cls : 'input-group-addon',
9169 html : this.fieldLabel
9174 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
9175 tooltip : 'This field is required'
9195 if (this.parentType === 'Navbar' && this.parent().bar) {
9196 cfg.cls += ' navbar-form';
9199 if (this.parentType === 'NavGroup') {
9200 cfg.cls += ' navbar-form';
9208 * return the real input element.
9210 inputEl: function ()
9212 return this.el.select('input.form-control',true).first();
9215 tooltipEl : function()
9217 return this.inputEl();
9220 indicatorEl : function()
9222 var indicator = this.el.select('i.roo-required-indicator',true).first();
9232 setDisabled : function(v)
9234 var i = this.inputEl().dom;
9236 i.removeAttribute('disabled');
9240 i.setAttribute('disabled','true');
9242 initEvents : function()
9245 this.inputEl().on("keydown" , this.fireKey, this);
9246 this.inputEl().on("focus", this.onFocus, this);
9247 this.inputEl().on("blur", this.onBlur, this);
9249 this.inputEl().relayEvent('keyup', this);
9251 this.indicator = this.indicatorEl();
9254 this.indicator.addClass(this.indicatorpos == 'right' ? 'hidden' : 'invisible'); // changed from invisible??? -
9257 // reference to original value for reset
9258 this.originalValue = this.getValue();
9259 //Roo.form.TextField.superclass.initEvents.call(this);
9260 if(this.validationEvent == 'keyup'){
9261 this.validationTask = new Roo.util.DelayedTask(this.validate, this);
9262 this.inputEl().on('keyup', this.filterValidation, this);
9264 else if(this.validationEvent !== false){
9265 this.inputEl().on(this.validationEvent, this.validate, this, {buffer: this.validationDelay});
9268 if(this.selectOnFocus){
9269 this.on("focus", this.preFocus, this);
9272 if(this.maskRe || (this.vtype && this.disableKeyFilter !== true && (this.maskRe = Roo.form.VTypes[this.vtype+'Mask']))){
9273 this.inputEl().on("keypress", this.filterKeys, this);
9275 this.inputEl().relayEvent('keypress', this);
9278 this.el.on("keyup", this.onKeyUp, this, {buffer:50});
9279 this.el.on("click", this.autoSize, this);
9282 if(this.inputEl().is('input[type=password]') && Roo.isSafari){
9283 this.inputEl().on('keydown', this.SafariOnKeyDown, this);
9286 if (typeof(this.before) == 'object') {
9287 this.before.render(this.el.select('.roo-input-before',true).first());
9289 if (typeof(this.after) == 'object') {
9290 this.after.render(this.el.select('.roo-input-after',true).first());
9293 this.inputEl().on('change', this.onChange, this);
9296 filterValidation : function(e){
9297 if(!e.isNavKeyPress()){
9298 this.validationTask.delay(this.validationDelay);
9302 * Validates the field value
9303 * @return {Boolean} True if the value is valid, else false
9305 validate : function(){
9306 //if(this.disabled || this.validateValue(this.processValue(this.getRawValue()))){
9307 if(this.disabled || this.validateValue(this.getRawValue())){
9318 * Validates a value according to the field's validation rules and marks the field as invalid
9319 * if the validation fails
9320 * @param {Mixed} value The value to validate
9321 * @return {Boolean} True if the value is valid, else false
9323 validateValue : function(value)
9325 if(this.getVisibilityEl().hasClass('hidden')){
9329 if(value.length < 1) { // if it's blank
9330 if(this.allowBlank){
9336 if(value.length < this.minLength){
9339 if(value.length > this.maxLength){
9343 var vt = Roo.form.VTypes;
9344 if(!vt[this.vtype](value, this)){
9348 if(typeof this.validator == "function"){
9349 var msg = this.validator(value);
9353 if (typeof(msg) == 'string') {
9354 this.invalidText = msg;
9358 if(this.regex && !this.regex.test(value)){
9366 fireKey : function(e){
9367 //Roo.log('field ' + e.getKey());
9368 if(e.isNavKeyPress()){
9369 this.fireEvent("specialkey", this, e);
9372 focus : function (selectText){
9374 this.inputEl().focus();
9375 if(selectText === true){
9376 this.inputEl().dom.select();
9382 onFocus : function(){
9383 if(!Roo.isOpera && this.focusClass){ // don't touch in Opera
9384 // this.el.addClass(this.focusClass);
9387 this.hasFocus = true;
9388 this.startValue = this.getValue();
9389 this.fireEvent("focus", this);
9393 beforeBlur : Roo.emptyFn,
9397 onBlur : function(){
9399 if(!Roo.isOpera && this.focusClass){ // don't touch in Opera
9400 //this.el.removeClass(this.focusClass);
9402 this.hasFocus = false;
9403 if(this.validationEvent !== false && this.validateOnBlur && this.validationEvent != "blur"){
9406 var v = this.getValue();
9407 if(String(v) !== String(this.startValue)){
9408 this.fireEvent('change', this, v, this.startValue);
9410 this.fireEvent("blur", this);
9413 onChange : function(e)
9415 var v = this.getValue();
9416 if(String(v) !== String(this.startValue)){
9417 this.fireEvent('change', this, v, this.startValue);
9423 * Resets the current field value to the originally loaded value and clears any validation messages
9426 this.setValue(this.originalValue);
9430 * Returns the name of the field
9431 * @return {Mixed} name The name field
9433 getName: function(){
9437 * Returns the normalized data value (undefined or emptyText will be returned as ''). To return the raw value see {@link #getRawValue}.
9438 * @return {Mixed} value The field value
9440 getValue : function(){
9442 var v = this.inputEl().getValue();
9447 * Returns the raw data value which may or may not be a valid, defined value. To return a normalized value see {@link #getValue}.
9448 * @return {Mixed} value The field value
9450 getRawValue : function(){
9451 var v = this.inputEl().getValue();
9457 * Sets the underlying DOM field's value directly, bypassing validation. To set the value with validation see {@link #setValue}.
9458 * @param {Mixed} value The value to set
9460 setRawValue : function(v){
9461 return this.inputEl().dom.value = (v === null || v === undefined ? '' : v);
9464 selectText : function(start, end){
9465 var v = this.getRawValue();
9467 start = start === undefined ? 0 : start;
9468 end = end === undefined ? v.length : end;
9469 var d = this.inputEl().dom;
9470 if(d.setSelectionRange){
9471 d.setSelectionRange(start, end);
9472 }else if(d.createTextRange){
9473 var range = d.createTextRange();
9474 range.moveStart("character", start);
9475 range.moveEnd("character", v.length-end);
9482 * Sets a data value into the field and validates it. To set the value directly without validation see {@link #setRawValue}.
9483 * @param {Mixed} value The value to set
9485 setValue : function(v){
9488 this.inputEl().dom.value = (v === null || v === undefined ? '' : v);
9494 processValue : function(value){
9495 if(this.stripCharsRe){
9496 var newValue = value.replace(this.stripCharsRe, '');
9497 if(newValue !== value){
9498 this.setRawValue(newValue);
9505 preFocus : function(){
9507 if(this.selectOnFocus){
9508 this.inputEl().dom.select();
9511 filterKeys : function(e){
9513 if(!Roo.isIE && (e.isNavKeyPress() || k == e.BACKSPACE || (k == e.DELETE && e.button == -1))){
9516 var c = e.getCharCode(), cc = String.fromCharCode(c);
9517 if(Roo.isIE && (e.isSpecialKey() || !cc)){
9520 if(!this.maskRe.test(cc)){
9525 * Clear any invalid styles/messages for this field
9527 clearInvalid : function(){
9529 if(!this.el || this.preventMark){ // not rendered
9534 this.el.removeClass(this.invalidClass);
9536 if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank){
9538 var feedback = this.el.select('.form-control-feedback', true).first();
9541 this.el.select('.form-control-feedback', true).first().removeClass(this.invalidFeedbackClass);
9547 this.indicator.removeClass('visible');
9548 this.indicator.addClass(this.indicatorpos == 'right' ? 'hidden' : 'invisible');
9551 this.fireEvent('valid', this);
9555 * Mark this field as valid
9557 markValid : function()
9559 if(!this.el || this.preventMark){ // not rendered...
9563 this.el.removeClass([this.invalidClass, this.validClass]);
9565 var feedback = this.el.select('.form-control-feedback', true).first();
9568 this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
9572 this.indicator.removeClass('visible');
9573 this.indicator.addClass(this.indicatorpos == 'right' ? 'hidden' : 'invisible');
9580 if(this.allowBlank && !this.getRawValue().length){
9584 this.el.addClass(this.validClass);
9586 if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank && (this.getValue().length || this.forceFeedback)){
9588 var feedback = this.el.select('.form-control-feedback', true).first();
9591 this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
9592 this.el.select('.form-control-feedback', true).first().addClass([this.validFeedbackClass]);
9597 this.fireEvent('valid', this);
9601 * Mark this field as invalid
9602 * @param {String} msg The validation message
9604 markInvalid : function(msg)
9606 if(!this.el || this.preventMark){ // not rendered
9610 this.el.removeClass([this.invalidClass, this.validClass]);
9612 var feedback = this.el.select('.form-control-feedback', true).first();
9615 this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
9622 if(this.allowBlank && !this.getRawValue().length){
9627 this.indicator.removeClass(this.indicatorpos == 'right' ? 'hidden' : 'invisible');
9628 this.indicator.addClass('visible');
9631 this.el.addClass(this.invalidClass);
9633 if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank){
9635 var feedback = this.el.select('.form-control-feedback', true).first();
9638 this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
9640 if(this.getValue().length || this.forceFeedback){
9641 this.el.select('.form-control-feedback', true).first().addClass([this.invalidFeedbackClass]);
9648 this.fireEvent('invalid', this, msg);
9651 SafariOnKeyDown : function(event)
9653 // this is a workaround for a password hang bug on chrome/ webkit.
9654 if (this.inputEl().dom.type != 'password') {
9658 var isSelectAll = false;
9660 if(this.inputEl().dom.selectionEnd > 0){
9661 isSelectAll = (this.inputEl().dom.selectionEnd - this.inputEl().dom.selectionStart - this.getValue().length == 0) ? true : false;
9663 if(((event.getKey() == 8 || event.getKey() == 46) && this.getValue().length ==1)){ // backspace and delete key
9664 event.preventDefault();
9669 if(isSelectAll && event.getCharCode() > 31 && !event.ctrlKey) { // not backspace and delete key (or ctrl-v)
9671 event.preventDefault();
9672 // this is very hacky as keydown always get's upper case.
9674 var cc = String.fromCharCode(event.getCharCode());
9675 this.setValue( event.shiftKey ? cc : cc.toLowerCase());
9679 adjustWidth : function(tag, w){
9680 tag = tag.toLowerCase();
9681 if(typeof w == 'number' && Roo.isStrict && !Roo.isSafari){
9682 if(Roo.isIE && (tag == 'input' || tag == 'textarea')){
9686 if(tag == 'textarea'){
9689 }else if(Roo.isOpera){
9693 if(tag == 'textarea'){
9701 setFieldLabel : function(v)
9708 var ar = this.el.select('label > span',true);
9710 if (ar.elements.length) {
9711 this.el.select('label > span',true).first().dom.innerHTML = (v === null || v === undefined ? '' : v);
9712 this.fieldLabel = v;
9716 var br = this.el.select('label',true);
9718 if(br.elements.length) {
9719 this.el.select('label',true).first().dom.innerHTML = (v === null || v === undefined ? '' : v);
9720 this.fieldLabel = v;
9724 Roo.log('Cannot Found any of label > span || label in input');
9728 this.el.select('label',true).first().dom.innerHTML = (v === null || v === undefined ? '' : v);
9729 this.fieldLabel = v;
9744 * @class Roo.bootstrap.TextArea
9745 * @extends Roo.bootstrap.Input
9746 * Bootstrap TextArea class
9747 * @cfg {Number} cols Specifies the visible width of a text area
9748 * @cfg {Number} rows Specifies the visible number of lines in a text area
9749 * @cfg {string} wrap (soft|hard)Specifies how the text in a text area is to be wrapped when submitted in a form
9750 * @cfg {string} resize (none|both|horizontal|vertical|inherit|initial)
9751 * @cfg {string} html text
9754 * Create a new TextArea
9755 * @param {Object} config The config object
9758 Roo.bootstrap.TextArea = function(config){
9759 Roo.bootstrap.TextArea.superclass.constructor.call(this, config);
9763 Roo.extend(Roo.bootstrap.TextArea, Roo.bootstrap.Input, {
9773 getAutoCreate : function(){
9775 var align = (!this.labelAlign) ? this.parentLabelAlign() : this.labelAlign;
9781 if(this.inputType != 'hidden'){
9782 cfg.cls = 'form-group' //input-group
9790 value : this.value || '',
9791 html: this.html || '',
9792 cls : 'form-control',
9793 placeholder : this.placeholder || ''
9797 if(this.maxLength && this.maxLength != Number.MAX_VALUE){
9798 input.maxLength = this.maxLength;
9802 input.style = (typeof(input.style) == 'undefined') ? 'resize:' + this.resize : input.style + 'resize:' + this.resize;
9806 input.cols = this.cols;
9809 if (this.readOnly) {
9810 input.readonly = true;
9814 input.name = this.name;
9818 input.cls = (typeof(input.cls) == 'undefined') ? 'input-' + this.size : input.cls + ' input-' + this.size;
9822 ['xs','sm','md','lg'].map(function(size){
9823 if (settings[size]) {
9824 cfg.cls += ' col-' + size + '-' + settings[size];
9828 var inputblock = input;
9830 if(this.hasFeedback && !this.allowBlank){
9834 cls: 'glyphicon form-control-feedback'
9838 cls : 'has-feedback',
9847 if (this.before || this.after) {
9850 cls : 'input-group',
9854 inputblock.cn.push({
9856 cls : 'input-group-addon',
9861 inputblock.cn.push(input);
9863 if(this.hasFeedback && !this.allowBlank){
9864 inputblock.cls += ' has-feedback';
9865 inputblock.cn.push(feedback);
9869 inputblock.cn.push({
9871 cls : 'input-group-addon',
9878 if (align ==='left' && this.fieldLabel.length) {
9883 cls : 'control-label',
9884 html : this.fieldLabel
9895 if(this.labelWidth > 12){
9896 cfg.cn[0].style = "width: " + this.labelWidth + 'px';
9899 if(this.labelWidth < 13 && this.labelmd == 0){
9900 this.labelmd = this.labelWidth;
9903 if(this.labellg > 0){
9904 cfg.cn[0].cls += ' col-lg-' + this.labellg;
9905 cfg.cn[1].cls += ' col-lg-' + (12 - this.labellg);
9908 if(this.labelmd > 0){
9909 cfg.cn[0].cls += ' col-md-' + this.labelmd;
9910 cfg.cn[1].cls += ' col-md-' + (12 - this.labelmd);
9913 if(this.labelsm > 0){
9914 cfg.cn[0].cls += ' col-sm-' + this.labelsm;
9915 cfg.cn[1].cls += ' col-sm-' + (12 - this.labelsm);
9918 if(this.labelxs > 0){
9919 cfg.cn[0].cls += ' col-xs-' + this.labelxs;
9920 cfg.cn[1].cls += ' col-xs-' + (12 - this.labelxs);
9923 } else if ( this.fieldLabel.length) {
9928 //cls : 'input-group-addon',
9929 html : this.fieldLabel
9947 if (this.disabled) {
9948 input.disabled=true;
9955 * return the real textarea element.
9957 inputEl: function ()
9959 return this.el.select('textarea.form-control',true).first();
9963 * Clear any invalid styles/messages for this field
9965 clearInvalid : function()
9968 if(!this.el || this.preventMark){ // not rendered
9972 var label = this.el.select('label', true).first();
9973 var icon = this.el.select('i.fa-star', true).first();
9979 this.el.removeClass(this.invalidClass);
9981 if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank){
9983 var feedback = this.el.select('.form-control-feedback', true).first();
9986 this.el.select('.form-control-feedback', true).first().removeClass(this.invalidFeedbackClass);
9991 this.fireEvent('valid', this);
9995 * Mark this field as valid
9997 markValid : function()
9999 if(!this.el || this.preventMark){ // not rendered
10003 this.el.removeClass([this.invalidClass, this.validClass]);
10005 var feedback = this.el.select('.form-control-feedback', true).first();
10008 this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
10011 if(this.disabled || this.allowBlank){
10015 var label = this.el.select('label', true).first();
10016 var icon = this.el.select('i.fa-star', true).first();
10022 this.el.addClass(this.validClass);
10024 if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank && (this.getValue().length || this.forceFeedback)){
10026 var feedback = this.el.select('.form-control-feedback', true).first();
10029 this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
10030 this.el.select('.form-control-feedback', true).first().addClass([this.validFeedbackClass]);
10035 this.fireEvent('valid', this);
10039 * Mark this field as invalid
10040 * @param {String} msg The validation message
10042 markInvalid : function(msg)
10044 if(!this.el || this.preventMark){ // not rendered
10048 this.el.removeClass([this.invalidClass, this.validClass]);
10050 var feedback = this.el.select('.form-control-feedback', true).first();
10053 this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
10056 if(this.disabled || this.allowBlank){
10060 var label = this.el.select('label', true).first();
10061 var icon = this.el.select('i.fa-star', true).first();
10063 if(!this.getValue().length && label && !icon){
10064 this.el.createChild({
10066 cls : 'text-danger fa fa-lg fa-star',
10067 tooltip : 'This field is required',
10068 style : 'margin-right:5px;'
10072 this.el.addClass(this.invalidClass);
10074 if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank){
10076 var feedback = this.el.select('.form-control-feedback', true).first();
10079 this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
10081 if(this.getValue().length || this.forceFeedback){
10082 this.el.select('.form-control-feedback', true).first().addClass([this.invalidFeedbackClass]);
10089 this.fireEvent('invalid', this, msg);
10097 * trigger field - base class for combo..
10102 * @class Roo.bootstrap.TriggerField
10103 * @extends Roo.bootstrap.Input
10104 * Provides a convenient wrapper for TextFields that adds a clickable trigger button (looks like a combobox by default).
10105 * The trigger has no default action, so you must assign a function to implement the trigger click handler by
10106 * overriding {@link #onTriggerClick}. You can create a TriggerField directly, as it renders exactly like a combobox
10107 * for which you can provide a custom implementation. For example:
10109 var trigger = new Roo.bootstrap.TriggerField();
10110 trigger.onTriggerClick = myTriggerFn;
10111 trigger.applyTo('my-field');
10114 * However, in general you will most likely want to use TriggerField as the base class for a reusable component.
10115 * {@link Roo.bootstrap.DateField} and {@link Roo.bootstrap.ComboBox} are perfect examples of this.
10116 * @cfg {String} triggerClass An additional CSS class used to style the trigger button. The trigger will always get the
10117 * class 'x-form-trigger' by default and triggerClass will be <b>appended</b> if specified.
10118 * @cfg {String} caret (search|calendar) a fontawesome for the trigger icon see http://fortawesome.github.io/Font-Awesome/icons/
10121 * Create a new TriggerField.
10122 * @param {Object} config Configuration options (valid {@Roo.bootstrap.Input} config options will also be applied
10123 * to the base TextField)
10125 Roo.bootstrap.TriggerField = function(config){
10126 this.mimicing = false;
10127 Roo.bootstrap.TriggerField.superclass.constructor.call(this, config);
10130 Roo.extend(Roo.bootstrap.TriggerField, Roo.bootstrap.Input, {
10132 * @cfg {String} triggerClass A CSS class to apply to the trigger
10135 * @cfg {Boolean} hideTrigger True to hide the trigger element and display only the base text field (defaults to false)
10140 * @cfg {Boolean} removable (true|false) special filter default false
10144 /** @cfg {Boolean} grow @hide */
10145 /** @cfg {Number} growMin @hide */
10146 /** @cfg {Number} growMax @hide */
10152 autoSize: Roo.emptyFn,
10156 deferHeight : true,
10159 actionMode : 'wrap',
10164 getAutoCreate : function(){
10166 var align = this.labelAlign || this.parentLabelAlign();
10171 cls: 'form-group' //input-group
10178 type : this.inputType,
10179 cls : 'form-control',
10180 autocomplete: 'new-password',
10181 placeholder : this.placeholder || ''
10185 input.name = this.name;
10188 input.cls += ' input-' + this.size;
10191 if (this.disabled) {
10192 input.disabled=true;
10195 var inputblock = input;
10197 if(this.hasFeedback && !this.allowBlank){
10201 cls: 'glyphicon form-control-feedback'
10204 if(this.removable && !this.editable && !this.tickable){
10206 cls : 'has-feedback',
10212 cls : 'roo-combo-removable-btn close'
10219 cls : 'has-feedback',
10228 if(this.removable && !this.editable && !this.tickable){
10230 cls : 'roo-removable',
10236 cls : 'roo-combo-removable-btn close'
10243 if (this.before || this.after) {
10246 cls : 'input-group',
10250 inputblock.cn.push({
10252 cls : 'input-group-addon',
10257 inputblock.cn.push(input);
10259 if(this.hasFeedback && !this.allowBlank){
10260 inputblock.cls += ' has-feedback';
10261 inputblock.cn.push(feedback);
10265 inputblock.cn.push({
10267 cls : 'input-group-addon',
10280 cls: 'form-hidden-field'
10294 cls: 'form-hidden-field'
10298 cls: 'roo-select2-choices',
10302 cls: 'roo-select2-search-field',
10315 cls: 'roo-select2-container input-group',
10320 // cls: 'typeahead typeahead-long dropdown-menu',
10321 // style: 'display:none'
10326 if(!this.multiple && this.showToggleBtn){
10332 if (this.caret != false) {
10335 cls: 'fa fa-' + this.caret
10342 cls : 'input-group-addon btn dropdown-toggle',
10347 cls: 'combobox-clear',
10361 combobox.cls += ' roo-select2-container-multi';
10364 if (align ==='left' && this.fieldLabel.length) {
10366 cfg.cls += ' roo-form-group-label-left';
10371 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
10372 tooltip : 'This field is required'
10377 cls : 'control-label',
10378 html : this.fieldLabel
10390 var labelCfg = cfg.cn[1];
10391 var contentCfg = cfg.cn[2];
10393 if(this.indicatorpos == 'right'){
10398 cls : 'control-label',
10402 html : this.fieldLabel
10406 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
10407 tooltip : 'This field is required'
10420 labelCfg = cfg.cn[0];
10421 contentCfg = cfg.cn[1];
10424 if(this.labelWidth > 12){
10425 labelCfg.style = "width: " + this.labelWidth + 'px';
10428 if(this.labelWidth < 13 && this.labelmd == 0){
10429 this.labelmd = this.labelWidth;
10432 if(this.labellg > 0){
10433 labelCfg.cls += ' col-lg-' + this.labellg;
10434 contentCfg.cls += ' col-lg-' + (12 - this.labellg);
10437 if(this.labelmd > 0){
10438 labelCfg.cls += ' col-md-' + this.labelmd;
10439 contentCfg.cls += ' col-md-' + (12 - this.labelmd);
10442 if(this.labelsm > 0){
10443 labelCfg.cls += ' col-sm-' + this.labelsm;
10444 contentCfg.cls += ' col-sm-' + (12 - this.labelsm);
10447 if(this.labelxs > 0){
10448 labelCfg.cls += ' col-xs-' + this.labelxs;
10449 contentCfg.cls += ' col-xs-' + (12 - this.labelxs);
10452 } else if ( this.fieldLabel.length) {
10453 // Roo.log(" label");
10457 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
10458 tooltip : 'This field is required'
10462 //cls : 'input-group-addon',
10463 html : this.fieldLabel
10471 if(this.indicatorpos == 'right'){
10479 html : this.fieldLabel
10483 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
10484 tooltip : 'This field is required'
10497 // Roo.log(" no label && no align");
10504 ['xs','sm','md','lg'].map(function(size){
10505 if (settings[size]) {
10506 cfg.cls += ' col-' + size + '-' + settings[size];
10517 onResize : function(w, h){
10518 // Roo.bootstrap.TriggerField.superclass.onResize.apply(this, arguments);
10519 // if(typeof w == 'number'){
10520 // var x = w - this.trigger.getWidth();
10521 // this.inputEl().setWidth(this.adjustWidth('input', x));
10522 // this.trigger.setStyle('left', x+'px');
10527 adjustSize : Roo.BoxComponent.prototype.adjustSize,
10530 getResizeEl : function(){
10531 return this.inputEl();
10535 getPositionEl : function(){
10536 return this.inputEl();
10540 alignErrorIcon : function(){
10541 this.errorIcon.alignTo(this.inputEl(), 'tl-tr', [2, 0]);
10545 initEvents : function(){
10549 Roo.bootstrap.TriggerField.superclass.initEvents.call(this);
10550 //this.wrap = this.el.wrap({cls: "x-form-field-wrap"});
10551 if(!this.multiple && this.showToggleBtn){
10552 this.trigger = this.el.select('span.dropdown-toggle',true).first();
10553 if(this.hideTrigger){
10554 this.trigger.setDisplayed(false);
10556 this.trigger.on("click", this.onTriggerClick, this, {preventDefault:true});
10560 this.inputEl().on("click", this.onTriggerClick, this, {preventDefault:true});
10563 if(this.removable && !this.editable && !this.tickable){
10564 var close = this.closeTriggerEl();
10567 close.setVisibilityMode(Roo.Element.DISPLAY).hide();
10568 close.on('click', this.removeBtnClick, this, close);
10572 //this.trigger.addClassOnOver('x-form-trigger-over');
10573 //this.trigger.addClassOnClick('x-form-trigger-click');
10576 // this.wrap.setWidth(this.el.getWidth()+this.trigger.getWidth());
10580 closeTriggerEl : function()
10582 var close = this.el.select('.roo-combo-removable-btn', true).first();
10583 return close ? close : false;
10586 removeBtnClick : function(e, h, el)
10588 e.preventDefault();
10590 if(this.fireEvent("remove", this) !== false){
10592 this.fireEvent("afterremove", this)
10596 createList : function()
10598 this.list = Roo.get(document.body).createChild({
10600 cls: 'typeahead typeahead-long dropdown-menu',
10601 style: 'display:none'
10604 this.list.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';;
10609 initTrigger : function(){
10614 onDestroy : function(){
10616 this.trigger.removeAllListeners();
10617 // this.trigger.remove();
10620 // this.wrap.remove();
10622 Roo.bootstrap.TriggerField.superclass.onDestroy.call(this);
10626 onFocus : function(){
10627 Roo.bootstrap.TriggerField.superclass.onFocus.call(this);
10629 if(!this.mimicing){
10630 this.wrap.addClass('x-trigger-wrap-focus');
10631 this.mimicing = true;
10632 Roo.get(Roo.isIE ? document.body : document).on("mousedown", this.mimicBlur, this);
10633 if(this.monitorTab){
10634 this.el.on("keydown", this.checkTab, this);
10641 checkTab : function(e){
10642 if(e.getKey() == e.TAB){
10643 this.triggerBlur();
10648 onBlur : function(){
10653 mimicBlur : function(e, t){
10655 if(!this.wrap.contains(t) && this.validateBlur()){
10656 this.triggerBlur();
10662 triggerBlur : function(){
10663 this.mimicing = false;
10664 Roo.get(Roo.isIE ? document.body : document).un("mousedown", this.mimicBlur);
10665 if(this.monitorTab){
10666 this.el.un("keydown", this.checkTab, this);
10668 //this.wrap.removeClass('x-trigger-wrap-focus');
10669 Roo.bootstrap.TriggerField.superclass.onBlur.call(this);
10673 // This should be overriden by any subclass that needs to check whether or not the field can be blurred.
10674 validateBlur : function(e, t){
10679 onDisable : function(){
10680 this.inputEl().dom.disabled = true;
10681 //Roo.bootstrap.TriggerField.superclass.onDisable.call(this);
10683 // this.wrap.addClass('x-item-disabled');
10688 onEnable : function(){
10689 this.inputEl().dom.disabled = false;
10690 //Roo.bootstrap.TriggerField.superclass.onEnable.call(this);
10692 // this.el.removeClass('x-item-disabled');
10697 onShow : function(){
10698 var ae = this.getActionEl();
10701 ae.dom.style.display = '';
10702 ae.dom.style.visibility = 'visible';
10708 onHide : function(){
10709 var ae = this.getActionEl();
10710 ae.dom.style.display = 'none';
10714 * The function that should handle the trigger's click event. This method does nothing by default until overridden
10715 * by an implementing function.
10717 * @param {EventObject} e
10719 onTriggerClick : Roo.emptyFn
10723 * Ext JS Library 1.1.1
10724 * Copyright(c) 2006-2007, Ext JS, LLC.
10726 * Originally Released Under LGPL - original licence link has changed is not relivant.
10729 * <script type="text/javascript">
10734 * @class Roo.data.SortTypes
10736 * Defines the default sorting (casting?) comparison functions used when sorting data.
10738 Roo.data.SortTypes = {
10740 * Default sort that does nothing
10741 * @param {Mixed} s The value being converted
10742 * @return {Mixed} The comparison value
10744 none : function(s){
10749 * The regular expression used to strip tags
10753 stripTagsRE : /<\/?[^>]+>/gi,
10756 * Strips all HTML tags to sort on text only
10757 * @param {Mixed} s The value being converted
10758 * @return {String} The comparison value
10760 asText : function(s){
10761 return String(s).replace(this.stripTagsRE, "");
10765 * Strips all HTML tags to sort on text only - Case insensitive
10766 * @param {Mixed} s The value being converted
10767 * @return {String} The comparison value
10769 asUCText : function(s){
10770 return String(s).toUpperCase().replace(this.stripTagsRE, "");
10774 * Case insensitive string
10775 * @param {Mixed} s The value being converted
10776 * @return {String} The comparison value
10778 asUCString : function(s) {
10779 return String(s).toUpperCase();
10784 * @param {Mixed} s The value being converted
10785 * @return {Number} The comparison value
10787 asDate : function(s) {
10791 if(s instanceof Date){
10792 return s.getTime();
10794 return Date.parse(String(s));
10799 * @param {Mixed} s The value being converted
10800 * @return {Float} The comparison value
10802 asFloat : function(s) {
10803 var val = parseFloat(String(s).replace(/,/g, ""));
10812 * @param {Mixed} s The value being converted
10813 * @return {Number} The comparison value
10815 asInt : function(s) {
10816 var val = parseInt(String(s).replace(/,/g, ""));
10824 * Ext JS Library 1.1.1
10825 * Copyright(c) 2006-2007, Ext JS, LLC.
10827 * Originally Released Under LGPL - original licence link has changed is not relivant.
10830 * <script type="text/javascript">
10834 * @class Roo.data.Record
10835 * Instances of this class encapsulate both record <em>definition</em> information, and record
10836 * <em>value</em> information for use in {@link Roo.data.Store} objects, or any code which needs
10837 * to access Records cached in an {@link Roo.data.Store} object.<br>
10839 * Constructors for this class are generated by passing an Array of field definition objects to {@link #create}.
10840 * Instances are usually only created by {@link Roo.data.Reader} implementations when processing unformatted data
10843 * Record objects generated by this constructor inherit all the methods of Roo.data.Record listed below.
10845 * This constructor should not be used to create Record objects. Instead, use the constructor generated by
10846 * {@link #create}. The parameters are the same.
10847 * @param {Array} data An associative Array of data values keyed by the field name.
10848 * @param {Object} id (Optional) The id of the record. This id should be unique, and is used by the
10849 * {@link Roo.data.Store} object which owns the Record to index its collection of Records. If
10850 * not specified an integer id is generated.
10852 Roo.data.Record = function(data, id){
10853 this.id = (id || id === 0) ? id : ++Roo.data.Record.AUTO_ID;
10858 * Generate a constructor for a specific record layout.
10859 * @param {Array} o An Array of field definition objects which specify field names, and optionally,
10860 * data types, and a mapping for an {@link Roo.data.Reader} to extract the field's value from a data object.
10861 * Each field definition object may contain the following properties: <ul>
10862 * <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,
10863 * for example the <em>dataIndex</em> property in column definition objects passed to {@link Roo.grid.ColumnModel}</p></li>
10864 * <li><b>mapping</b> : String<p style="margin-left:1em">(Optional) A path specification for use by the {@link Roo.data.Reader} implementation
10865 * that is creating the Record to access the data value from the data object. If an {@link Roo.data.JsonReader}
10866 * is being used, then this is a string containing the javascript expression to reference the data relative to
10867 * the record item's root. If an {@link Roo.data.XmlReader} is being used, this is an {@link Roo.DomQuery} path
10868 * to the data item relative to the record element. If the mapping expression is the same as the field name,
10869 * this may be omitted.</p></li>
10870 * <li><b>type</b> : String<p style="margin-left:1em">(Optional) The data type for conversion to displayable value. Possible values are
10871 * <ul><li>auto (Default, implies no conversion)</li>
10876 * <li>date</li></ul></p></li>
10877 * <li><b>sortType</b> : Mixed<p style="margin-left:1em">(Optional) A member of {@link Roo.data.SortTypes}.</p></li>
10878 * <li><b>sortDir</b> : String<p style="margin-left:1em">(Optional) Initial direction to sort. "ASC" or "DESC"</p></li>
10879 * <li><b>convert</b> : Function<p style="margin-left:1em">(Optional) A function which converts the value provided
10880 * by the Reader into an object that will be stored in the Record. It is passed the
10881 * following parameters:<ul>
10882 * <li><b>v</b> : Mixed<p style="margin-left:1em">The data value as read by the Reader.</p></li>
10884 * <li><b>dateFormat</b> : String<p style="margin-left:1em">(Optional) A format String for the Date.parseDate function.</p></li>
10886 * <br>usage:<br><pre><code>
10887 var TopicRecord = Roo.data.Record.create(
10888 {name: 'title', mapping: 'topic_title'},
10889 {name: 'author', mapping: 'username'},
10890 {name: 'totalPosts', mapping: 'topic_replies', type: 'int'},
10891 {name: 'lastPost', mapping: 'post_time', type: 'date'},
10892 {name: 'lastPoster', mapping: 'user2'},
10893 {name: 'excerpt', mapping: 'post_text'}
10896 var myNewRecord = new TopicRecord({
10897 title: 'Do my job please',
10900 lastPost: new Date(),
10901 lastPoster: 'Animal',
10902 excerpt: 'No way dude!'
10904 myStore.add(myNewRecord);
10909 Roo.data.Record.create = function(o){
10910 var f = function(){
10911 f.superclass.constructor.apply(this, arguments);
10913 Roo.extend(f, Roo.data.Record);
10914 var p = f.prototype;
10915 p.fields = new Roo.util.MixedCollection(false, function(field){
10918 for(var i = 0, len = o.length; i < len; i++){
10919 p.fields.add(new Roo.data.Field(o[i]));
10921 f.getField = function(name){
10922 return p.fields.get(name);
10927 Roo.data.Record.AUTO_ID = 1000;
10928 Roo.data.Record.EDIT = 'edit';
10929 Roo.data.Record.REJECT = 'reject';
10930 Roo.data.Record.COMMIT = 'commit';
10932 Roo.data.Record.prototype = {
10934 * Readonly flag - true if this record has been modified.
10943 join : function(store){
10944 this.store = store;
10948 * Set the named field to the specified value.
10949 * @param {String} name The name of the field to set.
10950 * @param {Object} value The value to set the field to.
10952 set : function(name, value){
10953 if(this.data[name] == value){
10957 if(!this.modified){
10958 this.modified = {};
10960 if(typeof this.modified[name] == 'undefined'){
10961 this.modified[name] = this.data[name];
10963 this.data[name] = value;
10964 if(!this.editing && this.store){
10965 this.store.afterEdit(this);
10970 * Get the value of the named field.
10971 * @param {String} name The name of the field to get the value of.
10972 * @return {Object} The value of the field.
10974 get : function(name){
10975 return this.data[name];
10979 beginEdit : function(){
10980 this.editing = true;
10981 this.modified = {};
10985 cancelEdit : function(){
10986 this.editing = false;
10987 delete this.modified;
10991 endEdit : function(){
10992 this.editing = false;
10993 if(this.dirty && this.store){
10994 this.store.afterEdit(this);
10999 * Usually called by the {@link Roo.data.Store} which owns the Record.
11000 * Rejects all changes made to the Record since either creation, or the last commit operation.
11001 * Modified fields are reverted to their original values.
11003 * Developers should subscribe to the {@link Roo.data.Store#update} event to have their code notified
11004 * of reject operations.
11006 reject : function(){
11007 var m = this.modified;
11009 if(typeof m[n] != "function"){
11010 this.data[n] = m[n];
11013 this.dirty = false;
11014 delete this.modified;
11015 this.editing = false;
11017 this.store.afterReject(this);
11022 * Usually called by the {@link Roo.data.Store} which owns the Record.
11023 * Commits all changes made to the Record since either creation, or the last commit operation.
11025 * Developers should subscribe to the {@link Roo.data.Store#update} event to have their code notified
11026 * of commit operations.
11028 commit : function(){
11029 this.dirty = false;
11030 delete this.modified;
11031 this.editing = false;
11033 this.store.afterCommit(this);
11038 hasError : function(){
11039 return this.error != null;
11043 clearError : function(){
11048 * Creates a copy of this record.
11049 * @param {String} id (optional) A new record id if you don't want to use this record's id
11052 copy : function(newId) {
11053 return new this.constructor(Roo.apply({}, this.data), newId || this.id);
11057 * Ext JS Library 1.1.1
11058 * Copyright(c) 2006-2007, Ext JS, LLC.
11060 * Originally Released Under LGPL - original licence link has changed is not relivant.
11063 * <script type="text/javascript">
11069 * @class Roo.data.Store
11070 * @extends Roo.util.Observable
11071 * The Store class encapsulates a client side cache of {@link Roo.data.Record} objects which provide input data
11072 * for widgets such as the Roo.grid.Grid, or the Roo.form.ComboBox.<br>
11074 * 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
11075 * has no knowledge of the format of the data returned by the Proxy.<br>
11077 * A Store object uses its configured implementation of {@link Roo.data.DataReader} to create {@link Roo.data.Record}
11078 * instances from the data object. These records are cached and made available through accessor functions.
11080 * Creates a new Store.
11081 * @param {Object} config A config object containing the objects needed for the Store to access data,
11082 * and read the data into Records.
11084 Roo.data.Store = function(config){
11085 this.data = new Roo.util.MixedCollection(false);
11086 this.data.getKey = function(o){
11089 this.baseParams = {};
11091 this.paramNames = {
11096 "multisort" : "_multisort"
11099 if(config && config.data){
11100 this.inlineData = config.data;
11101 delete config.data;
11104 Roo.apply(this, config);
11106 if(this.reader){ // reader passed
11107 this.reader = Roo.factory(this.reader, Roo.data);
11108 this.reader.xmodule = this.xmodule || false;
11109 if(!this.recordType){
11110 this.recordType = this.reader.recordType;
11112 if(this.reader.onMetaChange){
11113 this.reader.onMetaChange = this.onMetaChange.createDelegate(this);
11117 if(this.recordType){
11118 this.fields = this.recordType.prototype.fields;
11120 this.modified = [];
11124 * @event datachanged
11125 * Fires when the data cache has changed, and a widget which is using this Store
11126 * as a Record cache should refresh its view.
11127 * @param {Store} this
11129 datachanged : true,
11131 * @event metachange
11132 * Fires when this store's reader provides new metadata (fields). This is currently only support for JsonReaders.
11133 * @param {Store} this
11134 * @param {Object} meta The JSON metadata
11139 * Fires when Records have been added to the Store
11140 * @param {Store} this
11141 * @param {Roo.data.Record[]} records The array of Records added
11142 * @param {Number} index The index at which the record(s) were added
11147 * Fires when a Record has been removed from the Store
11148 * @param {Store} this
11149 * @param {Roo.data.Record} record The Record that was removed
11150 * @param {Number} index The index at which the record was removed
11155 * Fires when a Record has been updated
11156 * @param {Store} this
11157 * @param {Roo.data.Record} record The Record that was updated
11158 * @param {String} operation The update operation being performed. Value may be one of:
11160 Roo.data.Record.EDIT
11161 Roo.data.Record.REJECT
11162 Roo.data.Record.COMMIT
11168 * Fires when the data cache has been cleared.
11169 * @param {Store} this
11173 * @event beforeload
11174 * Fires before a request is made for a new data object. If the beforeload handler returns false
11175 * the load action will be canceled.
11176 * @param {Store} this
11177 * @param {Object} options The loading options that were specified (see {@link #load} for details)
11181 * @event beforeloadadd
11182 * Fires after a new set of Records has been loaded.
11183 * @param {Store} this
11184 * @param {Roo.data.Record[]} records The Records that were loaded
11185 * @param {Object} options The loading options that were specified (see {@link #load} for details)
11187 beforeloadadd : true,
11190 * Fires after a new set of Records has been loaded, before they are added to the store.
11191 * @param {Store} this
11192 * @param {Roo.data.Record[]} records The Records that were loaded
11193 * @param {Object} options The loading options that were specified (see {@link #load} for details)
11194 * @params {Object} return from reader
11198 * @event loadexception
11199 * Fires if an exception occurs in the Proxy during loading.
11200 * Called with the signature of the Proxy's "loadexception" event.
11201 * If you return Json { data: [] , success: false, .... } then this will be thrown with the following args
11204 * @param {Object} return from JsonData.reader() - success, totalRecords, records
11205 * @param {Object} load options
11206 * @param {Object} jsonData from your request (normally this contains the Exception)
11208 loadexception : true
11212 this.proxy = Roo.factory(this.proxy, Roo.data);
11213 this.proxy.xmodule = this.xmodule || false;
11214 this.relayEvents(this.proxy, ["loadexception"]);
11216 this.sortToggle = {};
11217 this.sortOrder = []; // array of order of sorting - updated by grid if multisort is enabled.
11219 Roo.data.Store.superclass.constructor.call(this);
11221 if(this.inlineData){
11222 this.loadData(this.inlineData);
11223 delete this.inlineData;
11227 Roo.extend(Roo.data.Store, Roo.util.Observable, {
11229 * @cfg {boolean} isLocal flag if data is locally available (and can be always looked up
11230 * without a remote query - used by combo/forms at present.
11234 * @cfg {Roo.data.DataProxy} proxy The Proxy object which provides access to a data object.
11237 * @cfg {Array} data Inline data to be loaded when the store is initialized.
11240 * @cfg {Roo.data.Reader} reader The Reader object which processes the data object and returns
11241 * an Array of Roo.data.record objects which are cached keyed by their <em>id</em> property.
11244 * @cfg {Object} baseParams An object containing properties which are to be sent as parameters
11245 * on any HTTP request
11248 * @cfg {Object} sortInfo A config object in the format: {field: "fieldName", direction: "ASC|DESC"}
11251 * @cfg {Boolean} multiSort enable multi column sorting (sort is based on the order of columns, remote only at present)
11255 * @cfg {boolean} remoteSort True if sorting is to be handled by requesting the Proxy to provide a refreshed
11256 * version of the data object in sorted order, as opposed to sorting the Record cache in place (defaults to false).
11258 remoteSort : false,
11261 * @cfg {boolean} pruneModifiedRecords True to clear all modified record information each time the store is
11262 * loaded or when a record is removed. (defaults to false).
11264 pruneModifiedRecords : false,
11267 lastOptions : null,
11270 * Add Records to the Store and fires the add event.
11271 * @param {Roo.data.Record[]} records An Array of Roo.data.Record objects to add to the cache.
11273 add : function(records){
11274 records = [].concat(records);
11275 for(var i = 0, len = records.length; i < len; i++){
11276 records[i].join(this);
11278 var index = this.data.length;
11279 this.data.addAll(records);
11280 this.fireEvent("add", this, records, index);
11284 * Remove a Record from the Store and fires the remove event.
11285 * @param {Ext.data.Record} record The Roo.data.Record object to remove from the cache.
11287 remove : function(record){
11288 var index = this.data.indexOf(record);
11289 this.data.removeAt(index);
11291 if(this.pruneModifiedRecords){
11292 this.modified.remove(record);
11294 this.fireEvent("remove", this, record, index);
11298 * Remove all Records from the Store and fires the clear event.
11300 removeAll : function(){
11302 if(this.pruneModifiedRecords){
11303 this.modified = [];
11305 this.fireEvent("clear", this);
11309 * Inserts Records to the Store at the given index and fires the add event.
11310 * @param {Number} index The start index at which to insert the passed Records.
11311 * @param {Roo.data.Record[]} records An Array of Roo.data.Record objects to add to the cache.
11313 insert : function(index, records){
11314 records = [].concat(records);
11315 for(var i = 0, len = records.length; i < len; i++){
11316 this.data.insert(index, records[i]);
11317 records[i].join(this);
11319 this.fireEvent("add", this, records, index);
11323 * Get the index within the cache of the passed Record.
11324 * @param {Roo.data.Record} record The Roo.data.Record object to to find.
11325 * @return {Number} The index of the passed Record. Returns -1 if not found.
11327 indexOf : function(record){
11328 return this.data.indexOf(record);
11332 * Get the index within the cache of the Record with the passed id.
11333 * @param {String} id The id of the Record to find.
11334 * @return {Number} The index of the Record. Returns -1 if not found.
11336 indexOfId : function(id){
11337 return this.data.indexOfKey(id);
11341 * Get the Record with the specified id.
11342 * @param {String} id The id of the Record to find.
11343 * @return {Roo.data.Record} The Record with the passed id. Returns undefined if not found.
11345 getById : function(id){
11346 return this.data.key(id);
11350 * Get the Record at the specified index.
11351 * @param {Number} index The index of the Record to find.
11352 * @return {Roo.data.Record} The Record at the passed index. Returns undefined if not found.
11354 getAt : function(index){
11355 return this.data.itemAt(index);
11359 * Returns a range of Records between specified indices.
11360 * @param {Number} startIndex (optional) The starting index (defaults to 0)
11361 * @param {Number} endIndex (optional) The ending index (defaults to the last Record in the Store)
11362 * @return {Roo.data.Record[]} An array of Records
11364 getRange : function(start, end){
11365 return this.data.getRange(start, end);
11369 storeOptions : function(o){
11370 o = Roo.apply({}, o);
11373 this.lastOptions = o;
11377 * Loads the Record cache from the configured Proxy using the configured Reader.
11379 * If using remote paging, then the first load call must specify the <em>start</em>
11380 * and <em>limit</em> properties in the options.params property to establish the initial
11381 * position within the dataset, and the number of Records to cache on each read from the Proxy.
11383 * <strong>It is important to note that for remote data sources, loading is asynchronous,
11384 * and this call will return before the new data has been loaded. Perform any post-processing
11385 * in a callback function, or in a "load" event handler.</strong>
11387 * @param {Object} options An object containing properties which control loading options:<ul>
11388 * <li>params {Object} An object containing properties to pass as HTTP parameters to a remote data source.</li>
11389 * <li>callback {Function} A function to be called after the Records have been loaded. The callback is
11390 * passed the following arguments:<ul>
11391 * <li>r : Roo.data.Record[]</li>
11392 * <li>options: Options object from the load call</li>
11393 * <li>success: Boolean success indicator</li></ul></li>
11394 * <li>scope {Object} Scope with which to call the callback (defaults to the Store object)</li>
11395 * <li>add {Boolean} indicator to append loaded records rather than replace the current cache.</li>
11398 load : function(options){
11399 options = options || {};
11400 if(this.fireEvent("beforeload", this, options) !== false){
11401 this.storeOptions(options);
11402 var p = Roo.apply(options.params || {}, this.baseParams);
11403 // if meta was not loaded from remote source.. try requesting it.
11404 if (!this.reader.metaFromRemote) {
11405 p._requestMeta = 1;
11407 if(this.sortInfo && this.remoteSort){
11408 var pn = this.paramNames;
11409 p[pn["sort"]] = this.sortInfo.field;
11410 p[pn["dir"]] = this.sortInfo.direction;
11412 if (this.multiSort) {
11413 var pn = this.paramNames;
11414 p[pn["multisort"]] = Roo.encode( { sort : this.sortToggle, order: this.sortOrder });
11417 this.proxy.load(p, this.reader, this.loadRecords, this, options);
11422 * Reloads the Record cache from the configured Proxy using the configured Reader and
11423 * the options from the last load operation performed.
11424 * @param {Object} options (optional) An object containing properties which may override the options
11425 * used in the last load operation. See {@link #load} for details (defaults to null, in which case
11426 * the most recently used options are reused).
11428 reload : function(options){
11429 this.load(Roo.applyIf(options||{}, this.lastOptions));
11433 // Called as a callback by the Reader during a load operation.
11434 loadRecords : function(o, options, success){
11435 if(!o || success === false){
11436 if(success !== false){
11437 this.fireEvent("load", this, [], options, o);
11439 if(options.callback){
11440 options.callback.call(options.scope || this, [], options, false);
11444 // if data returned failure - throw an exception.
11445 if (o.success === false) {
11446 // show a message if no listener is registered.
11447 if (!this.hasListener('loadexception') && typeof(o.raw.errorMsg) != 'undefined') {
11448 Roo.MessageBox.alert("Error loading",o.raw.errorMsg);
11450 // loadmask wil be hooked into this..
11451 this.fireEvent("loadexception", this, o, options, o.raw.errorMsg);
11454 var r = o.records, t = o.totalRecords || r.length;
11456 this.fireEvent("beforeloadadd", this, r, options, o);
11458 if(!options || options.add !== true){
11459 if(this.pruneModifiedRecords){
11460 this.modified = [];
11462 for(var i = 0, len = r.length; i < len; i++){
11466 this.data = this.snapshot;
11467 delete this.snapshot;
11470 this.data.addAll(r);
11471 this.totalLength = t;
11473 this.fireEvent("datachanged", this);
11475 this.totalLength = Math.max(t, this.data.length+r.length);
11479 if(this.parent && !Roo.isIOS && !this.useNativeIOS && this.parent.emptyTitle.length) {
11481 var e = new Roo.data.Record({});
11483 e.set(this.parent.displayField, this.parent.emptyTitle);
11484 e.set(this.parent.valueField, '');
11489 this.fireEvent("load", this, r, options, o);
11490 if(options.callback){
11491 options.callback.call(options.scope || this, r, options, true);
11497 * Loads data from a passed data block. A Reader which understands the format of the data
11498 * must have been configured in the constructor.
11499 * @param {Object} data The data block from which to read the Records. The format of the data expected
11500 * is dependent on the type of Reader that is configured and should correspond to that Reader's readRecords parameter.
11501 * @param {Boolean} append (Optional) True to append the new Records rather than replace the existing cache.
11503 loadData : function(o, append){
11504 var r = this.reader.readRecords(o);
11505 this.loadRecords(r, {add: append}, true);
11509 * Gets the number of cached records.
11511 * <em>If using paging, this may not be the total size of the dataset. If the data object
11512 * used by the Reader contains the dataset size, then the getTotalCount() function returns
11513 * the data set size</em>
11515 getCount : function(){
11516 return this.data.length || 0;
11520 * Gets the total number of records in the dataset as returned by the server.
11522 * <em>If using paging, for this to be accurate, the data object used by the Reader must contain
11523 * the dataset size</em>
11525 getTotalCount : function(){
11526 return this.totalLength || 0;
11530 * Returns the sort state of the Store as an object with two properties:
11532 field {String} The name of the field by which the Records are sorted
11533 direction {String} The sort order, "ASC" or "DESC"
11536 getSortState : function(){
11537 return this.sortInfo;
11541 applySort : function(){
11542 if(this.sortInfo && !this.remoteSort){
11543 var s = this.sortInfo, f = s.field;
11544 var st = this.fields.get(f).sortType;
11545 var fn = function(r1, r2){
11546 var v1 = st(r1.data[f]), v2 = st(r2.data[f]);
11547 return v1 > v2 ? 1 : (v1 < v2 ? -1 : 0);
11549 this.data.sort(s.direction, fn);
11550 if(this.snapshot && this.snapshot != this.data){
11551 this.snapshot.sort(s.direction, fn);
11557 * Sets the default sort column and order to be used by the next load operation.
11558 * @param {String} fieldName The name of the field to sort by.
11559 * @param {String} dir (optional) The sort order, "ASC" or "DESC" (defaults to "ASC")
11561 setDefaultSort : function(field, dir){
11562 this.sortInfo = {field: field, direction: dir ? dir.toUpperCase() : "ASC"};
11566 * Sort the Records.
11567 * If remote sorting is used, the sort is performed on the server, and the cache is
11568 * reloaded. If local sorting is used, the cache is sorted internally.
11569 * @param {String} fieldName The name of the field to sort by.
11570 * @param {String} dir (optional) The sort order, "ASC" or "DESC" (defaults to "ASC")
11572 sort : function(fieldName, dir){
11573 var f = this.fields.get(fieldName);
11575 this.sortToggle[f.name] = this.sortToggle[f.name] || f.sortDir;
11577 if(this.multiSort || (this.sortInfo && this.sortInfo.field == f.name) ){ // toggle sort dir
11578 dir = (this.sortToggle[f.name] || "ASC").toggle("ASC", "DESC");
11583 this.sortToggle[f.name] = dir;
11584 this.sortInfo = {field: f.name, direction: dir};
11585 if(!this.remoteSort){
11587 this.fireEvent("datachanged", this);
11589 this.load(this.lastOptions);
11594 * Calls the specified function for each of the Records in the cache.
11595 * @param {Function} fn The function to call. The Record is passed as the first parameter.
11596 * Returning <em>false</em> aborts and exits the iteration.
11597 * @param {Object} scope (optional) The scope in which to call the function (defaults to the Record).
11599 each : function(fn, scope){
11600 this.data.each(fn, scope);
11604 * Gets all records modified since the last commit. Modified records are persisted across load operations
11605 * (e.g., during paging).
11606 * @return {Roo.data.Record[]} An array of Records containing outstanding modifications.
11608 getModifiedRecords : function(){
11609 return this.modified;
11613 createFilterFn : function(property, value, anyMatch){
11614 if(!value.exec){ // not a regex
11615 value = String(value);
11616 if(value.length == 0){
11619 value = new RegExp((anyMatch === true ? '' : '^') + Roo.escapeRe(value), "i");
11621 return function(r){
11622 return value.test(r.data[property]);
11627 * Sums the value of <i>property</i> for each record between start and end and returns the result.
11628 * @param {String} property A field on your records
11629 * @param {Number} start The record index to start at (defaults to 0)
11630 * @param {Number} end The last record index to include (defaults to length - 1)
11631 * @return {Number} The sum
11633 sum : function(property, start, end){
11634 var rs = this.data.items, v = 0;
11635 start = start || 0;
11636 end = (end || end === 0) ? end : rs.length-1;
11638 for(var i = start; i <= end; i++){
11639 v += (rs[i].data[property] || 0);
11645 * Filter the records by a specified property.
11646 * @param {String} field A field on your records
11647 * @param {String/RegExp} value Either a string that the field
11648 * should start with or a RegExp to test against the field
11649 * @param {Boolean} anyMatch True to match any part not just the beginning
11651 filter : function(property, value, anyMatch){
11652 var fn = this.createFilterFn(property, value, anyMatch);
11653 return fn ? this.filterBy(fn) : this.clearFilter();
11657 * Filter by a function. The specified function will be called with each
11658 * record in this data source. If the function returns true the record is included,
11659 * otherwise it is filtered.
11660 * @param {Function} fn The function to be called, it will receive 2 args (record, id)
11661 * @param {Object} scope (optional) The scope of the function (defaults to this)
11663 filterBy : function(fn, scope){
11664 this.snapshot = this.snapshot || this.data;
11665 this.data = this.queryBy(fn, scope||this);
11666 this.fireEvent("datachanged", this);
11670 * Query the records by a specified property.
11671 * @param {String} field A field on your records
11672 * @param {String/RegExp} value Either a string that the field
11673 * should start with or a RegExp to test against the field
11674 * @param {Boolean} anyMatch True to match any part not just the beginning
11675 * @return {MixedCollection} Returns an Roo.util.MixedCollection of the matched records
11677 query : function(property, value, anyMatch){
11678 var fn = this.createFilterFn(property, value, anyMatch);
11679 return fn ? this.queryBy(fn) : this.data.clone();
11683 * Query by a function. The specified function will be called with each
11684 * record in this data source. If the function returns true the record is included
11686 * @param {Function} fn The function to be called, it will receive 2 args (record, id)
11687 * @param {Object} scope (optional) The scope of the function (defaults to this)
11688 @return {MixedCollection} Returns an Roo.util.MixedCollection of the matched records
11690 queryBy : function(fn, scope){
11691 var data = this.snapshot || this.data;
11692 return data.filterBy(fn, scope||this);
11696 * Collects unique values for a particular dataIndex from this store.
11697 * @param {String} dataIndex The property to collect
11698 * @param {Boolean} allowNull (optional) Pass true to allow null, undefined or empty string values
11699 * @param {Boolean} bypassFilter (optional) Pass true to collect from all records, even ones which are filtered
11700 * @return {Array} An array of the unique values
11702 collect : function(dataIndex, allowNull, bypassFilter){
11703 var d = (bypassFilter === true && this.snapshot) ?
11704 this.snapshot.items : this.data.items;
11705 var v, sv, r = [], l = {};
11706 for(var i = 0, len = d.length; i < len; i++){
11707 v = d[i].data[dataIndex];
11709 if((allowNull || !Roo.isEmpty(v)) && !l[sv]){
11718 * Revert to a view of the Record cache with no filtering applied.
11719 * @param {Boolean} suppressEvent If true the filter is cleared silently without notifying listeners
11721 clearFilter : function(suppressEvent){
11722 if(this.snapshot && this.snapshot != this.data){
11723 this.data = this.snapshot;
11724 delete this.snapshot;
11725 if(suppressEvent !== true){
11726 this.fireEvent("datachanged", this);
11732 afterEdit : function(record){
11733 if(this.modified.indexOf(record) == -1){
11734 this.modified.push(record);
11736 this.fireEvent("update", this, record, Roo.data.Record.EDIT);
11740 afterReject : function(record){
11741 this.modified.remove(record);
11742 this.fireEvent("update", this, record, Roo.data.Record.REJECT);
11746 afterCommit : function(record){
11747 this.modified.remove(record);
11748 this.fireEvent("update", this, record, Roo.data.Record.COMMIT);
11752 * Commit all Records with outstanding changes. To handle updates for changes, subscribe to the
11753 * Store's "update" event, and perform updating when the third parameter is Roo.data.Record.COMMIT.
11755 commitChanges : function(){
11756 var m = this.modified.slice(0);
11757 this.modified = [];
11758 for(var i = 0, len = m.length; i < len; i++){
11764 * Cancel outstanding changes on all changed records.
11766 rejectChanges : function(){
11767 var m = this.modified.slice(0);
11768 this.modified = [];
11769 for(var i = 0, len = m.length; i < len; i++){
11774 onMetaChange : function(meta, rtype, o){
11775 this.recordType = rtype;
11776 this.fields = rtype.prototype.fields;
11777 delete this.snapshot;
11778 this.sortInfo = meta.sortInfo || this.sortInfo;
11779 this.modified = [];
11780 this.fireEvent('metachange', this, this.reader.meta);
11783 moveIndex : function(data, type)
11785 var index = this.indexOf(data);
11787 var newIndex = index + type;
11791 this.insert(newIndex, data);
11796 * Ext JS Library 1.1.1
11797 * Copyright(c) 2006-2007, Ext JS, LLC.
11799 * Originally Released Under LGPL - original licence link has changed is not relivant.
11802 * <script type="text/javascript">
11806 * @class Roo.data.SimpleStore
11807 * @extends Roo.data.Store
11808 * Small helper class to make creating Stores from Array data easier.
11809 * @cfg {Number} id The array index of the record id. Leave blank to auto generate ids.
11810 * @cfg {Array} fields An array of field definition objects, or field name strings.
11811 * @cfg {Array} data The multi-dimensional array of data
11813 * @param {Object} config
11815 Roo.data.SimpleStore = function(config){
11816 Roo.data.SimpleStore.superclass.constructor.call(this, {
11818 reader: new Roo.data.ArrayReader({
11821 Roo.data.Record.create(config.fields)
11823 proxy : new Roo.data.MemoryProxy(config.data)
11827 Roo.extend(Roo.data.SimpleStore, Roo.data.Store);/*
11829 * Ext JS Library 1.1.1
11830 * Copyright(c) 2006-2007, Ext JS, LLC.
11832 * Originally Released Under LGPL - original licence link has changed is not relivant.
11835 * <script type="text/javascript">
11840 * @extends Roo.data.Store
11841 * @class Roo.data.JsonStore
11842 * Small helper class to make creating Stores for JSON data easier. <br/>
11844 var store = new Roo.data.JsonStore({
11845 url: 'get-images.php',
11847 fields: ['name', 'url', {name:'size', type: 'float'}, {name:'lastmod', type:'date'}]
11850 * <b>Note: Although they are not listed, this class inherits all of the config options of Store,
11851 * JsonReader and HttpProxy (unless inline data is provided).</b>
11852 * @cfg {Array} fields An array of field definition objects, or field name strings.
11854 * @param {Object} config
11856 Roo.data.JsonStore = function(c){
11857 Roo.data.JsonStore.superclass.constructor.call(this, Roo.apply(c, {
11858 proxy: !c.data ? new Roo.data.HttpProxy({url: c.url}) : undefined,
11859 reader: new Roo.data.JsonReader(c, c.fields)
11862 Roo.extend(Roo.data.JsonStore, Roo.data.Store);/*
11864 * Ext JS Library 1.1.1
11865 * Copyright(c) 2006-2007, Ext JS, LLC.
11867 * Originally Released Under LGPL - original licence link has changed is not relivant.
11870 * <script type="text/javascript">
11874 Roo.data.Field = function(config){
11875 if(typeof config == "string"){
11876 config = {name: config};
11878 Roo.apply(this, config);
11881 this.type = "auto";
11884 var st = Roo.data.SortTypes;
11885 // named sortTypes are supported, here we look them up
11886 if(typeof this.sortType == "string"){
11887 this.sortType = st[this.sortType];
11890 // set default sortType for strings and dates
11891 if(!this.sortType){
11894 this.sortType = st.asUCString;
11897 this.sortType = st.asDate;
11900 this.sortType = st.none;
11905 var stripRe = /[\$,%]/g;
11907 // prebuilt conversion function for this field, instead of
11908 // switching every time we're reading a value
11910 var cv, dateFormat = this.dateFormat;
11915 cv = function(v){ return v; };
11918 cv = function(v){ return (v === undefined || v === null) ? '' : String(v); };
11922 return v !== undefined && v !== null && v !== '' ?
11923 parseInt(String(v).replace(stripRe, ""), 10) : '';
11928 return v !== undefined && v !== null && v !== '' ?
11929 parseFloat(String(v).replace(stripRe, ""), 10) : '';
11934 cv = function(v){ return v === true || v === "true" || v == 1; };
11941 if(v instanceof Date){
11945 if(dateFormat == "timestamp"){
11946 return new Date(v*1000);
11948 return Date.parseDate(v, dateFormat);
11950 var parsed = Date.parse(v);
11951 return parsed ? new Date(parsed) : null;
11960 Roo.data.Field.prototype = {
11968 * Ext JS Library 1.1.1
11969 * Copyright(c) 2006-2007, Ext JS, LLC.
11971 * Originally Released Under LGPL - original licence link has changed is not relivant.
11974 * <script type="text/javascript">
11977 // Base class for reading structured data from a data source. This class is intended to be
11978 // extended (see ArrayReader, JsonReader and XmlReader) and should not be created directly.
11981 * @class Roo.data.DataReader
11982 * Base class for reading structured data from a data source. This class is intended to be
11983 * extended (see {Roo.data.ArrayReader}, {Roo.data.JsonReader} and {Roo.data.XmlReader}) and should not be created directly.
11986 Roo.data.DataReader = function(meta, recordType){
11990 this.recordType = recordType instanceof Array ?
11991 Roo.data.Record.create(recordType) : recordType;
11994 Roo.data.DataReader.prototype = {
11996 * Create an empty record
11997 * @param {Object} data (optional) - overlay some values
11998 * @return {Roo.data.Record} record created.
12000 newRow : function(d) {
12002 this.recordType.prototype.fields.each(function(c) {
12004 case 'int' : da[c.name] = 0; break;
12005 case 'date' : da[c.name] = new Date(); break;
12006 case 'float' : da[c.name] = 0.0; break;
12007 case 'boolean' : da[c.name] = false; break;
12008 default : da[c.name] = ""; break;
12012 return new this.recordType(Roo.apply(da, d));
12017 * Ext JS Library 1.1.1
12018 * Copyright(c) 2006-2007, Ext JS, LLC.
12020 * Originally Released Under LGPL - original licence link has changed is not relivant.
12023 * <script type="text/javascript">
12027 * @class Roo.data.DataProxy
12028 * @extends Roo.data.Observable
12029 * This class is an abstract base class for implementations which provide retrieval of
12030 * unformatted data objects.<br>
12032 * DataProxy implementations are usually used in conjunction with an implementation of Roo.data.DataReader
12033 * (of the appropriate type which knows how to parse the data object) to provide a block of
12034 * {@link Roo.data.Records} to an {@link Roo.data.Store}.<br>
12036 * Custom implementations must implement the load method as described in
12037 * {@link Roo.data.HttpProxy#load}.
12039 Roo.data.DataProxy = function(){
12042 * @event beforeload
12043 * Fires before a network request is made to retrieve a data object.
12044 * @param {Object} This DataProxy object.
12045 * @param {Object} params The params parameter to the load function.
12050 * Fires before the load method's callback is called.
12051 * @param {Object} This DataProxy object.
12052 * @param {Object} o The data object.
12053 * @param {Object} arg The callback argument object passed to the load function.
12057 * @event loadexception
12058 * Fires if an Exception occurs during data retrieval.
12059 * @param {Object} This DataProxy object.
12060 * @param {Object} o The data object.
12061 * @param {Object} arg The callback argument object passed to the load function.
12062 * @param {Object} e The Exception.
12064 loadexception : true
12066 Roo.data.DataProxy.superclass.constructor.call(this);
12069 Roo.extend(Roo.data.DataProxy, Roo.util.Observable);
12072 * @cfg {void} listeners (Not available) Constructor blocks listeners from being set
12076 * Ext JS Library 1.1.1
12077 * Copyright(c) 2006-2007, Ext JS, LLC.
12079 * Originally Released Under LGPL - original licence link has changed is not relivant.
12082 * <script type="text/javascript">
12085 * @class Roo.data.MemoryProxy
12086 * An implementation of Roo.data.DataProxy that simply passes the data specified in its constructor
12087 * to the Reader when its load method is called.
12089 * @param {Object} data The data object which the Reader uses to construct a block of Roo.data.Records.
12091 Roo.data.MemoryProxy = function(data){
12095 Roo.data.MemoryProxy.superclass.constructor.call(this);
12099 Roo.extend(Roo.data.MemoryProxy, Roo.data.DataProxy, {
12102 * Load data from the requested source (in this case an in-memory
12103 * data object passed to the constructor), read the data object into
12104 * a block of Roo.data.Records using the passed Roo.data.DataReader implementation, and
12105 * process that block using the passed callback.
12106 * @param {Object} params This parameter is not used by the MemoryProxy class.
12107 * @param {Roo.data.DataReader} reader The Reader object which converts the data
12108 * object into a block of Roo.data.Records.
12109 * @param {Function} callback The function into which to pass the block of Roo.data.records.
12110 * The function must be passed <ul>
12111 * <li>The Record block object</li>
12112 * <li>The "arg" argument from the load function</li>
12113 * <li>A boolean success indicator</li>
12115 * @param {Object} scope The scope in which to call the callback
12116 * @param {Object} arg An optional argument which is passed to the callback as its second parameter.
12118 load : function(params, reader, callback, scope, arg){
12119 params = params || {};
12122 result = reader.readRecords(this.data);
12124 this.fireEvent("loadexception", this, arg, null, e);
12125 callback.call(scope, null, arg, false);
12128 callback.call(scope, result, arg, true);
12132 update : function(params, records){
12137 * Ext JS Library 1.1.1
12138 * Copyright(c) 2006-2007, Ext JS, LLC.
12140 * Originally Released Under LGPL - original licence link has changed is not relivant.
12143 * <script type="text/javascript">
12146 * @class Roo.data.HttpProxy
12147 * @extends Roo.data.DataProxy
12148 * An implementation of {@link Roo.data.DataProxy} that reads a data object from an {@link Roo.data.Connection} object
12149 * configured to reference a certain URL.<br><br>
12151 * <em>Note that this class cannot be used to retrieve data from a domain other than the domain
12152 * from which the running page was served.<br><br>
12154 * For cross-domain access to remote data, use an {@link Roo.data.ScriptTagProxy}.</em><br><br>
12156 * Be aware that to enable the browser to parse an XML document, the server must set
12157 * the Content-Type header in the HTTP response to "text/xml".
12159 * @param {Object} conn Connection config options to add to each request (e.g. {url: 'foo.php'} or
12160 * an {@link Roo.data.Connection} object. If a Connection config is passed, the singleton {@link Roo.Ajax} object
12161 * will be used to make the request.
12163 Roo.data.HttpProxy = function(conn){
12164 Roo.data.HttpProxy.superclass.constructor.call(this);
12165 // is conn a conn config or a real conn?
12167 this.useAjax = !conn || !conn.events;
12171 Roo.extend(Roo.data.HttpProxy, Roo.data.DataProxy, {
12172 // thse are take from connection...
12175 * @cfg {String} url (Optional) The default URL to be used for requests to the server. (defaults to undefined)
12178 * @cfg {Object} extraParams (Optional) An object containing properties which are used as
12179 * extra parameters to each request made by this object. (defaults to undefined)
12182 * @cfg {Object} defaultHeaders (Optional) An object containing request headers which are added
12183 * to each request made by this object. (defaults to undefined)
12186 * @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)
12189 * @cfg {Number} timeout (Optional) The timeout in milliseconds to be used for requests. (defaults to 30000)
12192 * @cfg {Boolean} autoAbort (Optional) Whether this request should abort any pending requests. (defaults to false)
12198 * @cfg {Boolean} disableCaching (Optional) True to add a unique cache-buster param to GET requests. (defaults to true)
12202 * Return the {@link Roo.data.Connection} object being used by this Proxy.
12203 * @return {Connection} The Connection object. This object may be used to subscribe to events on
12204 * a finer-grained basis than the DataProxy events.
12206 getConnection : function(){
12207 return this.useAjax ? Roo.Ajax : this.conn;
12211 * Load data from the configured {@link Roo.data.Connection}, read the data object into
12212 * a block of Roo.data.Records using the passed {@link Roo.data.DataReader} implementation, and
12213 * process that block using the passed callback.
12214 * @param {Object} params An object containing properties which are to be used as HTTP parameters
12215 * for the request to the remote server.
12216 * @param {Roo.data.DataReader} reader The Reader object which converts the data
12217 * object into a block of Roo.data.Records.
12218 * @param {Function} callback The function into which to pass the block of Roo.data.Records.
12219 * The function must be passed <ul>
12220 * <li>The Record block object</li>
12221 * <li>The "arg" argument from the load function</li>
12222 * <li>A boolean success indicator</li>
12224 * @param {Object} scope The scope in which to call the callback
12225 * @param {Object} arg An optional argument which is passed to the callback as its second parameter.
12227 load : function(params, reader, callback, scope, arg){
12228 if(this.fireEvent("beforeload", this, params) !== false){
12230 params : params || {},
12232 callback : callback,
12237 callback : this.loadResponse,
12241 Roo.applyIf(o, this.conn);
12242 if(this.activeRequest){
12243 Roo.Ajax.abort(this.activeRequest);
12245 this.activeRequest = Roo.Ajax.request(o);
12247 this.conn.request(o);
12250 callback.call(scope||this, null, arg, false);
12255 loadResponse : function(o, success, response){
12256 delete this.activeRequest;
12258 this.fireEvent("loadexception", this, o, response);
12259 o.request.callback.call(o.request.scope, null, o.request.arg, false);
12264 result = o.reader.read(response);
12266 this.fireEvent("loadexception", this, o, response, e);
12267 o.request.callback.call(o.request.scope, null, o.request.arg, false);
12271 this.fireEvent("load", this, o, o.request.arg);
12272 o.request.callback.call(o.request.scope, result, o.request.arg, true);
12276 update : function(dataSet){
12281 updateResponse : function(dataSet){
12286 * Ext JS Library 1.1.1
12287 * Copyright(c) 2006-2007, Ext JS, LLC.
12289 * Originally Released Under LGPL - original licence link has changed is not relivant.
12292 * <script type="text/javascript">
12296 * @class Roo.data.ScriptTagProxy
12297 * An implementation of Roo.data.DataProxy that reads a data object from a URL which may be in a domain
12298 * other than the originating domain of the running page.<br><br>
12300 * <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
12301 * of the running page, you must use this class, rather than DataProxy.</em><br><br>
12303 * The content passed back from a server resource requested by a ScriptTagProxy is executable JavaScript
12304 * source code that is used as the source inside a <script> tag.<br><br>
12306 * In order for the browser to process the returned data, the server must wrap the data object
12307 * with a call to a callback function, the name of which is passed as a parameter by the ScriptTagProxy.
12308 * Below is a Java example for a servlet which returns data for either a ScriptTagProxy, or an HttpProxy
12309 * depending on whether the callback name was passed:
12312 boolean scriptTag = false;
12313 String cb = request.getParameter("callback");
12316 response.setContentType("text/javascript");
12318 response.setContentType("application/x-json");
12320 Writer out = response.getWriter();
12322 out.write(cb + "(");
12324 out.print(dataBlock.toJsonString());
12331 * @param {Object} config A configuration object.
12333 Roo.data.ScriptTagProxy = function(config){
12334 Roo.data.ScriptTagProxy.superclass.constructor.call(this);
12335 Roo.apply(this, config);
12336 this.head = document.getElementsByTagName("head")[0];
12339 Roo.data.ScriptTagProxy.TRANS_ID = 1000;
12341 Roo.extend(Roo.data.ScriptTagProxy, Roo.data.DataProxy, {
12343 * @cfg {String} url The URL from which to request the data object.
12346 * @cfg {Number} timeout (Optional) The number of milliseconds to wait for a response. Defaults to 30 seconds.
12350 * @cfg {String} callbackParam (Optional) The name of the parameter to pass to the server which tells
12351 * the server the name of the callback function set up by the load call to process the returned data object.
12352 * Defaults to "callback".<p>The server-side processing must read this parameter value, and generate
12353 * javascript output which calls this named function passing the data object as its only parameter.
12355 callbackParam : "callback",
12357 * @cfg {Boolean} nocache (Optional) Defaults to true. Disable cacheing by adding a unique parameter
12358 * name to the request.
12363 * Load data from the configured URL, read the data object into
12364 * a block of Roo.data.Records using the passed Roo.data.DataReader implementation, and
12365 * process that block using the passed callback.
12366 * @param {Object} params An object containing properties which are to be used as HTTP parameters
12367 * for the request to the remote server.
12368 * @param {Roo.data.DataReader} reader The Reader object which converts the data
12369 * object into a block of Roo.data.Records.
12370 * @param {Function} callback The function into which to pass the block of Roo.data.Records.
12371 * The function must be passed <ul>
12372 * <li>The Record block object</li>
12373 * <li>The "arg" argument from the load function</li>
12374 * <li>A boolean success indicator</li>
12376 * @param {Object} scope The scope in which to call the callback
12377 * @param {Object} arg An optional argument which is passed to the callback as its second parameter.
12379 load : function(params, reader, callback, scope, arg){
12380 if(this.fireEvent("beforeload", this, params) !== false){
12382 var p = Roo.urlEncode(Roo.apply(params, this.extraParams));
12384 var url = this.url;
12385 url += (url.indexOf("?") != -1 ? "&" : "?") + p;
12387 url += "&_dc=" + (new Date().getTime());
12389 var transId = ++Roo.data.ScriptTagProxy.TRANS_ID;
12392 cb : "stcCallback"+transId,
12393 scriptId : "stcScript"+transId,
12397 callback : callback,
12403 window[trans.cb] = function(o){
12404 conn.handleResponse(o, trans);
12407 url += String.format("&{0}={1}", this.callbackParam, trans.cb);
12409 if(this.autoAbort !== false){
12413 trans.timeoutId = this.handleFailure.defer(this.timeout, this, [trans]);
12415 var script = document.createElement("script");
12416 script.setAttribute("src", url);
12417 script.setAttribute("type", "text/javascript");
12418 script.setAttribute("id", trans.scriptId);
12419 this.head.appendChild(script);
12421 this.trans = trans;
12423 callback.call(scope||this, null, arg, false);
12428 isLoading : function(){
12429 return this.trans ? true : false;
12433 * Abort the current server request.
12435 abort : function(){
12436 if(this.isLoading()){
12437 this.destroyTrans(this.trans);
12442 destroyTrans : function(trans, isLoaded){
12443 this.head.removeChild(document.getElementById(trans.scriptId));
12444 clearTimeout(trans.timeoutId);
12446 window[trans.cb] = undefined;
12448 delete window[trans.cb];
12451 // if hasn't been loaded, wait for load to remove it to prevent script error
12452 window[trans.cb] = function(){
12453 window[trans.cb] = undefined;
12455 delete window[trans.cb];
12462 handleResponse : function(o, trans){
12463 this.trans = false;
12464 this.destroyTrans(trans, true);
12467 result = trans.reader.readRecords(o);
12469 this.fireEvent("loadexception", this, o, trans.arg, e);
12470 trans.callback.call(trans.scope||window, null, trans.arg, false);
12473 this.fireEvent("load", this, o, trans.arg);
12474 trans.callback.call(trans.scope||window, result, trans.arg, true);
12478 handleFailure : function(trans){
12479 this.trans = false;
12480 this.destroyTrans(trans, false);
12481 this.fireEvent("loadexception", this, null, trans.arg);
12482 trans.callback.call(trans.scope||window, null, trans.arg, false);
12486 * Ext JS Library 1.1.1
12487 * Copyright(c) 2006-2007, Ext JS, LLC.
12489 * Originally Released Under LGPL - original licence link has changed is not relivant.
12492 * <script type="text/javascript">
12496 * @class Roo.data.JsonReader
12497 * @extends Roo.data.DataReader
12498 * Data reader class to create an Array of Roo.data.Record objects from a JSON response
12499 * based on mappings in a provided Roo.data.Record constructor.
12501 * The default behaviour of a store is to send ?_requestMeta=1, unless the class has recieved 'metaData' property
12502 * in the reply previously.
12507 var RecordDef = Roo.data.Record.create([
12508 {name: 'name', mapping: 'name'}, // "mapping" property not needed if it's the same as "name"
12509 {name: 'occupation'} // This field will use "occupation" as the mapping.
12511 var myReader = new Roo.data.JsonReader({
12512 totalProperty: "results", // The property which contains the total dataset size (optional)
12513 root: "rows", // The property which contains an Array of row objects
12514 id: "id" // The property within each row object that provides an ID for the record (optional)
12518 * This would consume a JSON file like this:
12520 { 'results': 2, 'rows': [
12521 { 'id': 1, 'name': 'Bill', occupation: 'Gardener' },
12522 { 'id': 2, 'name': 'Ben', occupation: 'Horticulturalist' } ]
12525 * @cfg {String} totalProperty Name of the property from which to retrieve the total number of records
12526 * in the dataset. This is only needed if the whole dataset is not passed in one go, but is being
12527 * paged from the remote server.
12528 * @cfg {String} successProperty Name of the property from which to retrieve the success attribute used by forms.
12529 * @cfg {String} root name of the property which contains the Array of row objects.
12530 * @cfg {String} id Name of the property within a row object that contains a record identifier value.
12531 * @cfg {Array} fields Array of field definition objects
12533 * Create a new JsonReader
12534 * @param {Object} meta Metadata configuration options
12535 * @param {Object} recordType Either an Array of field definition objects,
12536 * or an {@link Roo.data.Record} object created using {@link Roo.data.Record#create}.
12538 Roo.data.JsonReader = function(meta, recordType){
12541 // set some defaults:
12542 Roo.applyIf(meta, {
12543 totalProperty: 'total',
12544 successProperty : 'success',
12549 Roo.data.JsonReader.superclass.constructor.call(this, meta, recordType||meta.fields);
12551 Roo.extend(Roo.data.JsonReader, Roo.data.DataReader, {
12554 * @prop {Boolean} metaFromRemote - if the meta data was loaded from the remote source.
12555 * Used by Store query builder to append _requestMeta to params.
12558 metaFromRemote : false,
12560 * This method is only used by a DataProxy which has retrieved data from a remote server.
12561 * @param {Object} response The XHR object which contains the JSON data in its responseText.
12562 * @return {Object} data A data block which is used by an Roo.data.Store object as
12563 * a cache of Roo.data.Records.
12565 read : function(response){
12566 var json = response.responseText;
12568 var o = /* eval:var:o */ eval("("+json+")");
12570 throw {message: "JsonReader.read: Json object not found"};
12576 this.metaFromRemote = true;
12577 this.meta = o.metaData;
12578 this.recordType = Roo.data.Record.create(o.metaData.fields);
12579 this.onMetaChange(this.meta, this.recordType, o);
12581 return this.readRecords(o);
12584 // private function a store will implement
12585 onMetaChange : function(meta, recordType, o){
12592 simpleAccess: function(obj, subsc) {
12599 getJsonAccessor: function(){
12601 return function(expr) {
12603 return(re.test(expr))
12604 ? new Function("obj", "return obj." + expr)
12609 return Roo.emptyFn;
12614 * Create a data block containing Roo.data.Records from an XML document.
12615 * @param {Object} o An object which contains an Array of row objects in the property specified
12616 * in the config as 'root, and optionally a property, specified in the config as 'totalProperty'
12617 * which contains the total size of the dataset.
12618 * @return {Object} data A data block which is used by an Roo.data.Store object as
12619 * a cache of Roo.data.Records.
12621 readRecords : function(o){
12623 * After any data loads, the raw JSON data is available for further custom processing.
12627 var s = this.meta, Record = this.recordType,
12628 f = Record ? Record.prototype.fields : null, fi = f ? f.items : [], fl = f ? f.length : 0;
12630 // Generate extraction functions for the totalProperty, the root, the id, and for each field
12632 if(s.totalProperty) {
12633 this.getTotal = this.getJsonAccessor(s.totalProperty);
12635 if(s.successProperty) {
12636 this.getSuccess = this.getJsonAccessor(s.successProperty);
12638 this.getRoot = s.root ? this.getJsonAccessor(s.root) : function(p){return p;};
12640 var g = this.getJsonAccessor(s.id);
12641 this.getId = function(rec) {
12643 return (r === undefined || r === "") ? null : r;
12646 this.getId = function(){return null;};
12649 for(var jj = 0; jj < fl; jj++){
12651 var map = (f.mapping !== undefined && f.mapping !== null) ? f.mapping : f.name;
12652 this.ef[jj] = this.getJsonAccessor(map);
12656 var root = this.getRoot(o), c = root.length, totalRecords = c, success = true;
12657 if(s.totalProperty){
12658 var vt = parseInt(this.getTotal(o), 10);
12663 if(s.successProperty){
12664 var vs = this.getSuccess(o);
12665 if(vs === false || vs === 'false'){
12670 for(var i = 0; i < c; i++){
12673 var id = this.getId(n);
12674 for(var j = 0; j < fl; j++){
12676 var v = this.ef[j](n);
12678 Roo.log('missing convert for ' + f.name);
12682 values[f.name] = f.convert((v !== undefined) ? v : f.defaultValue);
12684 var record = new Record(values, id);
12686 records[i] = record;
12692 totalRecords : totalRecords
12697 * Ext JS Library 1.1.1
12698 * Copyright(c) 2006-2007, Ext JS, LLC.
12700 * Originally Released Under LGPL - original licence link has changed is not relivant.
12703 * <script type="text/javascript">
12707 * @class Roo.data.ArrayReader
12708 * @extends Roo.data.DataReader
12709 * Data reader class to create an Array of Roo.data.Record objects from an Array.
12710 * Each element of that Array represents a row of data fields. The
12711 * fields are pulled into a Record object using as a subscript, the <em>mapping</em> property
12712 * of the field definition if it exists, or the field's ordinal position in the definition.<br>
12716 var RecordDef = Roo.data.Record.create([
12717 {name: 'name', mapping: 1}, // "mapping" only needed if an "id" field is present which
12718 {name: 'occupation', mapping: 2} // precludes using the ordinal position as the index.
12720 var myReader = new Roo.data.ArrayReader({
12721 id: 0 // The subscript within row Array that provides an ID for the Record (optional)
12725 * This would consume an Array like this:
12727 [ [1, 'Bill', 'Gardener'], [2, 'Ben', 'Horticulturalist'] ]
12729 * @cfg {String} id (optional) The subscript within row Array that provides an ID for the Record
12731 * Create a new JsonReader
12732 * @param {Object} meta Metadata configuration options.
12733 * @param {Object} recordType Either an Array of field definition objects
12734 * as specified to {@link Roo.data.Record#create},
12735 * or an {@link Roo.data.Record} object
12736 * created using {@link Roo.data.Record#create}.
12738 Roo.data.ArrayReader = function(meta, recordType){
12739 Roo.data.ArrayReader.superclass.constructor.call(this, meta, recordType);
12742 Roo.extend(Roo.data.ArrayReader, Roo.data.JsonReader, {
12744 * Create a data block containing Roo.data.Records from an XML document.
12745 * @param {Object} o An Array of row objects which represents the dataset.
12746 * @return {Object} data A data block which is used by an Roo.data.Store object as
12747 * a cache of Roo.data.Records.
12749 readRecords : function(o){
12750 var sid = this.meta ? this.meta.id : null;
12751 var recordType = this.recordType, fields = recordType.prototype.fields;
12754 for(var i = 0; i < root.length; i++){
12757 var id = ((sid || sid === 0) && n[sid] !== undefined && n[sid] !== "" ? n[sid] : null);
12758 for(var j = 0, jlen = fields.length; j < jlen; j++){
12759 var f = fields.items[j];
12760 var k = f.mapping !== undefined && f.mapping !== null ? f.mapping : j;
12761 var v = n[k] !== undefined ? n[k] : f.defaultValue;
12763 values[f.name] = v;
12765 var record = new recordType(values, id);
12767 records[records.length] = record;
12771 totalRecords : records.length
12780 * @class Roo.bootstrap.ComboBox
12781 * @extends Roo.bootstrap.TriggerField
12782 * A combobox control with support for autocomplete, remote-loading, paging and many other features.
12783 * @cfg {Boolean} append (true|false) default false
12784 * @cfg {Boolean} autoFocus (true|false) auto focus the first item, default true
12785 * @cfg {Boolean} tickable ComboBox with tickable selections (true|false), default false
12786 * @cfg {Boolean} triggerList trigger show the list or not (true|false) default true
12787 * @cfg {Boolean} showToggleBtn show toggle button or not (true|false) default true
12788 * @cfg {String} btnPosition set the position of the trigger button (left | right) default right
12789 * @cfg {Boolean} animate default true
12790 * @cfg {Boolean} emptyResultText only for touch device
12791 * @cfg {String} triggerText multiple combobox trigger button text default 'Select'
12792 * @cfg {String} emptyTitle default ''
12794 * Create a new ComboBox.
12795 * @param {Object} config Configuration options
12797 Roo.bootstrap.ComboBox = function(config){
12798 Roo.bootstrap.ComboBox.superclass.constructor.call(this, config);
12802 * Fires when the dropdown list is expanded
12803 * @param {Roo.bootstrap.ComboBox} combo This combo box
12808 * Fires when the dropdown list is collapsed
12809 * @param {Roo.bootstrap.ComboBox} combo This combo box
12813 * @event beforeselect
12814 * Fires before a list item is selected. Return false to cancel the selection.
12815 * @param {Roo.bootstrap.ComboBox} combo This combo box
12816 * @param {Roo.data.Record} record The data record returned from the underlying store
12817 * @param {Number} index The index of the selected item in the dropdown list
12819 'beforeselect' : true,
12822 * Fires when a list item is selected
12823 * @param {Roo.bootstrap.ComboBox} combo This combo box
12824 * @param {Roo.data.Record} record The data record returned from the underlying store (or false on clear)
12825 * @param {Number} index The index of the selected item in the dropdown list
12829 * @event beforequery
12830 * Fires before all queries are processed. Return false to cancel the query or set cancel to true.
12831 * The event object passed has these properties:
12832 * @param {Roo.bootstrap.ComboBox} combo This combo box
12833 * @param {String} query The query
12834 * @param {Boolean} forceAll true to force "all" query
12835 * @param {Boolean} cancel true to cancel the query
12836 * @param {Object} e The query event object
12838 'beforequery': true,
12841 * Fires when the 'add' icon is pressed (add a listener to enable add button)
12842 * @param {Roo.bootstrap.ComboBox} combo This combo box
12847 * Fires when the 'edit' icon is pressed (add a listener to enable add button)
12848 * @param {Roo.bootstrap.ComboBox} combo This combo box
12849 * @param {Roo.data.Record|false} record The data record returned from the underlying store (or false on nothing selected)
12854 * Fires when the remove value from the combobox array
12855 * @param {Roo.bootstrap.ComboBox} combo This combo box
12859 * @event afterremove
12860 * Fires when the remove value from the combobox array
12861 * @param {Roo.bootstrap.ComboBox} combo This combo box
12863 'afterremove' : true,
12865 * @event specialfilter
12866 * Fires when specialfilter
12867 * @param {Roo.bootstrap.ComboBox} combo This combo box
12869 'specialfilter' : true,
12872 * Fires when tick the element
12873 * @param {Roo.bootstrap.ComboBox} combo This combo box
12877 * @event touchviewdisplay
12878 * Fires when touch view require special display (default is using displayField)
12879 * @param {Roo.bootstrap.ComboBox} combo This combo box
12880 * @param {Object} cfg set html .
12882 'touchviewdisplay' : true
12887 this.tickItems = [];
12889 this.selectedIndex = -1;
12890 if(this.mode == 'local'){
12891 if(config.queryDelay === undefined){
12892 this.queryDelay = 10;
12894 if(config.minChars === undefined){
12900 Roo.extend(Roo.bootstrap.ComboBox, Roo.bootstrap.TriggerField, {
12903 * @cfg {Boolean} lazyRender True to prevent the ComboBox from rendering until requested (should always be used when
12904 * rendering into an Roo.Editor, defaults to false)
12907 * @cfg {Boolean/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to:
12908 * {tag: "input", type: "text", size: "24", autocomplete: "off"})
12911 * @cfg {Roo.data.Store} store The data store to which this combo is bound (defaults to undefined)
12914 * @cfg {String} title If supplied, a header element is created containing this text and added into the top of
12915 * the dropdown list (defaults to undefined, with no header element)
12919 * @cfg {String/Roo.Template} tpl The template to use to render the output
12923 * @cfg {Number} listWidth The width in pixels of the dropdown list (defaults to the width of the ComboBox field)
12925 listWidth: undefined,
12927 * @cfg {String} displayField The underlying data field name to bind to this CombBox (defaults to undefined if
12928 * mode = 'remote' or 'text' if mode = 'local')
12930 displayField: undefined,
12933 * @cfg {String} valueField The underlying data value name to bind to this CombBox (defaults to undefined if
12934 * mode = 'remote' or 'value' if mode = 'local').
12935 * Note: use of a valueField requires the user make a selection
12936 * in order for a value to be mapped.
12938 valueField: undefined,
12940 * @cfg {String} modalTitle The title of the dialog that pops up on mobile views.
12945 * @cfg {String} hiddenName If specified, a hidden form field with this name is dynamically generated to store the
12946 * field's data value (defaults to the underlying DOM element's name)
12948 hiddenName: undefined,
12950 * @cfg {String} listClass CSS class to apply to the dropdown list element (defaults to '')
12954 * @cfg {String} selectedClass CSS class to apply to the selected item in the dropdown list (defaults to 'x-combo-selected')
12956 selectedClass: 'active',
12959 * @cfg {Boolean/String} shadow True or "sides" for the default effect, "frame" for 4-way shadow, and "drop" for bottom-right
12963 * @cfg {String} listAlign A valid anchor position value. See {@link Roo.Element#alignTo} for details on supported
12964 * anchor positions (defaults to 'tl-bl')
12966 listAlign: 'tl-bl?',
12968 * @cfg {Number} maxHeight The maximum height in pixels of the dropdown list before scrollbars are shown (defaults to 300)
12972 * @cfg {String} triggerAction The action to execute when the trigger field is activated. Use 'all' to run the
12973 * query specified by the allQuery config option (defaults to 'query')
12975 triggerAction: 'query',
12977 * @cfg {Number} minChars The minimum number of characters the user must type before autocomplete and typeahead activate
12978 * (defaults to 4, does not apply if editable = false)
12982 * @cfg {Boolean} typeAhead True to populate and autoselect the remainder of the text being typed after a configurable
12983 * delay (typeAheadDelay) if it matches a known value (defaults to false)
12987 * @cfg {Number} queryDelay The length of time in milliseconds to delay between the start of typing and sending the
12988 * query to filter the dropdown list (defaults to 500 if mode = 'remote' or 10 if mode = 'local')
12992 * @cfg {Number} pageSize If greater than 0, a paging toolbar is displayed in the footer of the dropdown list and the
12993 * filter queries will execute with page start and limit parameters. Only applies when mode = 'remote' (defaults to 0)
12997 * @cfg {Boolean} selectOnFocus True to select any existing text in the field immediately on focus. Only applies
12998 * when editable = true (defaults to false)
13000 selectOnFocus:false,
13002 * @cfg {String} queryParam Name of the query as it will be passed on the querystring (defaults to 'query')
13004 queryParam: 'query',
13006 * @cfg {String} loadingText The text to display in the dropdown list while data is loading. Only applies
13007 * when mode = 'remote' (defaults to 'Loading...')
13009 loadingText: 'Loading...',
13011 * @cfg {Boolean} resizable True to add a resize handle to the bottom of the dropdown list (defaults to false)
13015 * @cfg {Number} handleHeight The height in pixels of the dropdown list resize handle if resizable = true (defaults to 8)
13019 * @cfg {Boolean} editable False to prevent the user from typing text directly into the field, just like a
13020 * traditional select (defaults to true)
13024 * @cfg {String} allQuery The text query to send to the server to return all records for the list with no filtering (defaults to '')
13028 * @cfg {String} mode Set to 'local' if the ComboBox loads local data (defaults to 'remote' which loads from the server)
13032 * @cfg {Number} minListWidth The minimum width of the dropdown list in pixels (defaults to 70, will be ignored if
13033 * listWidth has a higher value)
13037 * @cfg {Boolean} forceSelection True to restrict the selected value to one of the values in the list, false to
13038 * allow the user to set arbitrary text into the field (defaults to false)
13040 forceSelection:false,
13042 * @cfg {Number} typeAheadDelay The length of time in milliseconds to wait until the typeahead text is displayed
13043 * if typeAhead = true (defaults to 250)
13045 typeAheadDelay : 250,
13047 * @cfg {String} valueNotFoundText When using a name/value combo, if the value passed to setValue is not found in
13048 * the store, valueNotFoundText will be displayed as the field text if defined (defaults to undefined)
13050 valueNotFoundText : undefined,
13052 * @cfg {Boolean} blockFocus Prevents all focus calls, so it can work with things like HTML edtor bar
13054 blockFocus : false,
13057 * @cfg {Boolean} disableClear Disable showing of clear button.
13059 disableClear : false,
13061 * @cfg {Boolean} alwaysQuery Disable caching of results, and always send query
13063 alwaysQuery : false,
13066 * @cfg {Boolean} multiple (true|false) ComboBobArray, default false
13071 * @cfg {String} invalidClass The CSS class to use when marking a field invalid (defaults to "x-form-invalid")
13073 invalidClass : "has-warning",
13076 * @cfg {String} validClass The CSS class to use when marking a field valid (defaults to "x-form-invalid")
13078 validClass : "has-success",
13081 * @cfg {Boolean} specialFilter (true|false) special filter default false
13083 specialFilter : false,
13086 * @cfg {Boolean} mobileTouchView (true|false) show mobile touch view when using a mobile default true
13088 mobileTouchView : true,
13091 * @cfg {Boolean} useNativeIOS (true|false) render it as classic select for ios, not support dynamic load data (default false)
13093 useNativeIOS : false,
13096 * @cfg {Boolean} mobile_restrict_height (true|false) restrict height for touch view
13098 mobile_restrict_height : false,
13100 ios_options : false,
13112 btnPosition : 'right',
13113 triggerList : true,
13114 showToggleBtn : true,
13116 emptyResultText: 'Empty',
13117 triggerText : 'Select',
13120 // element that contains real text value.. (when hidden is used..)
13122 getAutoCreate : function()
13127 * Render classic select for iso
13130 if(Roo.isIOS && this.useNativeIOS){
13131 cfg = this.getAutoCreateNativeIOS();
13139 if(Roo.isTouch && this.mobileTouchView){
13140 cfg = this.getAutoCreateTouchView();
13147 if(!this.tickable){
13148 cfg = Roo.bootstrap.ComboBox.superclass.getAutoCreate.call(this);
13153 * ComboBox with tickable selections
13156 var align = this.labelAlign || this.parentLabelAlign();
13159 cls : 'form-group roo-combobox-tickable' //input-group
13162 var btn_text_select = '';
13163 var btn_text_done = '';
13164 var btn_text_cancel = '';
13166 if (this.btn_text_show) {
13167 btn_text_select = 'Select';
13168 btn_text_done = 'Done';
13169 btn_text_cancel = 'Cancel';
13174 cls : 'tickable-buttons',
13179 cls : 'btn btn-link btn-edit pull-' + this.btnPosition,
13180 //html : this.triggerText
13181 html: btn_text_select
13187 cls : 'btn btn-link btn-ok pull-' + this.btnPosition,
13189 html: btn_text_done
13195 cls : 'btn btn-link btn-cancel pull-' + this.btnPosition,
13197 html: btn_text_cancel
13203 buttons.cn.unshift({
13205 cls: 'roo-select2-search-field-input'
13211 Roo.each(buttons.cn, function(c){
13213 c.cls += ' btn-' + _this.size;
13216 if (_this.disabled) {
13227 cls: 'form-hidden-field'
13231 cls: 'roo-select2-choices',
13235 cls: 'roo-select2-search-field',
13246 cls: 'roo-select2-container input-group roo-select2-container-multi',
13251 // cls: 'typeahead typeahead-long dropdown-menu',
13252 // style: 'display:none; max-height:' + this.maxHeight + 'px;'
13257 if(this.hasFeedback && !this.allowBlank){
13261 cls: 'glyphicon form-control-feedback'
13264 combobox.cn.push(feedback);
13268 if (align ==='left' && this.fieldLabel.length) {
13270 cfg.cls += ' roo-form-group-label-left';
13275 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
13276 tooltip : 'This field is required'
13281 cls : 'control-label',
13282 html : this.fieldLabel
13294 var labelCfg = cfg.cn[1];
13295 var contentCfg = cfg.cn[2];
13298 if(this.indicatorpos == 'right'){
13304 cls : 'control-label',
13308 html : this.fieldLabel
13312 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
13313 tooltip : 'This field is required'
13328 labelCfg = cfg.cn[0];
13329 contentCfg = cfg.cn[1];
13333 if(this.labelWidth > 12){
13334 labelCfg.style = "width: " + this.labelWidth + 'px';
13337 if(this.labelWidth < 13 && this.labelmd == 0){
13338 this.labelmd = this.labelWidth;
13341 if(this.labellg > 0){
13342 labelCfg.cls += ' col-lg-' + this.labellg;
13343 contentCfg.cls += ' col-lg-' + (12 - this.labellg);
13346 if(this.labelmd > 0){
13347 labelCfg.cls += ' col-md-' + this.labelmd;
13348 contentCfg.cls += ' col-md-' + (12 - this.labelmd);
13351 if(this.labelsm > 0){
13352 labelCfg.cls += ' col-sm-' + this.labelsm;
13353 contentCfg.cls += ' col-sm-' + (12 - this.labelsm);
13356 if(this.labelxs > 0){
13357 labelCfg.cls += ' col-xs-' + this.labelxs;
13358 contentCfg.cls += ' col-xs-' + (12 - this.labelxs);
13362 } else if ( this.fieldLabel.length) {
13363 // Roo.log(" label");
13367 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
13368 tooltip : 'This field is required'
13372 //cls : 'input-group-addon',
13373 html : this.fieldLabel
13378 if(this.indicatorpos == 'right'){
13382 //cls : 'input-group-addon',
13383 html : this.fieldLabel
13387 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
13388 tooltip : 'This field is required'
13397 // Roo.log(" no label && no align");
13404 ['xs','sm','md','lg'].map(function(size){
13405 if (settings[size]) {
13406 cfg.cls += ' col-' + size + '-' + settings[size];
13414 _initEventsCalled : false,
13417 initEvents: function()
13419 if (this._initEventsCalled) { // as we call render... prevent looping...
13422 this._initEventsCalled = true;
13425 throw "can not find store for combo";
13428 this.indicator = this.indicatorEl();
13430 this.store = Roo.factory(this.store, Roo.data);
13431 this.store.parent = this;
13433 // if we are building from html. then this element is so complex, that we can not really
13434 // use the rendered HTML.
13435 // so we have to trash and replace the previous code.
13436 if (Roo.XComponent.build_from_html) {
13437 // remove this element....
13438 var e = this.el.dom, k=0;
13439 while (e ) { e = e.previousSibling; ++k;}
13444 this.rendered = false;
13446 this.render(this.parent().getChildContainer(true), k);
13449 if(Roo.isIOS && this.useNativeIOS){
13450 this.initIOSView();
13458 if(Roo.isTouch && this.mobileTouchView){
13459 this.initTouchView();
13464 this.initTickableEvents();
13468 Roo.bootstrap.ComboBox.superclass.initEvents.call(this);
13470 if(this.hiddenName){
13472 this.hiddenField = this.el.select('input.form-hidden-field',true).first();
13474 this.hiddenField.dom.value =
13475 this.hiddenValue !== undefined ? this.hiddenValue :
13476 this.value !== undefined ? this.value : '';
13478 // prevent input submission
13479 this.el.dom.removeAttribute('name');
13480 this.hiddenField.dom.setAttribute('name', this.hiddenName);
13485 // this.el.dom.setAttribute('autocomplete', 'off');
13488 var cls = 'x-combo-list';
13490 //this.list = new Roo.Layer({
13491 // shadow: this.shadow, cls: [cls, this.listClass].join(' '), constrain:false
13497 var lw = _this.listWidth || Math.max(_this.inputEl().getWidth(), _this.minListWidth);
13498 _this.list.setWidth(lw);
13501 this.list.on('mouseover', this.onViewOver, this);
13502 this.list.on('mousemove', this.onViewMove, this);
13503 this.list.on('scroll', this.onViewScroll, this);
13506 this.list.swallowEvent('mousewheel');
13507 this.assetHeight = 0;
13510 this.header = this.list.createChild({cls:cls+'-hd', html: this.title});
13511 this.assetHeight += this.header.getHeight();
13514 this.innerList = this.list.createChild({cls:cls+'-inner'});
13515 this.innerList.on('mouseover', this.onViewOver, this);
13516 this.innerList.on('mousemove', this.onViewMove, this);
13517 this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
13519 if(this.allowBlank && !this.pageSize && !this.disableClear){
13520 this.footer = this.list.createChild({cls:cls+'-ft'});
13521 this.pageTb = new Roo.Toolbar(this.footer);
13525 this.footer = this.list.createChild({cls:cls+'-ft'});
13526 this.pageTb = new Roo.PagingToolbar(this.footer, this.store,
13527 {pageSize: this.pageSize});
13531 if (this.pageTb && this.allowBlank && !this.disableClear) {
13533 this.pageTb.add(new Roo.Toolbar.Fill(), {
13534 cls: 'x-btn-icon x-btn-clear',
13536 handler: function()
13539 _this.clearValue();
13540 _this.onSelect(false, -1);
13545 this.assetHeight += this.footer.getHeight();
13550 this.tpl = '<li><a href="#">{' + this.displayField + '}</a></li>';
13553 this.view = new Roo.View(this.list, this.tpl, {
13554 singleSelect:true, store: this.store, selectedClass: this.selectedClass
13556 //this.view.wrapEl.setDisplayed(false);
13557 this.view.on('click', this.onViewClick, this);
13560 this.store.on('beforeload', this.onBeforeLoad, this);
13561 this.store.on('load', this.onLoad, this);
13562 this.store.on('loadexception', this.onLoadException, this);
13564 if(this.resizable){
13565 this.resizer = new Roo.Resizable(this.list, {
13566 pinned:true, handles:'se'
13568 this.resizer.on('resize', function(r, w, h){
13569 this.maxHeight = h-this.handleHeight-this.list.getFrameWidth('tb')-this.assetHeight;
13570 this.listWidth = w;
13571 this.innerList.setWidth(w - this.list.getFrameWidth('lr'));
13572 this.restrictHeight();
13574 this[this.pageSize?'footer':'innerList'].setStyle('margin-bottom', this.handleHeight+'px');
13577 if(!this.editable){
13578 this.editable = true;
13579 this.setEditable(false);
13584 if (typeof(this.events.add.listeners) != 'undefined') {
13586 this.addicon = this.wrap.createChild(
13587 {tag: 'img', src: Roo.BLANK_IMAGE_URL, cls: 'x-form-combo-add' });
13589 this.addicon.on('click', function(e) {
13590 this.fireEvent('add', this);
13593 if (typeof(this.events.edit.listeners) != 'undefined') {
13595 this.editicon = this.wrap.createChild(
13596 {tag: 'img', src: Roo.BLANK_IMAGE_URL, cls: 'x-form-combo-edit' });
13597 if (this.addicon) {
13598 this.editicon.setStyle('margin-left', '40px');
13600 this.editicon.on('click', function(e) {
13602 // we fire even if inothing is selected..
13603 this.fireEvent('edit', this, this.lastData );
13609 this.keyNav = new Roo.KeyNav(this.inputEl(), {
13610 "up" : function(e){
13611 this.inKeyMode = true;
13615 "down" : function(e){
13616 if(!this.isExpanded()){
13617 this.onTriggerClick();
13619 this.inKeyMode = true;
13624 "enter" : function(e){
13625 // this.onViewClick();
13629 if(this.fireEvent("specialkey", this, e)){
13630 this.onViewClick(false);
13636 "esc" : function(e){
13640 "tab" : function(e){
13643 if(this.fireEvent("specialkey", this, e)){
13644 this.onViewClick(false);
13652 doRelay : function(foo, bar, hname){
13653 if(hname == 'down' || this.scope.isExpanded()){
13654 return Roo.KeyNav.prototype.doRelay.apply(this, arguments);
13663 this.queryDelay = Math.max(this.queryDelay || 10,
13664 this.mode == 'local' ? 10 : 250);
13667 this.dqTask = new Roo.util.DelayedTask(this.initQuery, this);
13669 if(this.typeAhead){
13670 this.taTask = new Roo.util.DelayedTask(this.onTypeAhead, this);
13672 if(this.editable !== false){
13673 this.inputEl().on("keyup", this.onKeyUp, this);
13675 if(this.forceSelection){
13676 this.inputEl().on('blur', this.doForce, this);
13680 this.choices = this.el.select('ul.roo-select2-choices', true).first();
13681 this.searchField = this.el.select('ul li.roo-select2-search-field', true).first();
13685 initTickableEvents: function()
13689 if(this.hiddenName){
13691 this.hiddenField = this.el.select('input.form-hidden-field',true).first();
13693 this.hiddenField.dom.value =
13694 this.hiddenValue !== undefined ? this.hiddenValue :
13695 this.value !== undefined ? this.value : '';
13697 // prevent input submission
13698 this.el.dom.removeAttribute('name');
13699 this.hiddenField.dom.setAttribute('name', this.hiddenName);
13704 // this.list = this.el.select('ul.dropdown-menu',true).first();
13706 this.choices = this.el.select('ul.roo-select2-choices', true).first();
13707 this.searchField = this.el.select('ul li.roo-select2-search-field', true).first();
13708 if(this.triggerList){
13709 this.searchField.on("click", this.onSearchFieldClick, this, {preventDefault:true});
13712 this.trigger = this.el.select('.tickable-buttons > .btn-edit', true).first();
13713 this.trigger.on("click", this.onTickableTriggerClick, this, {preventDefault:true});
13715 this.okBtn = this.el.select('.tickable-buttons > .btn-ok', true).first();
13716 this.cancelBtn = this.el.select('.tickable-buttons > .btn-cancel', true).first();
13718 this.okBtn.on('click', this.onTickableFooterButtonClick, this, this.okBtn);
13719 this.cancelBtn.on('click', this.onTickableFooterButtonClick, this, this.cancelBtn);
13721 this.trigger.setVisibilityMode(Roo.Element.DISPLAY);
13722 this.okBtn.setVisibilityMode(Roo.Element.DISPLAY);
13723 this.cancelBtn.setVisibilityMode(Roo.Element.DISPLAY);
13726 this.cancelBtn.hide();
13731 var lw = _this.listWidth || Math.max(_this.inputEl().getWidth(), _this.minListWidth);
13732 _this.list.setWidth(lw);
13735 this.list.on('mouseover', this.onViewOver, this);
13736 this.list.on('mousemove', this.onViewMove, this);
13738 this.list.on('scroll', this.onViewScroll, this);
13741 this.tpl = '<li class="roo-select2-result"><div class="checkbox"><input id="{roo-id}"' +
13742 'type="checkbox" {roo-data-checked}><label for="{roo-id}"><b>{' + this.displayField + '}</b></label></div></li>';
13745 this.view = new Roo.View(this.list, this.tpl, {
13750 selectedClass: this.selectedClass
13753 //this.view.wrapEl.setDisplayed(false);
13754 this.view.on('click', this.onViewClick, this);
13758 this.store.on('beforeload', this.onBeforeLoad, this);
13759 this.store.on('load', this.onLoad, this);
13760 this.store.on('loadexception', this.onLoadException, this);
13763 this.keyNav = new Roo.KeyNav(this.tickableInputEl(), {
13764 "up" : function(e){
13765 this.inKeyMode = true;
13769 "down" : function(e){
13770 this.inKeyMode = true;
13774 "enter" : function(e){
13775 if(this.fireEvent("specialkey", this, e)){
13776 this.onViewClick(false);
13782 "esc" : function(e){
13783 this.onTickableFooterButtonClick(e, false, false);
13786 "tab" : function(e){
13787 this.fireEvent("specialkey", this, e);
13789 this.onTickableFooterButtonClick(e, false, false);
13796 doRelay : function(e, fn, key){
13797 if(this.scope.isExpanded()){
13798 return Roo.KeyNav.prototype.doRelay.apply(this, arguments);
13807 this.queryDelay = Math.max(this.queryDelay || 10,
13808 this.mode == 'local' ? 10 : 250);
13811 this.dqTask = new Roo.util.DelayedTask(this.initQuery, this);
13813 if(this.typeAhead){
13814 this.taTask = new Roo.util.DelayedTask(this.onTypeAhead, this);
13817 if(this.editable !== false){
13818 this.tickableInputEl().on("keyup", this.onKeyUp, this);
13821 this.indicator = this.indicatorEl();
13823 if(this.indicator){
13824 this.indicator.setVisibilityMode(Roo.Element.DISPLAY);
13825 this.indicator.hide();
13830 onDestroy : function(){
13832 this.view.setStore(null);
13833 this.view.el.removeAllListeners();
13834 this.view.el.remove();
13835 this.view.purgeListeners();
13838 this.list.dom.innerHTML = '';
13842 this.store.un('beforeload', this.onBeforeLoad, this);
13843 this.store.un('load', this.onLoad, this);
13844 this.store.un('loadexception', this.onLoadException, this);
13846 Roo.bootstrap.ComboBox.superclass.onDestroy.call(this);
13850 fireKey : function(e){
13851 if(e.isNavKeyPress() && !this.list.isVisible()){
13852 this.fireEvent("specialkey", this, e);
13857 onResize: function(w, h){
13858 // Roo.bootstrap.ComboBox.superclass.onResize.apply(this, arguments);
13860 // if(typeof w != 'number'){
13861 // // we do not handle it!?!?
13864 // var tw = this.trigger.getWidth();
13865 // // tw += this.addicon ? this.addicon.getWidth() : 0;
13866 // // tw += this.editicon ? this.editicon.getWidth() : 0;
13868 // this.inputEl().setWidth( this.adjustWidth('input', x));
13870 // //this.trigger.setStyle('left', x+'px');
13872 // if(this.list && this.listWidth === undefined){
13873 // var lw = Math.max(x + this.trigger.getWidth(), this.minListWidth);
13874 // this.list.setWidth(lw);
13875 // this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
13883 * Allow or prevent the user from directly editing the field text. If false is passed,
13884 * the user will only be able to select from the items defined in the dropdown list. This method
13885 * is the runtime equivalent of setting the 'editable' config option at config time.
13886 * @param {Boolean} value True to allow the user to directly edit the field text
13888 setEditable : function(value){
13889 if(value == this.editable){
13892 this.editable = value;
13894 this.inputEl().dom.setAttribute('readOnly', true);
13895 this.inputEl().on('mousedown', this.onTriggerClick, this);
13896 this.inputEl().addClass('x-combo-noedit');
13898 this.inputEl().dom.setAttribute('readOnly', false);
13899 this.inputEl().un('mousedown', this.onTriggerClick, this);
13900 this.inputEl().removeClass('x-combo-noedit');
13906 onBeforeLoad : function(combo,opts){
13907 if(!this.hasFocus){
13911 this.list.dom.innerHTML = '<li class="loading-indicator">'+(this.loadingText||'loading')+'</li>' ;
13913 this.restrictHeight();
13914 this.selectedIndex = -1;
13918 onLoad : function(){
13920 this.hasQuery = false;
13922 if(!this.hasFocus){
13926 if(typeof(this.loading) !== 'undefined' && this.loading !== null){
13927 this.loading.hide();
13930 if(this.store.getCount() > 0){
13933 this.restrictHeight();
13934 if(this.lastQuery == this.allQuery){
13935 if(this.editable && !this.tickable){
13936 this.inputEl().dom.select();
13940 !this.selectByValue(this.value, true) &&
13943 !this.store.lastOptions ||
13944 typeof(this.store.lastOptions.add) == 'undefined' ||
13945 this.store.lastOptions.add != true
13948 this.select(0, true);
13951 if(this.autoFocus){
13954 if(this.typeAhead && this.lastKey != Roo.EventObject.BACKSPACE && this.lastKey != Roo.EventObject.DELETE){
13955 this.taTask.delay(this.typeAheadDelay);
13959 this.onEmptyResults();
13965 onLoadException : function()
13967 this.hasQuery = false;
13969 if(typeof(this.loading) !== 'undefined' && this.loading !== null){
13970 this.loading.hide();
13973 if(this.tickable && this.editable){
13978 // only causes errors at present
13979 //Roo.log(this.store.reader.jsonData);
13980 //if (this.store && typeof(this.store.reader.jsonData.errorMsg) != 'undefined') {
13982 //Roo.MessageBox.alert("Error loading",this.store.reader.jsonData.errorMsg);
13988 onTypeAhead : function(){
13989 if(this.store.getCount() > 0){
13990 var r = this.store.getAt(0);
13991 var newValue = r.data[this.displayField];
13992 var len = newValue.length;
13993 var selStart = this.getRawValue().length;
13995 if(selStart != len){
13996 this.setRawValue(newValue);
13997 this.selectText(selStart, newValue.length);
14003 onSelect : function(record, index){
14005 if(this.fireEvent('beforeselect', this, record, index) !== false){
14007 this.setFromData(index > -1 ? record.data : false);
14010 this.fireEvent('select', this, record, index);
14015 * Returns the currently selected field value or empty string if no value is set.
14016 * @return {String} value The selected value
14018 getValue : function()
14020 if(Roo.isIOS && this.useNativeIOS){
14021 return this.ios_options[this.inputEl().dom.selectedIndex].data[this.valueField];
14025 return (this.hiddenField) ? this.hiddenField.dom.value : this.value;
14028 if(this.valueField){
14029 return typeof this.value != 'undefined' ? this.value : '';
14031 return Roo.bootstrap.ComboBox.superclass.getValue.call(this);
14035 getRawValue : function()
14037 if(Roo.isIOS && this.useNativeIOS){
14038 return this.ios_options[this.inputEl().dom.selectedIndex].data[this.displayField];
14041 var v = this.inputEl().getValue();
14047 * Clears any text/value currently set in the field
14049 clearValue : function(){
14051 if(this.hiddenField){
14052 this.hiddenField.dom.value = '';
14055 this.setRawValue('');
14056 this.lastSelectionText = '';
14057 this.lastData = false;
14059 var close = this.closeTriggerEl();
14070 * Sets the specified value into the field. If the value finds a match, the corresponding record text
14071 * will be displayed in the field. If the value does not match the data value of an existing item,
14072 * and the valueNotFoundText config option is defined, it will be displayed as the default field text.
14073 * Otherwise the field will be blank (although the value will still be set).
14074 * @param {String} value The value to match
14076 setValue : function(v)
14078 if(Roo.isIOS && this.useNativeIOS){
14079 this.setIOSValue(v);
14089 if(this.valueField){
14090 var r = this.findRecord(this.valueField, v);
14092 text = r.data[this.displayField];
14093 }else if(this.valueNotFoundText !== undefined){
14094 text = this.valueNotFoundText;
14097 this.lastSelectionText = text;
14098 if(this.hiddenField){
14099 this.hiddenField.dom.value = v;
14101 Roo.bootstrap.ComboBox.superclass.setValue.call(this, text);
14104 var close = this.closeTriggerEl();
14107 (v && (v.length || v * 1 > 0)) ? close.show() : close.hide();
14113 * @property {Object} the last set data for the element
14118 * Sets the value of the field based on a object which is related to the record format for the store.
14119 * @param {Object} value the value to set as. or false on reset?
14121 setFromData : function(o){
14128 var dv = ''; // display value
14129 var vv = ''; // value value..
14131 if (this.displayField) {
14132 dv = !o || typeof(o[this.displayField]) == 'undefined' ? '' : o[this.displayField];
14134 // this is an error condition!!!
14135 Roo.log('no displayField value set for '+ (this.name ? this.name : this.id));
14138 if(this.valueField){
14139 vv = !o || typeof(o[this.valueField]) == 'undefined' ? dv : o[this.valueField];
14142 var close = this.closeTriggerEl();
14145 if(dv.length || vv * 1 > 0){
14147 this.blockFocus=true;
14153 if(this.hiddenField){
14154 this.hiddenField.dom.value = vv;
14156 this.lastSelectionText = dv;
14157 Roo.bootstrap.ComboBox.superclass.setValue.call(this, dv);
14161 // no hidden field.. - we store the value in 'value', but still display
14162 // display field!!!!
14163 this.lastSelectionText = dv;
14164 Roo.bootstrap.ComboBox.superclass.setValue.call(this, dv);
14171 reset : function(){
14172 // overridden so that last data is reset..
14179 this.setValue(this.originalValue);
14180 //this.clearInvalid();
14181 this.lastData = false;
14183 this.view.clearSelections();
14189 findRecord : function(prop, value){
14191 if(this.store.getCount() > 0){
14192 this.store.each(function(r){
14193 if(r.data[prop] == value){
14203 getName: function()
14205 // returns hidden if it's set..
14206 if (!this.rendered) {return ''};
14207 return !this.hiddenName && this.inputEl().dom.name ? this.inputEl().dom.name : (this.hiddenName || '');
14211 onViewMove : function(e, t){
14212 this.inKeyMode = false;
14216 onViewOver : function(e, t){
14217 if(this.inKeyMode){ // prevent key nav and mouse over conflicts
14220 var item = this.view.findItemFromChild(t);
14223 var index = this.view.indexOf(item);
14224 this.select(index, false);
14229 onViewClick : function(view, doFocus, el, e)
14231 var index = this.view.getSelectedIndexes()[0];
14233 var r = this.store.getAt(index);
14237 if(typeof(e) != 'undefined' && e.getTarget().nodeName.toLowerCase() != 'input'){
14244 Roo.each(this.tickItems, function(v,k){
14246 if(typeof(v) != 'undefined' && v[_this.valueField] == r.data[_this.valueField]){
14248 _this.tickItems.splice(k, 1);
14250 if(typeof(e) == 'undefined' && view == false){
14251 Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked = false;
14263 if(this.fireEvent('tick', this, r, index, Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked) !== false){
14264 this.tickItems.push(r.data);
14267 if(typeof(e) == 'undefined' && view == false){
14268 Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked = true;
14275 this.onSelect(r, index);
14277 if(doFocus !== false && !this.blockFocus){
14278 this.inputEl().focus();
14283 restrictHeight : function(){
14284 //this.innerList.dom.style.height = '';
14285 //var inner = this.innerList.dom;
14286 //var h = Math.max(inner.clientHeight, inner.offsetHeight, inner.scrollHeight);
14287 //this.innerList.setHeight(h < this.maxHeight ? 'auto' : this.maxHeight);
14288 //this.list.beginUpdate();
14289 //this.list.setHeight(this.innerList.getHeight()+this.list.getFrameWidth('tb')+(this.resizable?this.handleHeight:0)+this.assetHeight);
14290 this.list.alignTo(this.inputEl(), this.listAlign);
14291 this.list.alignTo(this.inputEl(), this.listAlign);
14292 //this.list.endUpdate();
14296 onEmptyResults : function(){
14298 if(this.tickable && this.editable){
14299 this.hasFocus = false;
14300 this.restrictHeight();
14308 * Returns true if the dropdown list is expanded, else false.
14310 isExpanded : function(){
14311 return this.list.isVisible();
14315 * Select an item in the dropdown list by its data value. This function does NOT cause the select event to fire.
14316 * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
14317 * @param {String} value The data value of the item to select
14318 * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
14319 * selected item if it is not currently in view (defaults to true)
14320 * @return {Boolean} True if the value matched an item in the list, else false
14322 selectByValue : function(v, scrollIntoView){
14323 if(v !== undefined && v !== null){
14324 var r = this.findRecord(this.valueField || this.displayField, v);
14326 this.select(this.store.indexOf(r), scrollIntoView);
14334 * Select an item in the dropdown list by its numeric index in the list. This function does NOT cause the select event to fire.
14335 * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
14336 * @param {Number} index The zero-based index of the list item to select
14337 * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
14338 * selected item if it is not currently in view (defaults to true)
14340 select : function(index, scrollIntoView){
14341 this.selectedIndex = index;
14342 this.view.select(index);
14343 if(scrollIntoView !== false){
14344 var el = this.view.getNode(index);
14346 * el && !this.multiple && !this.tickable // not sure why we disable multiple before..
14349 this.list.scrollChildIntoView(el, false);
14355 selectNext : function(){
14356 var ct = this.store.getCount();
14358 if(this.selectedIndex == -1){
14360 }else if(this.selectedIndex < ct-1){
14361 this.select(this.selectedIndex+1);
14367 selectPrev : function(){
14368 var ct = this.store.getCount();
14370 if(this.selectedIndex == -1){
14372 }else if(this.selectedIndex != 0){
14373 this.select(this.selectedIndex-1);
14379 onKeyUp : function(e){
14380 if(this.editable !== false && !e.isSpecialKey()){
14381 this.lastKey = e.getKey();
14382 this.dqTask.delay(this.queryDelay);
14387 validateBlur : function(){
14388 return !this.list || !this.list.isVisible();
14392 initQuery : function(){
14394 var v = this.getRawValue();
14396 if(this.tickable && this.editable){
14397 v = this.tickableInputEl().getValue();
14404 doForce : function(){
14405 if(this.inputEl().dom.value.length > 0){
14406 this.inputEl().dom.value =
14407 this.lastSelectionText === undefined ? '' : this.lastSelectionText;
14413 * Execute a query to filter the dropdown list. Fires the beforequery event prior to performing the
14414 * query allowing the query action to be canceled if needed.
14415 * @param {String} query The SQL query to execute
14416 * @param {Boolean} forceAll True to force the query to execute even if there are currently fewer characters
14417 * in the field than the minimum specified by the minChars config option. It also clears any filter previously
14418 * saved in the current store (defaults to false)
14420 doQuery : function(q, forceAll){
14422 if(q === undefined || q === null){
14427 forceAll: forceAll,
14431 if(this.fireEvent('beforequery', qe)===false || qe.cancel){
14436 forceAll = qe.forceAll;
14437 if(forceAll === true || (q.length >= this.minChars)){
14439 this.hasQuery = true;
14441 if(this.lastQuery != q || this.alwaysQuery){
14442 this.lastQuery = q;
14443 if(this.mode == 'local'){
14444 this.selectedIndex = -1;
14446 this.store.clearFilter();
14449 if(this.specialFilter){
14450 this.fireEvent('specialfilter', this);
14455 this.store.filter(this.displayField, q);
14458 this.store.fireEvent("datachanged", this.store);
14465 this.store.baseParams[this.queryParam] = q;
14467 var options = {params : this.getParams(q)};
14470 options.add = true;
14471 options.params.start = this.page * this.pageSize;
14474 this.store.load(options);
14477 * this code will make the page width larger, at the beginning, the list not align correctly,
14478 * we should expand the list on onLoad
14479 * so command out it
14484 this.selectedIndex = -1;
14489 this.loadNext = false;
14493 getParams : function(q){
14495 //p[this.queryParam] = q;
14499 p.limit = this.pageSize;
14505 * Hides the dropdown list if it is currently expanded. Fires the 'collapse' event on completion.
14507 collapse : function(){
14508 if(!this.isExpanded()){
14514 this.hasFocus = false;
14518 this.cancelBtn.hide();
14519 this.trigger.show();
14522 this.tickableInputEl().dom.value = '';
14523 this.tickableInputEl().blur();
14528 Roo.get(document).un('mousedown', this.collapseIf, this);
14529 Roo.get(document).un('mousewheel', this.collapseIf, this);
14530 if (!this.editable) {
14531 Roo.get(document).un('keydown', this.listKeyPress, this);
14533 this.fireEvent('collapse', this);
14539 collapseIf : function(e){
14540 var in_combo = e.within(this.el);
14541 var in_list = e.within(this.list);
14542 var is_list = (Roo.get(e.getTarget()).id == this.list.id) ? true : false;
14544 if (in_combo || in_list || is_list) {
14545 //e.stopPropagation();
14550 this.onTickableFooterButtonClick(e, false, false);
14558 * Expands the dropdown list if it is currently hidden. Fires the 'expand' event on completion.
14560 expand : function(){
14562 if(this.isExpanded() || !this.hasFocus){
14566 var lw = this.listWidth || Math.max(this.inputEl().getWidth(), this.minListWidth);
14567 this.list.setWidth(lw);
14573 this.restrictHeight();
14577 this.tickItems = Roo.apply([], this.item);
14580 this.cancelBtn.show();
14581 this.trigger.hide();
14584 this.tickableInputEl().focus();
14589 Roo.get(document).on('mousedown', this.collapseIf, this);
14590 Roo.get(document).on('mousewheel', this.collapseIf, this);
14591 if (!this.editable) {
14592 Roo.get(document).on('keydown', this.listKeyPress, this);
14595 this.fireEvent('expand', this);
14599 // Implements the default empty TriggerField.onTriggerClick function
14600 onTriggerClick : function(e)
14602 Roo.log('trigger click');
14604 if(this.disabled || !this.triggerList){
14609 this.loadNext = false;
14611 if(this.isExpanded()){
14613 if (!this.blockFocus) {
14614 this.inputEl().focus();
14618 this.hasFocus = true;
14619 if(this.triggerAction == 'all') {
14620 this.doQuery(this.allQuery, true);
14622 this.doQuery(this.getRawValue());
14624 if (!this.blockFocus) {
14625 this.inputEl().focus();
14630 onTickableTriggerClick : function(e)
14637 this.loadNext = false;
14638 this.hasFocus = true;
14640 if(this.triggerAction == 'all') {
14641 this.doQuery(this.allQuery, true);
14643 this.doQuery(this.getRawValue());
14647 onSearchFieldClick : function(e)
14649 if(this.hasFocus && !this.disabled && e.getTarget().nodeName.toLowerCase() != 'button'){
14650 this.onTickableFooterButtonClick(e, false, false);
14654 if(this.hasFocus || this.disabled || e.getTarget().nodeName.toLowerCase() == 'button'){
14659 this.loadNext = false;
14660 this.hasFocus = true;
14662 if(this.triggerAction == 'all') {
14663 this.doQuery(this.allQuery, true);
14665 this.doQuery(this.getRawValue());
14669 listKeyPress : function(e)
14671 //Roo.log('listkeypress');
14672 // scroll to first matching element based on key pres..
14673 if (e.isSpecialKey()) {
14676 var k = String.fromCharCode(e.getKey()).toUpperCase();
14679 var csel = this.view.getSelectedNodes();
14680 var cselitem = false;
14682 var ix = this.view.indexOf(csel[0]);
14683 cselitem = this.store.getAt(ix);
14684 if (!cselitem.get(this.displayField) || cselitem.get(this.displayField).substring(0,1).toUpperCase() != k) {
14690 this.store.each(function(v) {
14692 // start at existing selection.
14693 if (cselitem.id == v.id) {
14699 if (v.get(this.displayField) && v.get(this.displayField).substring(0,1).toUpperCase() == k) {
14700 match = this.store.indexOf(v);
14706 if (match === false) {
14707 return true; // no more action?
14710 this.view.select(match);
14711 var sn = Roo.get(this.view.getSelectedNodes()[0]);
14712 sn.scrollIntoView(sn.dom.parentNode, false);
14715 onViewScroll : function(e, t){
14717 if(this.view.el.getScroll().top == 0 ||this.view.el.getScroll().top < this.view.el.dom.scrollHeight - this.view.el.dom.clientHeight || !this.hasFocus || !this.append || this.hasQuery){
14721 this.hasQuery = true;
14723 this.loading = this.list.select('.loading', true).first();
14725 if(this.loading === null){
14726 this.list.createChild({
14728 cls: 'loading roo-select2-more-results roo-select2-active',
14729 html: 'Loading more results...'
14732 this.loading = this.list.select('.loading', true).first();
14734 this.loading.setVisibilityMode(Roo.Element.DISPLAY);
14736 this.loading.hide();
14739 this.loading.show();
14744 this.loadNext = true;
14746 (function() { _combo.doQuery(_combo.allQuery, true); }).defer(500);
14751 addItem : function(o)
14753 var dv = ''; // display value
14755 if (this.displayField) {
14756 dv = !o || typeof(o[this.displayField]) == 'undefined' ? '' : o[this.displayField];
14758 // this is an error condition!!!
14759 Roo.log('no displayField value set for '+ (this.name ? this.name : this.id));
14766 var choice = this.choices.createChild({
14768 cls: 'roo-select2-search-choice',
14777 cls: 'roo-select2-search-choice-close fa fa-times',
14782 }, this.searchField);
14784 var close = choice.select('a.roo-select2-search-choice-close', true).first();
14786 close.on('click', this.onRemoveItem, this, { item : choice, data : o} );
14794 this.inputEl().dom.value = '';
14799 onRemoveItem : function(e, _self, o)
14801 e.preventDefault();
14803 this.lastItem = Roo.apply([], this.item);
14805 var index = this.item.indexOf(o.data) * 1;
14808 Roo.log('not this item?!');
14812 this.item.splice(index, 1);
14817 this.fireEvent('remove', this, e);
14823 syncValue : function()
14825 if(!this.item.length){
14832 Roo.each(this.item, function(i){
14833 if(_this.valueField){
14834 value.push(i[_this.valueField]);
14841 this.value = value.join(',');
14843 if(this.hiddenField){
14844 this.hiddenField.dom.value = this.value;
14847 this.store.fireEvent("datachanged", this.store);
14852 clearItem : function()
14854 if(!this.multiple){
14860 Roo.each(this.choices.select('>li.roo-select2-search-choice', true).elements, function(c){
14868 if(this.tickable && !Roo.isTouch){
14869 this.view.refresh();
14873 inputEl: function ()
14875 if(Roo.isIOS && this.useNativeIOS){
14876 return this.el.select('select.roo-ios-select', true).first();
14879 if(Roo.isTouch && this.mobileTouchView){
14880 return this.el.select('input.form-control',true).first();
14884 return this.searchField;
14887 return this.el.select('input.form-control',true).first();
14890 onTickableFooterButtonClick : function(e, btn, el)
14892 e.preventDefault();
14894 this.lastItem = Roo.apply([], this.item);
14896 if(btn && btn.name == 'cancel'){
14897 this.tickItems = Roo.apply([], this.item);
14906 Roo.each(this.tickItems, function(o){
14914 validate : function()
14916 if(this.getVisibilityEl().hasClass('hidden')){
14920 var v = this.getRawValue();
14923 v = this.getValue();
14926 if(this.disabled || this.allowBlank || v.length){
14931 this.markInvalid();
14935 tickableInputEl : function()
14937 if(!this.tickable || !this.editable){
14938 return this.inputEl();
14941 return this.inputEl().select('.roo-select2-search-field-input', true).first();
14945 getAutoCreateTouchView : function()
14950 cls: 'form-group' //input-group
14956 type : this.inputType,
14957 cls : 'form-control x-combo-noedit',
14958 autocomplete: 'new-password',
14959 placeholder : this.placeholder || '',
14964 input.name = this.name;
14968 input.cls += ' input-' + this.size;
14971 if (this.disabled) {
14972 input.disabled = true;
14983 inputblock.cls += ' input-group';
14985 inputblock.cn.unshift({
14987 cls : 'input-group-addon',
14992 if(this.removable && !this.multiple){
14993 inputblock.cls += ' roo-removable';
14995 inputblock.cn.push({
14998 cls : 'roo-combo-removable-btn close'
15002 if(this.hasFeedback && !this.allowBlank){
15004 inputblock.cls += ' has-feedback';
15006 inputblock.cn.push({
15008 cls: 'glyphicon form-control-feedback'
15015 inputblock.cls += (this.before) ? '' : ' input-group';
15017 inputblock.cn.push({
15019 cls : 'input-group-addon',
15030 cls: 'form-hidden-field'
15044 cls: 'form-hidden-field'
15048 cls: 'roo-select2-choices',
15052 cls: 'roo-select2-search-field',
15065 cls: 'roo-select2-container input-group roo-touchview-combobox ',
15071 if(!this.multiple && this.showToggleBtn){
15078 if (this.caret != false) {
15081 cls: 'fa fa-' + this.caret
15088 cls : 'input-group-addon btn dropdown-toggle',
15093 cls: 'combobox-clear',
15107 combobox.cls += ' roo-select2-container-multi';
15110 var align = this.labelAlign || this.parentLabelAlign();
15112 if (align ==='left' && this.fieldLabel.length) {
15117 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
15118 tooltip : 'This field is required'
15122 cls : 'control-label',
15123 html : this.fieldLabel
15134 var labelCfg = cfg.cn[1];
15135 var contentCfg = cfg.cn[2];
15138 if(this.indicatorpos == 'right'){
15143 cls : 'control-label',
15147 html : this.fieldLabel
15151 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
15152 tooltip : 'This field is required'
15165 labelCfg = cfg.cn[0];
15166 contentCfg = cfg.cn[1];
15171 if(this.labelWidth > 12){
15172 labelCfg.style = "width: " + this.labelWidth + 'px';
15175 if(this.labelWidth < 13 && this.labelmd == 0){
15176 this.labelmd = this.labelWidth;
15179 if(this.labellg > 0){
15180 labelCfg.cls += ' col-lg-' + this.labellg;
15181 contentCfg.cls += ' col-lg-' + (12 - this.labellg);
15184 if(this.labelmd > 0){
15185 labelCfg.cls += ' col-md-' + this.labelmd;
15186 contentCfg.cls += ' col-md-' + (12 - this.labelmd);
15189 if(this.labelsm > 0){
15190 labelCfg.cls += ' col-sm-' + this.labelsm;
15191 contentCfg.cls += ' col-sm-' + (12 - this.labelsm);
15194 if(this.labelxs > 0){
15195 labelCfg.cls += ' col-xs-' + this.labelxs;
15196 contentCfg.cls += ' col-xs-' + (12 - this.labelxs);
15200 } else if ( this.fieldLabel.length) {
15204 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
15205 tooltip : 'This field is required'
15209 cls : 'control-label',
15210 html : this.fieldLabel
15221 if(this.indicatorpos == 'right'){
15225 cls : 'control-label',
15226 html : this.fieldLabel,
15230 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
15231 tooltip : 'This field is required'
15248 var settings = this;
15250 ['xs','sm','md','lg'].map(function(size){
15251 if (settings[size]) {
15252 cfg.cls += ' col-' + size + '-' + settings[size];
15259 initTouchView : function()
15261 this.renderTouchView();
15263 this.touchViewEl.on('scroll', function(){
15264 this.el.dom.scrollTop = 0;
15267 this.originalValue = this.getValue();
15269 this.triggerEl = this.el.select('span.dropdown-toggle',true).first();
15271 this.inputEl().on("click", this.showTouchView, this);
15272 if (this.triggerEl) {
15273 this.triggerEl.on("click", this.showTouchView, this);
15277 this.touchViewFooterEl.select('.roo-touch-view-cancel', true).first().on('click', this.hideTouchView, this);
15278 this.touchViewFooterEl.select('.roo-touch-view-ok', true).first().on('click', this.setTouchViewValue, this);
15280 this.maskEl = new Roo.LoadMask(this.touchViewEl, { store : this.store, msgCls: 'roo-el-mask-msg' });
15282 this.store.on('beforeload', this.onTouchViewBeforeLoad, this);
15283 this.store.on('load', this.onTouchViewLoad, this);
15284 this.store.on('loadexception', this.onTouchViewLoadException, this);
15286 if(this.hiddenName){
15288 this.hiddenField = this.el.select('input.form-hidden-field',true).first();
15290 this.hiddenField.dom.value =
15291 this.hiddenValue !== undefined ? this.hiddenValue :
15292 this.value !== undefined ? this.value : '';
15294 this.el.dom.removeAttribute('name');
15295 this.hiddenField.dom.setAttribute('name', this.hiddenName);
15299 this.choices = this.el.select('ul.roo-select2-choices', true).first();
15300 this.searchField = this.el.select('ul li.roo-select2-search-field', true).first();
15303 if(this.removable && !this.multiple){
15304 var close = this.closeTriggerEl();
15306 close.setVisibilityMode(Roo.Element.DISPLAY).hide();
15307 close.on('click', this.removeBtnClick, this, close);
15311 * fix the bug in Safari iOS8
15313 this.inputEl().on("focus", function(e){
15314 document.activeElement.blur();
15317 this._touchViewMask = Roo.DomHelper.append(document.body, {tag: "div", cls:"x-dlg-mask"}, true);
15324 renderTouchView : function()
15326 this.touchViewEl = Roo.get(document.body).createChild(Roo.bootstrap.ComboBox.touchViewTemplate);
15327 this.touchViewEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
15329 this.touchViewHeaderEl = this.touchViewEl.select('.modal-header', true).first();
15330 this.touchViewHeaderEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
15332 this.touchViewBodyEl = this.touchViewEl.select('.modal-body', true).first();
15333 this.touchViewBodyEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
15334 this.touchViewBodyEl.setStyle('overflow', 'auto');
15336 this.touchViewListGroup = this.touchViewBodyEl.select('.list-group', true).first();
15337 this.touchViewListGroup.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
15339 this.touchViewFooterEl = this.touchViewEl.select('.modal-footer', true).first();
15340 this.touchViewFooterEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
15344 showTouchView : function()
15350 this.touchViewHeaderEl.hide();
15352 if(this.modalTitle.length){
15353 this.touchViewHeaderEl.dom.innerHTML = this.modalTitle;
15354 this.touchViewHeaderEl.show();
15357 this.touchViewEl.setStyle('z-index', Roo.bootstrap.Modal.zIndex++);
15358 this.touchViewEl.show();
15360 this.touchViewEl.select('.modal-dialog', true).first().setStyle({ margin : '0px', width : '100%'});
15362 //this.touchViewEl.select('.modal-dialog > .modal-content', true).first().setSize(
15363 // Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
15365 var bodyHeight = Roo.lib.Dom.getViewHeight() - this.touchViewFooterEl.getHeight() + this.touchViewBodyEl.getPadding('tb');
15367 if(this.modalTitle.length){
15368 bodyHeight = bodyHeight - this.touchViewHeaderEl.getHeight();
15371 this.touchViewBodyEl.setHeight(bodyHeight);
15375 (function(){ _this.touchViewEl.addClass('in'); }).defer(50);
15377 this.touchViewEl.addClass('in');
15380 if(this._touchViewMask){
15381 Roo.get(document.body).addClass("x-body-masked");
15382 this._touchViewMask.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
15383 this._touchViewMask.setStyle('z-index', 10000);
15384 this._touchViewMask.addClass('show');
15387 this.doTouchViewQuery();
15391 hideTouchView : function()
15393 this.touchViewEl.removeClass('in');
15397 (function(){ _this.touchViewEl.setStyle('display', 'none'); }).defer(150);
15399 this.touchViewEl.setStyle('display', 'none');
15402 if(this._touchViewMask){
15403 this._touchViewMask.removeClass('show');
15404 Roo.get(document.body).removeClass("x-body-masked");
15408 setTouchViewValue : function()
15415 Roo.each(this.tickItems, function(o){
15420 this.hideTouchView();
15423 doTouchViewQuery : function()
15432 if(this.fireEvent('beforequery', qe) ===false || qe.cancel){
15436 if(!this.alwaysQuery || this.mode == 'local'){
15437 this.onTouchViewLoad();
15444 onTouchViewBeforeLoad : function(combo,opts)
15450 onTouchViewLoad : function()
15452 if(this.store.getCount() < 1){
15453 this.onTouchViewEmptyResults();
15457 this.clearTouchView();
15459 var rawValue = this.getRawValue();
15461 var template = (this.multiple) ? Roo.bootstrap.ComboBox.listItemCheckbox : Roo.bootstrap.ComboBox.listItemRadio;
15463 this.tickItems = [];
15465 this.store.data.each(function(d, rowIndex){
15466 var row = this.touchViewListGroup.createChild(template);
15468 if(typeof(d.data.cls) != 'undefined' && d.data.cls.length){
15469 row.addClass(d.data.cls);
15472 if(this.displayField && typeof(d.data[this.displayField]) != 'undefined'){
15475 html : d.data[this.displayField]
15478 if(this.fireEvent('touchviewdisplay', this, cfg) !== false){
15479 row.select('.roo-combobox-list-group-item-value', true).first().dom.innerHTML = cfg.html;
15482 row.removeClass('selected');
15483 if(!this.multiple && this.valueField &&
15484 typeof(d.data[this.valueField]) != 'undefined' && d.data[this.valueField] == this.getValue())
15487 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
15488 row.addClass('selected');
15491 if(this.multiple && this.valueField &&
15492 typeof(d.data[this.valueField]) != 'undefined' && this.getValue().indexOf(d.data[this.valueField]) != -1)
15496 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
15497 this.tickItems.push(d.data);
15500 row.on('click', this.onTouchViewClick, this, {row : row, rowIndex : rowIndex});
15504 var firstChecked = this.touchViewListGroup.select('.list-group-item > .roo-combobox-list-group-item-box > input:checked', true).first();
15506 var bodyHeight = Roo.lib.Dom.getViewHeight() - this.touchViewFooterEl.getHeight() + this.touchViewBodyEl.getPadding('tb');
15508 if(this.modalTitle.length){
15509 bodyHeight = bodyHeight - this.touchViewHeaderEl.getHeight();
15512 var listHeight = this.touchViewListGroup.getHeight() + this.touchViewBodyEl.getPadding('tb') * 2;
15514 if(this.mobile_restrict_height && listHeight < bodyHeight){
15515 this.touchViewBodyEl.setHeight(listHeight);
15520 if(firstChecked && listHeight > bodyHeight){
15521 (function() { firstChecked.findParent('li').scrollIntoView(_this.touchViewListGroup.dom); }).defer(500);
15526 onTouchViewLoadException : function()
15528 this.hideTouchView();
15531 onTouchViewEmptyResults : function()
15533 this.clearTouchView();
15535 this.touchViewListGroup.createChild(Roo.bootstrap.ComboBox.emptyResult);
15537 this.touchViewListGroup.select('.roo-combobox-touch-view-empty-result', true).first().dom.innerHTML = this.emptyResultText;
15541 clearTouchView : function()
15543 this.touchViewListGroup.dom.innerHTML = '';
15546 onTouchViewClick : function(e, el, o)
15548 e.preventDefault();
15551 var rowIndex = o.rowIndex;
15553 var r = this.store.getAt(rowIndex);
15555 if(this.fireEvent('beforeselect', this, r, rowIndex) !== false){
15557 if(!this.multiple){
15558 Roo.each(this.touchViewListGroup.select('.list-group-item > .roo-combobox-list-group-item-box > input:checked', true).elements, function(c){
15559 c.dom.removeAttribute('checked');
15562 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
15564 this.setFromData(r.data);
15566 var close = this.closeTriggerEl();
15572 this.hideTouchView();
15574 this.fireEvent('select', this, r, rowIndex);
15579 if(this.valueField && typeof(r.data[this.valueField]) != 'undefined' && this.getValue().indexOf(r.data[this.valueField]) != -1){
15580 row.select('.roo-combobox-list-group-item-box > input', true).first().dom.removeAttribute('checked');
15581 this.tickItems.splice(this.tickItems.indexOf(r.data), 1);
15585 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
15586 this.addItem(r.data);
15587 this.tickItems.push(r.data);
15591 getAutoCreateNativeIOS : function()
15594 cls: 'form-group' //input-group,
15599 cls : 'roo-ios-select'
15603 combobox.name = this.name;
15606 if (this.disabled) {
15607 combobox.disabled = true;
15610 var settings = this;
15612 ['xs','sm','md','lg'].map(function(size){
15613 if (settings[size]) {
15614 cfg.cls += ' col-' + size + '-' + settings[size];
15624 initIOSView : function()
15626 this.store.on('load', this.onIOSViewLoad, this);
15631 onIOSViewLoad : function()
15633 if(this.store.getCount() < 1){
15637 this.clearIOSView();
15639 if(this.allowBlank) {
15641 var default_text = '-- SELECT --';
15643 if(this.placeholder.length){
15644 default_text = this.placeholder;
15647 if(this.emptyTitle.length){
15648 default_text += ' - ' + this.emptyTitle + ' -';
15651 var opt = this.inputEl().createChild({
15654 html : default_text
15658 o[this.valueField] = 0;
15659 o[this.displayField] = default_text;
15661 this.ios_options.push({
15668 this.store.data.each(function(d, rowIndex){
15672 if(this.displayField && typeof(d.data[this.displayField]) != 'undefined'){
15673 html = d.data[this.displayField];
15678 if(this.valueField && typeof(d.data[this.valueField]) != 'undefined'){
15679 value = d.data[this.valueField];
15688 if(this.value == d.data[this.valueField]){
15689 option['selected'] = true;
15692 var opt = this.inputEl().createChild(option);
15694 this.ios_options.push({
15701 this.inputEl().on('change', function(){
15702 this.fireEvent('select', this);
15707 clearIOSView: function()
15709 this.inputEl().dom.innerHTML = '';
15711 this.ios_options = [];
15714 setIOSValue: function(v)
15718 if(!this.ios_options){
15722 Roo.each(this.ios_options, function(opts){
15724 opts.el.dom.removeAttribute('selected');
15726 if(opts.data[this.valueField] != v){
15730 opts.el.dom.setAttribute('selected', true);
15736 * @cfg {Boolean} grow
15740 * @cfg {Number} growMin
15744 * @cfg {Number} growMax
15753 Roo.apply(Roo.bootstrap.ComboBox, {
15757 cls: 'modal-header',
15779 cls: 'list-group-item',
15783 cls: 'roo-combobox-list-group-item-value'
15787 cls: 'roo-combobox-list-group-item-box pull-xs-right radio-inline radio radio-info',
15801 listItemCheckbox : {
15803 cls: 'list-group-item',
15807 cls: 'roo-combobox-list-group-item-value'
15811 cls: 'roo-combobox-list-group-item-box pull-xs-right checkbox-inline checkbox checkbox-info',
15827 cls: 'alert alert-danger roo-combobox-touch-view-empty-result'
15832 cls: 'modal-footer',
15840 cls: 'col-xs-6 text-left',
15843 cls: 'btn btn-danger roo-touch-view-cancel',
15849 cls: 'col-xs-6 text-right',
15852 cls: 'btn btn-success roo-touch-view-ok',
15863 Roo.apply(Roo.bootstrap.ComboBox, {
15865 touchViewTemplate : {
15867 cls: 'modal fade roo-combobox-touch-view',
15871 cls: 'modal-dialog',
15872 style : 'position:fixed', // we have to fix position....
15876 cls: 'modal-content',
15878 Roo.bootstrap.ComboBox.header,
15879 Roo.bootstrap.ComboBox.body,
15880 Roo.bootstrap.ComboBox.footer
15889 * Ext JS Library 1.1.1
15890 * Copyright(c) 2006-2007, Ext JS, LLC.
15892 * Originally Released Under LGPL - original licence link has changed is not relivant.
15895 * <script type="text/javascript">
15900 * @extends Roo.util.Observable
15901 * Create a "View" for an element based on a data model or UpdateManager and the supplied DomHelper template.
15902 * This class also supports single and multi selection modes. <br>
15903 * Create a data model bound view:
15905 var store = new Roo.data.Store(...);
15907 var view = new Roo.View({
15909 tpl : '<div id="{0}">{2} - {1}</div>', // auto create template
15911 singleSelect: true,
15912 selectedClass: "ydataview-selected",
15916 // listen for node click?
15917 view.on("click", function(vw, index, node, e){
15918 alert('Node "' + node.id + '" at index: ' + index + " was clicked.");
15922 dataModel.load("foobar.xml");
15924 For an example of creating a JSON/UpdateManager view, see {@link Roo.JsonView}.
15926 * <b>Note: The root of your template must be a single node. Table/row implementations may work but are not supported due to
15927 * IE"s limited insertion support with tables and Opera"s faulty event bubbling.</b>
15929 * Note: old style constructor is still suported (container, template, config)
15932 * Create a new View
15933 * @param {Object} config The config object
15936 Roo.View = function(config, depreciated_tpl, depreciated_config){
15938 this.parent = false;
15940 if (typeof(depreciated_tpl) == 'undefined') {
15941 // new way.. - universal constructor.
15942 Roo.apply(this, config);
15943 this.el = Roo.get(this.el);
15946 this.el = Roo.get(config);
15947 this.tpl = depreciated_tpl;
15948 Roo.apply(this, depreciated_config);
15950 this.wrapEl = this.el.wrap().wrap();
15951 ///this.el = this.wrapEla.appendChild(document.createElement("div"));
15954 if(typeof(this.tpl) == "string"){
15955 this.tpl = new Roo.Template(this.tpl);
15957 // support xtype ctors..
15958 this.tpl = new Roo.factory(this.tpl, Roo);
15962 this.tpl.compile();
15967 * @event beforeclick
15968 * Fires before a click is processed. Returns false to cancel the default action.
15969 * @param {Roo.View} this
15970 * @param {Number} index The index of the target node
15971 * @param {HTMLElement} node The target node
15972 * @param {Roo.EventObject} e The raw event object
15974 "beforeclick" : true,
15977 * Fires when a template node is clicked.
15978 * @param {Roo.View} this
15979 * @param {Number} index The index of the target node
15980 * @param {HTMLElement} node The target node
15981 * @param {Roo.EventObject} e The raw event object
15986 * Fires when a template node is double clicked.
15987 * @param {Roo.View} this
15988 * @param {Number} index The index of the target node
15989 * @param {HTMLElement} node The target node
15990 * @param {Roo.EventObject} e The raw event object
15994 * @event contextmenu
15995 * Fires when a template node is right clicked.
15996 * @param {Roo.View} this
15997 * @param {Number} index The index of the target node
15998 * @param {HTMLElement} node The target node
15999 * @param {Roo.EventObject} e The raw event object
16001 "contextmenu" : true,
16003 * @event selectionchange
16004 * Fires when the selected nodes change.
16005 * @param {Roo.View} this
16006 * @param {Array} selections Array of the selected nodes
16008 "selectionchange" : true,
16011 * @event beforeselect
16012 * Fires before a selection is made. If any handlers return false, the selection is cancelled.
16013 * @param {Roo.View} this
16014 * @param {HTMLElement} node The node to be selected
16015 * @param {Array} selections Array of currently selected nodes
16017 "beforeselect" : true,
16019 * @event preparedata
16020 * Fires on every row to render, to allow you to change the data.
16021 * @param {Roo.View} this
16022 * @param {Object} data to be rendered (change this)
16024 "preparedata" : true
16032 "click": this.onClick,
16033 "dblclick": this.onDblClick,
16034 "contextmenu": this.onContextMenu,
16038 this.selections = [];
16040 this.cmp = new Roo.CompositeElementLite([]);
16042 this.store = Roo.factory(this.store, Roo.data);
16043 this.setStore(this.store, true);
16046 if ( this.footer && this.footer.xtype) {
16048 var fctr = this.wrapEl.appendChild(document.createElement("div"));
16050 this.footer.dataSource = this.store;
16051 this.footer.container = fctr;
16052 this.footer = Roo.factory(this.footer, Roo);
16053 fctr.insertFirst(this.el);
16055 // this is a bit insane - as the paging toolbar seems to detach the el..
16056 // dom.parentNode.parentNode.parentNode
16057 // they get detached?
16061 Roo.View.superclass.constructor.call(this);
16066 Roo.extend(Roo.View, Roo.util.Observable, {
16069 * @cfg {Roo.data.Store} store Data store to load data from.
16074 * @cfg {String|Roo.Element} el The container element.
16079 * @cfg {String|Roo.Template} tpl The template used by this View
16083 * @cfg {String} dataName the named area of the template to use as the data area
16084 * Works with domtemplates roo-name="name"
16088 * @cfg {String} selectedClass The css class to add to selected nodes
16090 selectedClass : "x-view-selected",
16092 * @cfg {String} emptyText The empty text to show when nothing is loaded.
16097 * @cfg {String} text to display on mask (default Loading)
16101 * @cfg {Boolean} multiSelect Allow multiple selection
16103 multiSelect : false,
16105 * @cfg {Boolean} singleSelect Allow single selection
16107 singleSelect: false,
16110 * @cfg {Boolean} toggleSelect - selecting
16112 toggleSelect : false,
16115 * @cfg {Boolean} tickable - selecting
16120 * Returns the element this view is bound to.
16121 * @return {Roo.Element}
16123 getEl : function(){
16124 return this.wrapEl;
16130 * Refreshes the view. - called by datachanged on the store. - do not call directly.
16132 refresh : function(){
16133 //Roo.log('refresh');
16136 // if we are using something like 'domtemplate', then
16137 // the what gets used is:
16138 // t.applySubtemplate(NAME, data, wrapping data..)
16139 // the outer template then get' applied with
16140 // the store 'extra data'
16141 // and the body get's added to the
16142 // roo-name="data" node?
16143 // <span class='roo-tpl-{name}'></span> ?????
16147 this.clearSelections();
16148 this.el.update("");
16150 var records = this.store.getRange();
16151 if(records.length < 1) {
16153 // is this valid?? = should it render a template??
16155 this.el.update(this.emptyText);
16159 if (this.dataName) {
16160 this.el.update(t.apply(this.store.meta)); //????
16161 el = this.el.child('.roo-tpl-' + this.dataName);
16164 for(var i = 0, len = records.length; i < len; i++){
16165 var data = this.prepareData(records[i].data, i, records[i]);
16166 this.fireEvent("preparedata", this, data, i, records[i]);
16168 var d = Roo.apply({}, data);
16171 Roo.apply(d, {'roo-id' : Roo.id()});
16175 Roo.each(this.parent.item, function(item){
16176 if(item[_this.parent.valueField] != data[_this.parent.valueField]){
16179 Roo.apply(d, {'roo-data-checked' : 'checked'});
16183 html[html.length] = Roo.util.Format.trim(
16185 t.applySubtemplate(this.dataName, d, this.store.meta) :
16192 el.update(html.join(""));
16193 this.nodes = el.dom.childNodes;
16194 this.updateIndexes(0);
16199 * Function to override to reformat the data that is sent to
16200 * the template for each node.
16201 * DEPRICATED - use the preparedata event handler.
16202 * @param {Array/Object} data The raw data (array of colData for a data model bound view or
16203 * a JSON object for an UpdateManager bound view).
16205 prepareData : function(data, index, record)
16207 this.fireEvent("preparedata", this, data, index, record);
16211 onUpdate : function(ds, record){
16212 // Roo.log('on update');
16213 this.clearSelections();
16214 var index = this.store.indexOf(record);
16215 var n = this.nodes[index];
16216 this.tpl.insertBefore(n, this.prepareData(record.data, index, record));
16217 n.parentNode.removeChild(n);
16218 this.updateIndexes(index, index);
16224 onAdd : function(ds, records, index)
16226 //Roo.log(['on Add', ds, records, index] );
16227 this.clearSelections();
16228 if(this.nodes.length == 0){
16232 var n = this.nodes[index];
16233 for(var i = 0, len = records.length; i < len; i++){
16234 var d = this.prepareData(records[i].data, i, records[i]);
16236 this.tpl.insertBefore(n, d);
16239 this.tpl.append(this.el, d);
16242 this.updateIndexes(index);
16245 onRemove : function(ds, record, index){
16246 // Roo.log('onRemove');
16247 this.clearSelections();
16248 var el = this.dataName ?
16249 this.el.child('.roo-tpl-' + this.dataName) :
16252 el.dom.removeChild(this.nodes[index]);
16253 this.updateIndexes(index);
16257 * Refresh an individual node.
16258 * @param {Number} index
16260 refreshNode : function(index){
16261 this.onUpdate(this.store, this.store.getAt(index));
16264 updateIndexes : function(startIndex, endIndex){
16265 var ns = this.nodes;
16266 startIndex = startIndex || 0;
16267 endIndex = endIndex || ns.length - 1;
16268 for(var i = startIndex; i <= endIndex; i++){
16269 ns[i].nodeIndex = i;
16274 * Changes the data store this view uses and refresh the view.
16275 * @param {Store} store
16277 setStore : function(store, initial){
16278 if(!initial && this.store){
16279 this.store.un("datachanged", this.refresh);
16280 this.store.un("add", this.onAdd);
16281 this.store.un("remove", this.onRemove);
16282 this.store.un("update", this.onUpdate);
16283 this.store.un("clear", this.refresh);
16284 this.store.un("beforeload", this.onBeforeLoad);
16285 this.store.un("load", this.onLoad);
16286 this.store.un("loadexception", this.onLoad);
16290 store.on("datachanged", this.refresh, this);
16291 store.on("add", this.onAdd, this);
16292 store.on("remove", this.onRemove, this);
16293 store.on("update", this.onUpdate, this);
16294 store.on("clear", this.refresh, this);
16295 store.on("beforeload", this.onBeforeLoad, this);
16296 store.on("load", this.onLoad, this);
16297 store.on("loadexception", this.onLoad, this);
16305 * onbeforeLoad - masks the loading area.
16308 onBeforeLoad : function(store,opts)
16310 //Roo.log('onBeforeLoad');
16312 this.el.update("");
16314 this.el.mask(this.mask ? this.mask : "Loading" );
16316 onLoad : function ()
16323 * Returns the template node the passed child belongs to or null if it doesn't belong to one.
16324 * @param {HTMLElement} node
16325 * @return {HTMLElement} The template node
16327 findItemFromChild : function(node){
16328 var el = this.dataName ?
16329 this.el.child('.roo-tpl-' + this.dataName,true) :
16332 if(!node || node.parentNode == el){
16335 var p = node.parentNode;
16336 while(p && p != el){
16337 if(p.parentNode == el){
16346 onClick : function(e){
16347 var item = this.findItemFromChild(e.getTarget());
16349 var index = this.indexOf(item);
16350 if(this.onItemClick(item, index, e) !== false){
16351 this.fireEvent("click", this, index, item, e);
16354 this.clearSelections();
16359 onContextMenu : function(e){
16360 var item = this.findItemFromChild(e.getTarget());
16362 this.fireEvent("contextmenu", this, this.indexOf(item), item, e);
16367 onDblClick : function(e){
16368 var item = this.findItemFromChild(e.getTarget());
16370 this.fireEvent("dblclick", this, this.indexOf(item), item, e);
16374 onItemClick : function(item, index, e)
16376 if(this.fireEvent("beforeclick", this, index, item, e) === false){
16379 if (this.toggleSelect) {
16380 var m = this.isSelected(item) ? 'unselect' : 'select';
16383 _t[m](item, true, false);
16386 if(this.multiSelect || this.singleSelect){
16387 if(this.multiSelect && e.shiftKey && this.lastSelection){
16388 this.select(this.getNodes(this.indexOf(this.lastSelection), index), false);
16390 this.select(item, this.multiSelect && e.ctrlKey);
16391 this.lastSelection = item;
16394 if(!this.tickable){
16395 e.preventDefault();
16403 * Get the number of selected nodes.
16406 getSelectionCount : function(){
16407 return this.selections.length;
16411 * Get the currently selected nodes.
16412 * @return {Array} An array of HTMLElements
16414 getSelectedNodes : function(){
16415 return this.selections;
16419 * Get the indexes of the selected nodes.
16422 getSelectedIndexes : function(){
16423 var indexes = [], s = this.selections;
16424 for(var i = 0, len = s.length; i < len; i++){
16425 indexes.push(s[i].nodeIndex);
16431 * Clear all selections
16432 * @param {Boolean} suppressEvent (optional) true to skip firing of the selectionchange event
16434 clearSelections : function(suppressEvent){
16435 if(this.nodes && (this.multiSelect || this.singleSelect) && this.selections.length > 0){
16436 this.cmp.elements = this.selections;
16437 this.cmp.removeClass(this.selectedClass);
16438 this.selections = [];
16439 if(!suppressEvent){
16440 this.fireEvent("selectionchange", this, this.selections);
16446 * Returns true if the passed node is selected
16447 * @param {HTMLElement/Number} node The node or node index
16448 * @return {Boolean}
16450 isSelected : function(node){
16451 var s = this.selections;
16455 node = this.getNode(node);
16456 return s.indexOf(node) !== -1;
16461 * @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
16462 * @param {Boolean} keepExisting (optional) true to keep existing selections
16463 * @param {Boolean} suppressEvent (optional) true to skip firing of the selectionchange vent
16465 select : function(nodeInfo, keepExisting, suppressEvent){
16466 if(nodeInfo instanceof Array){
16468 this.clearSelections(true);
16470 for(var i = 0, len = nodeInfo.length; i < len; i++){
16471 this.select(nodeInfo[i], true, true);
16475 var node = this.getNode(nodeInfo);
16476 if(!node || this.isSelected(node)){
16477 return; // already selected.
16480 this.clearSelections(true);
16483 if(this.fireEvent("beforeselect", this, node, this.selections) !== false){
16484 Roo.fly(node).addClass(this.selectedClass);
16485 this.selections.push(node);
16486 if(!suppressEvent){
16487 this.fireEvent("selectionchange", this, this.selections);
16495 * @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
16496 * @param {Boolean} keepExisting (optional) true IGNORED (for campatibility with select)
16497 * @param {Boolean} suppressEvent (optional) true to skip firing of the selectionchange vent
16499 unselect : function(nodeInfo, keepExisting, suppressEvent)
16501 if(nodeInfo instanceof Array){
16502 Roo.each(this.selections, function(s) {
16503 this.unselect(s, nodeInfo);
16507 var node = this.getNode(nodeInfo);
16508 if(!node || !this.isSelected(node)){
16509 //Roo.log("not selected");
16510 return; // not selected.
16514 Roo.each(this.selections, function(s) {
16516 Roo.fly(node).removeClass(this.selectedClass);
16523 this.selections= ns;
16524 this.fireEvent("selectionchange", this, this.selections);
16528 * Gets a template node.
16529 * @param {HTMLElement/String/Number} nodeInfo An HTMLElement template node, index of a template node or the id of a template node
16530 * @return {HTMLElement} The node or null if it wasn't found
16532 getNode : function(nodeInfo){
16533 if(typeof nodeInfo == "string"){
16534 return document.getElementById(nodeInfo);
16535 }else if(typeof nodeInfo == "number"){
16536 return this.nodes[nodeInfo];
16542 * Gets a range template nodes.
16543 * @param {Number} startIndex
16544 * @param {Number} endIndex
16545 * @return {Array} An array of nodes
16547 getNodes : function(start, end){
16548 var ns = this.nodes;
16549 start = start || 0;
16550 end = typeof end == "undefined" ? ns.length - 1 : end;
16553 for(var i = start; i <= end; i++){
16557 for(var i = start; i >= end; i--){
16565 * Finds the index of the passed node
16566 * @param {HTMLElement/String/Number} nodeInfo An HTMLElement template node, index of a template node or the id of a template node
16567 * @return {Number} The index of the node or -1
16569 indexOf : function(node){
16570 node = this.getNode(node);
16571 if(typeof node.nodeIndex == "number"){
16572 return node.nodeIndex;
16574 var ns = this.nodes;
16575 for(var i = 0, len = ns.length; i < len; i++){
16586 * based on jquery fullcalendar
16590 Roo.bootstrap = Roo.bootstrap || {};
16592 * @class Roo.bootstrap.Calendar
16593 * @extends Roo.bootstrap.Component
16594 * Bootstrap Calendar class
16595 * @cfg {Boolean} loadMask (true|false) default false
16596 * @cfg {Object} header generate the user specific header of the calendar, default false
16599 * Create a new Container
16600 * @param {Object} config The config object
16605 Roo.bootstrap.Calendar = function(config){
16606 Roo.bootstrap.Calendar.superclass.constructor.call(this, config);
16610 * Fires when a date is selected
16611 * @param {DatePicker} this
16612 * @param {Date} date The selected date
16616 * @event monthchange
16617 * Fires when the displayed month changes
16618 * @param {DatePicker} this
16619 * @param {Date} date The selected month
16621 'monthchange': true,
16623 * @event evententer
16624 * Fires when mouse over an event
16625 * @param {Calendar} this
16626 * @param {event} Event
16628 'evententer': true,
16630 * @event eventleave
16631 * Fires when the mouse leaves an
16632 * @param {Calendar} this
16635 'eventleave': true,
16637 * @event eventclick
16638 * Fires when the mouse click an
16639 * @param {Calendar} this
16648 Roo.extend(Roo.bootstrap.Calendar, Roo.bootstrap.Component, {
16651 * @cfg {Number} startDay
16652 * Day index at which the week should begin, 0-based (defaults to 0, which is Sunday)
16660 getAutoCreate : function(){
16663 var fc_button = function(name, corner, style, content ) {
16664 return Roo.apply({},{
16666 cls : 'fc-button fc-button-'+name+' fc-state-default ' +
16668 'fc-corner-' + corner.split(' ').join(' fc-corner-') :
16671 html : '<SPAN class="fc-text-'+style+ '">'+content +'</SPAN>',
16682 style : 'width:100%',
16689 cls : 'fc-header-left',
16691 fc_button('prev', 'left', 'arrow', '‹' ),
16692 fc_button('next', 'right', 'arrow', '›' ),
16693 { tag: 'span', cls: 'fc-header-space' },
16694 fc_button('today', 'left right', '', 'today' ) // neds state disabled..
16702 cls : 'fc-header-center',
16706 cls: 'fc-header-title',
16709 html : 'month / year'
16717 cls : 'fc-header-right',
16719 /* fc_button('month', 'left', '', 'month' ),
16720 fc_button('week', '', '', 'week' ),
16721 fc_button('day', 'right', '', 'day' )
16733 header = this.header;
16736 var cal_heads = function() {
16738 // fixme - handle this.
16740 for (var i =0; i < Date.dayNames.length; i++) {
16741 var d = Date.dayNames[i];
16744 cls : 'fc-day-header fc-' + d.substring(0,3).toLowerCase() + ' fc-widget-header',
16745 html : d.substring(0,3)
16749 ret[0].cls += ' fc-first';
16750 ret[6].cls += ' fc-last';
16753 var cal_cell = function(n) {
16756 cls : 'fc-day fc-'+n + ' fc-widget-content', ///fc-other-month fc-past
16761 cls: 'fc-day-number',
16765 cls: 'fc-day-content',
16769 style: 'position: relative;' // height: 17px;
16781 var cal_rows = function() {
16784 for (var r = 0; r < 6; r++) {
16791 for (var i =0; i < Date.dayNames.length; i++) {
16792 var d = Date.dayNames[i];
16793 row.cn.push(cal_cell(d.substring(0,3).toLowerCase()));
16796 row.cn[0].cls+=' fc-first';
16797 row.cn[0].cn[0].style = 'min-height:90px';
16798 row.cn[6].cls+=' fc-last';
16802 ret[0].cls += ' fc-first';
16803 ret[4].cls += ' fc-prev-last';
16804 ret[5].cls += ' fc-last';
16811 cls: 'fc-border-separate',
16812 style : 'width:100%',
16820 cls : 'fc-first fc-last',
16838 cls : 'fc-content',
16839 style : "position: relative;",
16842 cls : 'fc-view fc-view-month fc-grid',
16843 style : 'position: relative',
16844 unselectable : 'on',
16847 cls : 'fc-event-container',
16848 style : 'position:absolute;z-index:8;top:0;left:0;'
16866 initEvents : function()
16869 throw "can not find store for calendar";
16875 style: "text-align:center",
16879 style: "background-color:white;width:50%;margin:250 auto",
16883 src: Roo.rootURL + '/images/ux/lightbox/loading.gif'
16894 this.maskEl = Roo.DomHelper.append(this.el.select('.fc-content', true).first(), mark, true);
16896 var size = this.el.select('.fc-content', true).first().getSize();
16897 this.maskEl.setSize(size.width, size.height);
16898 this.maskEl.enableDisplayMode("block");
16899 if(!this.loadMask){
16900 this.maskEl.hide();
16903 this.store = Roo.factory(this.store, Roo.data);
16904 this.store.on('load', this.onLoad, this);
16905 this.store.on('beforeload', this.onBeforeLoad, this);
16909 this.cells = this.el.select('.fc-day',true);
16910 //Roo.log(this.cells);
16911 this.textNodes = this.el.query('.fc-day-number');
16912 this.cells.addClassOnOver('fc-state-hover');
16914 this.el.select('.fc-button-prev',true).on('click', this.showPrevMonth, this);
16915 this.el.select('.fc-button-next',true).on('click', this.showNextMonth, this);
16916 this.el.select('.fc-button-today',true).on('click', this.showToday, this);
16917 this.el.select('.fc-button',true).addClassOnOver('fc-state-hover');
16919 this.on('monthchange', this.onMonthChange, this);
16921 this.update(new Date().clearTime());
16924 resize : function() {
16925 var sz = this.el.getSize();
16927 this.el.select('.fc-day-header',true).setWidth(sz.width / 7);
16928 this.el.select('.fc-day-content div',true).setHeight(34);
16933 showPrevMonth : function(e){
16934 this.update(this.activeDate.add("mo", -1));
16936 showToday : function(e){
16937 this.update(new Date().clearTime());
16940 showNextMonth : function(e){
16941 this.update(this.activeDate.add("mo", 1));
16945 showPrevYear : function(){
16946 this.update(this.activeDate.add("y", -1));
16950 showNextYear : function(){
16951 this.update(this.activeDate.add("y", 1));
16956 update : function(date)
16958 var vd = this.activeDate;
16959 this.activeDate = date;
16960 // if(vd && this.el){
16961 // var t = date.getTime();
16962 // if(vd.getMonth() == date.getMonth() && vd.getFullYear() == date.getFullYear()){
16963 // Roo.log('using add remove');
16965 // this.fireEvent('monthchange', this, date);
16967 // this.cells.removeClass("fc-state-highlight");
16968 // this.cells.each(function(c){
16969 // if(c.dateValue == t){
16970 // c.addClass("fc-state-highlight");
16971 // setTimeout(function(){
16972 // try{c.dom.firstChild.focus();}catch(e){}
16982 var days = date.getDaysInMonth();
16984 var firstOfMonth = date.getFirstDateOfMonth();
16985 var startingPos = firstOfMonth.getDay()-this.startDay;
16987 if(startingPos < this.startDay){
16991 var pm = date.add(Date.MONTH, -1);
16992 var prevStart = pm.getDaysInMonth()-startingPos;
16994 this.cells = this.el.select('.fc-day',true);
16995 this.textNodes = this.el.query('.fc-day-number');
16996 this.cells.addClassOnOver('fc-state-hover');
16998 var cells = this.cells.elements;
16999 var textEls = this.textNodes;
17001 Roo.each(cells, function(cell){
17002 cell.removeClass([ 'fc-past', 'fc-other-month', 'fc-future', 'fc-state-highlight', 'fc-state-disabled']);
17005 days += startingPos;
17007 // convert everything to numbers so it's fast
17008 var day = 86400000;
17009 var d = (new Date(pm.getFullYear(), pm.getMonth(), prevStart)).clearTime();
17012 //Roo.log(prevStart);
17014 var today = new Date().clearTime().getTime();
17015 var sel = date.clearTime().getTime();
17016 var min = this.minDate ? this.minDate.clearTime() : Number.NEGATIVE_INFINITY;
17017 var max = this.maxDate ? this.maxDate.clearTime() : Number.POSITIVE_INFINITY;
17018 var ddMatch = this.disabledDatesRE;
17019 var ddText = this.disabledDatesText;
17020 var ddays = this.disabledDays ? this.disabledDays.join("") : false;
17021 var ddaysText = this.disabledDaysText;
17022 var format = this.format;
17024 var setCellClass = function(cal, cell){
17028 //Roo.log('set Cell Class');
17030 var t = d.getTime();
17034 cell.dateValue = t;
17036 cell.className += " fc-today";
17037 cell.className += " fc-state-highlight";
17038 cell.title = cal.todayText;
17041 // disable highlight in other month..
17042 //cell.className += " fc-state-highlight";
17047 cell.className = " fc-state-disabled";
17048 cell.title = cal.minText;
17052 cell.className = " fc-state-disabled";
17053 cell.title = cal.maxText;
17057 if(ddays.indexOf(d.getDay()) != -1){
17058 cell.title = ddaysText;
17059 cell.className = " fc-state-disabled";
17062 if(ddMatch && format){
17063 var fvalue = d.dateFormat(format);
17064 if(ddMatch.test(fvalue)){
17065 cell.title = ddText.replace("%0", fvalue);
17066 cell.className = " fc-state-disabled";
17070 if (!cell.initialClassName) {
17071 cell.initialClassName = cell.dom.className;
17074 cell.dom.className = cell.initialClassName + ' ' + cell.className;
17079 for(; i < startingPos; i++) {
17080 textEls[i].innerHTML = (++prevStart);
17081 d.setDate(d.getDate()+1);
17083 cells[i].className = "fc-past fc-other-month";
17084 setCellClass(this, cells[i]);
17089 for(; i < days; i++){
17090 intDay = i - startingPos + 1;
17091 textEls[i].innerHTML = (intDay);
17092 d.setDate(d.getDate()+1);
17094 cells[i].className = ''; // "x-date-active";
17095 setCellClass(this, cells[i]);
17099 for(; i < 42; i++) {
17100 textEls[i].innerHTML = (++extraDays);
17101 d.setDate(d.getDate()+1);
17103 cells[i].className = "fc-future fc-other-month";
17104 setCellClass(this, cells[i]);
17107 this.el.select('.fc-header-title h2',true).update(Date.monthNames[date.getMonth()] + " " + date.getFullYear());
17109 var totalRows = Math.ceil((date.getDaysInMonth() + date.getFirstDateOfMonth().getDay()) / 7);
17111 this.el.select('tr.fc-week.fc-prev-last',true).removeClass('fc-last');
17112 this.el.select('tr.fc-week.fc-next-last',true).addClass('fc-last').show();
17114 if(totalRows != 6){
17115 this.el.select('tr.fc-week.fc-last',true).removeClass('fc-last').addClass('fc-next-last').hide();
17116 this.el.select('tr.fc-week.fc-prev-last',true).addClass('fc-last');
17119 this.fireEvent('monthchange', this, date);
17123 if(!this.internalRender){
17124 var main = this.el.dom.firstChild;
17125 var w = main.offsetWidth;
17126 this.el.setWidth(w + this.el.getBorderWidth("lr"));
17127 Roo.fly(main).setWidth(w);
17128 this.internalRender = true;
17129 // opera does not respect the auto grow header center column
17130 // then, after it gets a width opera refuses to recalculate
17131 // without a second pass
17132 if(Roo.isOpera && !this.secondPass){
17133 main.rows[0].cells[1].style.width = (w - (main.rows[0].cells[0].offsetWidth+main.rows[0].cells[2].offsetWidth)) + "px";
17134 this.secondPass = true;
17135 this.update.defer(10, this, [date]);
17142 findCell : function(dt) {
17143 dt = dt.clearTime().getTime();
17145 this.cells.each(function(c){
17146 //Roo.log("check " +c.dateValue + '?=' + dt);
17147 if(c.dateValue == dt){
17157 findCells : function(ev) {
17158 var s = ev.start.clone().clearTime().getTime();
17160 var e= ev.end.clone().clearTime().getTime();
17163 this.cells.each(function(c){
17164 ////Roo.log("check " +c.dateValue + '<' + e + ' > ' + s);
17166 if(c.dateValue > e){
17169 if(c.dateValue < s){
17178 // findBestRow: function(cells)
17182 // for (var i =0 ; i < cells.length;i++) {
17183 // ret = Math.max(cells[i].rows || 0,ret);
17190 addItem : function(ev)
17192 // look for vertical location slot in
17193 var cells = this.findCells(ev);
17195 // ev.row = this.findBestRow(cells);
17197 // work out the location.
17201 for(var i =0; i < cells.length; i++) {
17203 cells[i].row = cells[0].row;
17206 cells[i].row = cells[i].row + 1;
17216 if (crow.start.getY() == cells[i].getY()) {
17218 crow.end = cells[i];
17235 cells[0].events.push(ev);
17237 this.calevents.push(ev);
17240 clearEvents: function() {
17242 if(!this.calevents){
17246 Roo.each(this.cells.elements, function(c){
17252 Roo.each(this.calevents, function(e) {
17253 Roo.each(e.els, function(el) {
17254 el.un('mouseenter' ,this.onEventEnter, this);
17255 el.un('mouseleave' ,this.onEventLeave, this);
17260 Roo.each(Roo.select('.fc-more-event', true).elements, function(e){
17266 renderEvents: function()
17270 this.cells.each(function(c) {
17279 if(c.row != c.events.length){
17280 r = 4 - (4 - (c.row - c.events.length));
17283 c.events = ev.slice(0, r);
17284 c.more = ev.slice(r);
17286 if(c.more.length && c.more.length == 1){
17287 c.events.push(c.more.pop());
17290 c.row = (c.row - ev.length) + c.events.length + ((c.more.length) ? 1 : 0);
17294 this.cells.each(function(c) {
17296 c.select('.fc-day-content div',true).first().setHeight(Math.max(34, c.row * 20));
17299 for (var e = 0; e < c.events.length; e++){
17300 var ev = c.events[e];
17301 var rows = ev.rows;
17303 for(var i = 0; i < rows.length; i++) {
17305 // how many rows should it span..
17308 cls : 'roo-dynamic fc-event fc-event-hori fc-event-draggable ui-draggable',
17309 style : 'position: absolute', // left: 387px; width: 121px; top: 359px;
17311 unselectable : "on",
17314 cls: 'fc-event-inner',
17318 // cls: 'fc-event-time',
17319 // html : cells.length > 1 ? '' : ev.time
17323 cls: 'fc-event-title',
17324 html : String.format('{0}', ev.title)
17331 cls: 'ui-resizable-handle ui-resizable-e',
17332 html : '  '
17339 cfg.cls += ' fc-event-start';
17341 if ((i+1) == rows.length) {
17342 cfg.cls += ' fc-event-end';
17345 var ctr = _this.el.select('.fc-event-container',true).first();
17346 var cg = ctr.createChild(cfg);
17348 var sbox = rows[i].start.select('.fc-day-content',true).first().getBox();
17349 var ebox = rows[i].end.select('.fc-day-content',true).first().getBox();
17351 var r = (c.more.length) ? 1 : 0;
17352 cg.setXY([sbox.x +2, sbox.y + ((c.row - c.events.length - r + e) * 20)]);
17353 cg.setWidth(ebox.right - sbox.x -2);
17355 cg.on('mouseenter' ,_this.onEventEnter, _this, ev);
17356 cg.on('mouseleave' ,_this.onEventLeave, _this, ev);
17357 cg.on('click', _this.onEventClick, _this, ev);
17368 cls : 'fc-more-event roo-dynamic fc-event fc-event-hori fc-event-draggable ui-draggable fc-event-start fc-event-end',
17369 style : 'position: absolute',
17370 unselectable : "on",
17373 cls: 'fc-event-inner',
17377 cls: 'fc-event-title',
17385 cls: 'ui-resizable-handle ui-resizable-e',
17386 html : '  '
17392 var ctr = _this.el.select('.fc-event-container',true).first();
17393 var cg = ctr.createChild(cfg);
17395 var sbox = c.select('.fc-day-content',true).first().getBox();
17396 var ebox = c.select('.fc-day-content',true).first().getBox();
17398 cg.setXY([sbox.x +2, sbox.y +((c.row - 1) * 20)]);
17399 cg.setWidth(ebox.right - sbox.x -2);
17401 cg.on('click', _this.onMoreEventClick, _this, c.more);
17411 onEventEnter: function (e, el,event,d) {
17412 this.fireEvent('evententer', this, el, event);
17415 onEventLeave: function (e, el,event,d) {
17416 this.fireEvent('eventleave', this, el, event);
17419 onEventClick: function (e, el,event,d) {
17420 this.fireEvent('eventclick', this, el, event);
17423 onMonthChange: function () {
17427 onMoreEventClick: function(e, el, more)
17431 this.calpopover.placement = 'right';
17432 this.calpopover.setTitle('More');
17434 this.calpopover.setContent('');
17436 var ctr = this.calpopover.el.select('.popover-content', true).first();
17438 Roo.each(more, function(m){
17440 cls : 'fc-event-hori fc-event-draggable',
17443 var cg = ctr.createChild(cfg);
17445 cg.on('click', _this.onEventClick, _this, m);
17448 this.calpopover.show(el);
17453 onLoad: function ()
17455 this.calevents = [];
17458 if(this.store.getCount() > 0){
17459 this.store.data.each(function(d){
17462 start: (typeof(d.data.start_dt) === 'string') ? new Date.parseDate(d.data.start_dt, 'Y-m-d H:i:s') : d.data.start_dt,
17463 end : (typeof(d.data.end_dt) === 'string') ? new Date.parseDate(d.data.end_dt, 'Y-m-d H:i:s') : d.data.end_dt,
17464 time : d.data.start_time,
17465 title : d.data.title,
17466 description : d.data.description,
17467 venue : d.data.venue
17472 this.renderEvents();
17474 if(this.calevents.length && this.loadMask){
17475 this.maskEl.hide();
17479 onBeforeLoad: function()
17481 this.clearEvents();
17483 this.maskEl.show();
17497 * @class Roo.bootstrap.Popover
17498 * @extends Roo.bootstrap.Component
17499 * Bootstrap Popover class
17500 * @cfg {String} html contents of the popover (or false to use children..)
17501 * @cfg {String} title of popover (or false to hide)
17502 * @cfg {String} placement how it is placed
17503 * @cfg {String} trigger click || hover (or false to trigger manually)
17504 * @cfg {String} over what (parent or false to trigger manually.)
17505 * @cfg {Number} delay - delay before showing
17508 * Create a new Popover
17509 * @param {Object} config The config object
17512 Roo.bootstrap.Popover = function(config){
17513 Roo.bootstrap.Popover.superclass.constructor.call(this, config);
17519 * After the popover show
17521 * @param {Roo.bootstrap.Popover} this
17526 * After the popover hide
17528 * @param {Roo.bootstrap.Popover} this
17534 Roo.extend(Roo.bootstrap.Popover, Roo.bootstrap.Component, {
17536 title: 'Fill in a title',
17539 placement : 'right',
17540 trigger : 'hover', // hover
17546 can_build_overlaid : false,
17548 getChildContainer : function()
17550 return this.el.select('.popover-content',true).first();
17553 getAutoCreate : function(){
17556 cls : 'popover roo-dynamic',
17557 style: 'display:block',
17563 cls : 'popover-inner',
17567 cls: 'popover-title',
17571 cls : 'popover-content',
17582 setTitle: function(str)
17585 this.el.select('.popover-title',true).first().dom.innerHTML = str;
17587 setContent: function(str)
17590 this.el.select('.popover-content',true).first().dom.innerHTML = str;
17592 // as it get's added to the bottom of the page.
17593 onRender : function(ct, position)
17595 Roo.bootstrap.Component.superclass.onRender.call(this, ct, position);
17597 var cfg = Roo.apply({}, this.getAutoCreate());
17601 cfg.cls += ' ' + this.cls;
17604 cfg.style = this.style;
17606 //Roo.log("adding to ");
17607 this.el = Roo.get(document.body).createChild(cfg, position);
17608 // Roo.log(this.el);
17613 initEvents : function()
17615 this.el.select('.popover-title',true).setVisibilityMode(Roo.Element.DISPLAY);
17616 this.el.enableDisplayMode('block');
17618 if (this.over === false) {
17621 if (this.triggers === false) {
17624 var on_el = (this.over == 'parent') ? this.parent().el : Roo.get(this.over);
17625 var triggers = this.trigger ? this.trigger.split(' ') : [];
17626 Roo.each(triggers, function(trigger) {
17628 if (trigger == 'click') {
17629 on_el.on('click', this.toggle, this);
17630 } else if (trigger != 'manual') {
17631 var eventIn = trigger == 'hover' ? 'mouseenter' : 'focusin';
17632 var eventOut = trigger == 'hover' ? 'mouseleave' : 'focusout';
17634 on_el.on(eventIn ,this.enter, this);
17635 on_el.on(eventOut, this.leave, this);
17646 toggle : function () {
17647 this.hoverState == 'in' ? this.leave() : this.enter();
17650 enter : function () {
17652 clearTimeout(this.timeout);
17654 this.hoverState = 'in';
17656 if (!this.delay || !this.delay.show) {
17661 this.timeout = setTimeout(function () {
17662 if (_t.hoverState == 'in') {
17665 }, this.delay.show)
17668 leave : function() {
17669 clearTimeout(this.timeout);
17671 this.hoverState = 'out';
17673 if (!this.delay || !this.delay.hide) {
17678 this.timeout = setTimeout(function () {
17679 if (_t.hoverState == 'out') {
17682 }, this.delay.hide)
17685 show : function (on_el)
17688 on_el= (this.over == 'parent') ? this.parent().el : Roo.get(this.over);
17692 this.el.select('.popover-title',true).first().dom.innerHtml = this.title;
17693 if (this.html !== false) {
17694 this.el.select('.popover-content',true).first().dom.innerHtml = this.html;
17696 this.el.removeClass(['fade','top','bottom', 'left', 'right','in']);
17697 if (!this.title.length) {
17698 this.el.select('.popover-title',true).hide();
17701 var placement = typeof this.placement == 'function' ?
17702 this.placement.call(this, this.el, on_el) :
17705 var autoToken = /\s?auto?\s?/i;
17706 var autoPlace = autoToken.test(placement);
17708 placement = placement.replace(autoToken, '') || 'top';
17712 //this.el.setXY([0,0]);
17714 this.el.dom.style.display='block';
17715 this.el.addClass(placement);
17717 //this.el.appendTo(on_el);
17719 var p = this.getPosition();
17720 var box = this.el.getBox();
17725 var align = Roo.bootstrap.Popover.alignment[placement];
17728 this.el.alignTo(on_el, align[0],align[1]);
17729 //var arrow = this.el.select('.arrow',true).first();
17730 //arrow.set(align[2],
17732 this.el.addClass('in');
17735 if (this.el.hasClass('fade')) {
17739 this.hoverState = 'in';
17741 this.fireEvent('show', this);
17746 this.el.setXY([0,0]);
17747 this.el.removeClass('in');
17749 this.hoverState = null;
17751 this.fireEvent('hide', this);
17756 Roo.bootstrap.Popover.alignment = {
17757 'left' : ['r-l', [-10,0], 'right'],
17758 'right' : ['l-r', [10,0], 'left'],
17759 'bottom' : ['t-b', [0,10], 'top'],
17760 'top' : [ 'b-t', [0,-10], 'bottom']
17771 * @class Roo.bootstrap.Progress
17772 * @extends Roo.bootstrap.Component
17773 * Bootstrap Progress class
17774 * @cfg {Boolean} striped striped of the progress bar
17775 * @cfg {Boolean} active animated of the progress bar
17779 * Create a new Progress
17780 * @param {Object} config The config object
17783 Roo.bootstrap.Progress = function(config){
17784 Roo.bootstrap.Progress.superclass.constructor.call(this, config);
17787 Roo.extend(Roo.bootstrap.Progress, Roo.bootstrap.Component, {
17792 getAutoCreate : function(){
17800 cfg.cls += ' progress-striped';
17804 cfg.cls += ' active';
17823 * @class Roo.bootstrap.ProgressBar
17824 * @extends Roo.bootstrap.Component
17825 * Bootstrap ProgressBar class
17826 * @cfg {Number} aria_valuenow aria-value now
17827 * @cfg {Number} aria_valuemin aria-value min
17828 * @cfg {Number} aria_valuemax aria-value max
17829 * @cfg {String} label label for the progress bar
17830 * @cfg {String} panel (success | info | warning | danger )
17831 * @cfg {String} role role of the progress bar
17832 * @cfg {String} sr_only text
17836 * Create a new ProgressBar
17837 * @param {Object} config The config object
17840 Roo.bootstrap.ProgressBar = function(config){
17841 Roo.bootstrap.ProgressBar.superclass.constructor.call(this, config);
17844 Roo.extend(Roo.bootstrap.ProgressBar, Roo.bootstrap.Component, {
17848 aria_valuemax : 100,
17854 getAutoCreate : function()
17859 cls: 'progress-bar',
17860 style: 'width:' + Math.ceil((this.aria_valuenow / this.aria_valuemax) * 100) + '%'
17872 cfg.role = this.role;
17875 if(this.aria_valuenow){
17876 cfg['aria-valuenow'] = this.aria_valuenow;
17879 if(this.aria_valuemin){
17880 cfg['aria-valuemin'] = this.aria_valuemin;
17883 if(this.aria_valuemax){
17884 cfg['aria-valuemax'] = this.aria_valuemax;
17887 if(this.label && !this.sr_only){
17888 cfg.html = this.label;
17892 cfg.cls += ' progress-bar-' + this.panel;
17898 update : function(aria_valuenow)
17900 this.aria_valuenow = aria_valuenow;
17902 this.el.setStyle('width', Math.ceil((this.aria_valuenow / this.aria_valuemax) * 100) + '%');
17917 * @class Roo.bootstrap.TabGroup
17918 * @extends Roo.bootstrap.Column
17919 * Bootstrap Column class
17920 * @cfg {String} navId the navigation id (for use with navbars) - will be auto generated if it does not exist..
17921 * @cfg {Boolean} carousel true to make the group behave like a carousel
17922 * @cfg {Boolean} bullets show bullets for the panels
17923 * @cfg {Boolean} autoslide (true|false) auto slide .. default false
17924 * @cfg {Number} timer auto slide timer .. default 0 millisecond
17925 * @cfg {Boolean} showarrow (true|false) show arrow default true
17928 * Create a new TabGroup
17929 * @param {Object} config The config object
17932 Roo.bootstrap.TabGroup = function(config){
17933 Roo.bootstrap.TabGroup.superclass.constructor.call(this, config);
17935 this.navId = Roo.id();
17938 Roo.bootstrap.TabGroup.register(this);
17942 Roo.extend(Roo.bootstrap.TabGroup, Roo.bootstrap.Column, {
17945 transition : false,
17950 slideOnTouch : false,
17953 getAutoCreate : function()
17955 var cfg = Roo.apply({}, Roo.bootstrap.TabGroup.superclass.getAutoCreate.call(this));
17957 cfg.cls += ' tab-content';
17959 if (this.carousel) {
17960 cfg.cls += ' carousel slide';
17963 cls : 'carousel-inner',
17967 if(this.bullets && !Roo.isTouch){
17970 cls : 'carousel-bullets',
17974 if(this.bullets_cls){
17975 bullets.cls = bullets.cls + ' ' + this.bullets_cls;
17982 cfg.cn[0].cn.push(bullets);
17985 if(this.showarrow){
17986 cfg.cn[0].cn.push({
17988 class : 'carousel-arrow',
17992 class : 'carousel-prev',
17996 class : 'fa fa-chevron-left'
18002 class : 'carousel-next',
18006 class : 'fa fa-chevron-right'
18019 initEvents: function()
18021 // if(Roo.isTouch && this.slideOnTouch && !this.showarrow){
18022 // this.el.on("touchstart", this.onTouchStart, this);
18025 if(this.autoslide){
18028 this.slideFn = window.setInterval(function() {
18029 _this.showPanelNext();
18033 if(this.showarrow){
18034 this.el.select('.carousel-prev', true).first().on('click', this.showPanelPrev, this);
18035 this.el.select('.carousel-next', true).first().on('click', this.showPanelNext, this);
18041 // onTouchStart : function(e, el, o)
18043 // if(!this.slideOnTouch || !Roo.isTouch || Roo.get(e.getTarget()).hasClass('roo-button-text')){
18047 // this.showPanelNext();
18051 getChildContainer : function()
18053 return this.carousel ? this.el.select('.carousel-inner', true).first() : this.el;
18057 * register a Navigation item
18058 * @param {Roo.bootstrap.NavItem} the navitem to add
18060 register : function(item)
18062 this.tabs.push( item);
18063 item.navId = this.navId; // not really needed..
18068 getActivePanel : function()
18071 Roo.each(this.tabs, function(t) {
18081 getPanelByName : function(n)
18084 Roo.each(this.tabs, function(t) {
18085 if (t.tabId == n) {
18093 indexOfPanel : function(p)
18096 Roo.each(this.tabs, function(t,i) {
18097 if (t.tabId == p.tabId) {
18106 * show a specific panel
18107 * @param {Roo.bootstrap.TabPanel|number|string} panel to change to (use the tabId to specify a specific one)
18108 * @return {boolean} false if panel was not shown (invalid entry or beforedeactivate fails.)
18110 showPanel : function (pan)
18112 if(this.transition || typeof(pan) == 'undefined'){
18113 Roo.log("waiting for the transitionend");
18117 if (typeof(pan) == 'number') {
18118 pan = this.tabs[pan];
18121 if (typeof(pan) == 'string') {
18122 pan = this.getPanelByName(pan);
18125 var cur = this.getActivePanel();
18128 Roo.log('pan or acitve pan is undefined');
18132 if (pan.tabId == this.getActivePanel().tabId) {
18136 if (false === cur.fireEvent('beforedeactivate')) {
18140 if(this.bullets > 0 && !Roo.isTouch){
18141 this.setActiveBullet(this.indexOfPanel(pan));
18144 if (this.carousel && typeof(Roo.get(document.body).dom.style.transition) != 'undefined') {
18146 this.transition = true;
18147 var dir = this.indexOfPanel(pan) > this.indexOfPanel(cur) ? 'next' : 'prev';
18148 var lr = dir == 'next' ? 'left' : 'right';
18149 pan.el.addClass(dir); // or prev
18150 pan.el.dom.offsetWidth; // find the offset with - causing a reflow?
18151 cur.el.addClass(lr); // or right
18152 pan.el.addClass(lr);
18155 cur.el.on('transitionend', function() {
18156 Roo.log("trans end?");
18158 pan.el.removeClass([lr,dir]);
18159 pan.setActive(true);
18161 cur.el.removeClass([lr]);
18162 cur.setActive(false);
18164 _this.transition = false;
18166 }, this, { single: true } );
18171 cur.setActive(false);
18172 pan.setActive(true);
18177 showPanelNext : function()
18179 var i = this.indexOfPanel(this.getActivePanel());
18181 if (i >= this.tabs.length - 1 && !this.autoslide) {
18185 if (i >= this.tabs.length - 1 && this.autoslide) {
18189 this.showPanel(this.tabs[i+1]);
18192 showPanelPrev : function()
18194 var i = this.indexOfPanel(this.getActivePanel());
18196 if (i < 1 && !this.autoslide) {
18200 if (i < 1 && this.autoslide) {
18201 i = this.tabs.length;
18204 this.showPanel(this.tabs[i-1]);
18208 addBullet: function()
18210 if(!this.bullets || Roo.isTouch){
18213 var ctr = this.el.select('.carousel-bullets',true).first();
18214 var i = this.el.select('.carousel-bullets .bullet',true).getCount() ;
18215 var bullet = ctr.createChild({
18216 cls : 'bullet bullet-' + i
18217 },ctr.dom.lastChild);
18222 bullet.on('click', (function(e, el, o, ii, t){
18224 e.preventDefault();
18226 this.showPanel(ii);
18228 if(this.autoslide && this.slideFn){
18229 clearInterval(this.slideFn);
18230 this.slideFn = window.setInterval(function() {
18231 _this.showPanelNext();
18235 }).createDelegate(this, [i, bullet], true));
18240 setActiveBullet : function(i)
18246 Roo.each(this.el.select('.bullet', true).elements, function(el){
18247 el.removeClass('selected');
18250 var bullet = this.el.select('.bullet-' + i, true).first();
18256 bullet.addClass('selected');
18267 Roo.apply(Roo.bootstrap.TabGroup, {
18271 * register a Navigation Group
18272 * @param {Roo.bootstrap.NavGroup} the navgroup to add
18274 register : function(navgrp)
18276 this.groups[navgrp.navId] = navgrp;
18280 * fetch a Navigation Group based on the navigation ID
18281 * if one does not exist , it will get created.
18282 * @param {string} the navgroup to add
18283 * @returns {Roo.bootstrap.NavGroup} the navgroup
18285 get: function(navId) {
18286 if (typeof(this.groups[navId]) == 'undefined') {
18287 this.register(new Roo.bootstrap.TabGroup({ navId : navId }));
18289 return this.groups[navId] ;
18304 * @class Roo.bootstrap.TabPanel
18305 * @extends Roo.bootstrap.Component
18306 * Bootstrap TabPanel class
18307 * @cfg {Boolean} active panel active
18308 * @cfg {String} html panel content
18309 * @cfg {String} tabId unique tab ID (will be autogenerated if not set. - used to match TabItem to Panel)
18310 * @cfg {String} navId The Roo.bootstrap.NavGroup which triggers show hide ()
18311 * @cfg {String} href click to link..
18315 * Create a new TabPanel
18316 * @param {Object} config The config object
18319 Roo.bootstrap.TabPanel = function(config){
18320 Roo.bootstrap.TabPanel.superclass.constructor.call(this, config);
18324 * Fires when the active status changes
18325 * @param {Roo.bootstrap.TabPanel} this
18326 * @param {Boolean} state the new state
18331 * @event beforedeactivate
18332 * Fires before a tab is de-activated - can be used to do validation on a form.
18333 * @param {Roo.bootstrap.TabPanel} this
18334 * @return {Boolean} false if there is an error
18337 'beforedeactivate': true
18340 this.tabId = this.tabId || Roo.id();
18344 Roo.extend(Roo.bootstrap.TabPanel, Roo.bootstrap.Component, {
18352 getAutoCreate : function(){
18355 // item is needed for carousel - not sure if it has any effect otherwise
18356 cls: 'tab-pane item' + ((this.href.length) ? ' clickable ' : ''),
18357 html: this.html || ''
18361 cfg.cls += ' active';
18365 cfg.tabId = this.tabId;
18372 initEvents: function()
18374 var p = this.parent();
18376 this.navId = this.navId || p.navId;
18378 if (typeof(this.navId) != 'undefined') {
18379 // not really needed.. but just in case.. parent should be a NavGroup.
18380 var tg = Roo.bootstrap.TabGroup.get(this.navId);
18384 var i = tg.tabs.length - 1;
18386 if(this.active && tg.bullets > 0 && i < tg.bullets){
18387 tg.setActiveBullet(i);
18391 this.el.on('click', this.onClick, this);
18394 this.el.on("touchstart", this.onTouchStart, this);
18395 this.el.on("touchmove", this.onTouchMove, this);
18396 this.el.on("touchend", this.onTouchEnd, this);
18401 onRender : function(ct, position)
18403 Roo.bootstrap.TabPanel.superclass.onRender.call(this, ct, position);
18406 setActive : function(state)
18408 Roo.log("panel - set active " + this.tabId + "=" + state);
18410 this.active = state;
18412 this.el.removeClass('active');
18414 } else if (!this.el.hasClass('active')) {
18415 this.el.addClass('active');
18418 this.fireEvent('changed', this, state);
18421 onClick : function(e)
18423 e.preventDefault();
18425 if(!this.href.length){
18429 window.location.href = this.href;
18438 onTouchStart : function(e)
18440 this.swiping = false;
18442 this.startX = e.browserEvent.touches[0].clientX;
18443 this.startY = e.browserEvent.touches[0].clientY;
18446 onTouchMove : function(e)
18448 this.swiping = true;
18450 this.endX = e.browserEvent.touches[0].clientX;
18451 this.endY = e.browserEvent.touches[0].clientY;
18454 onTouchEnd : function(e)
18461 var tabGroup = this.parent();
18463 if(this.endX > this.startX){ // swiping right
18464 tabGroup.showPanelPrev();
18468 if(this.startX > this.endX){ // swiping left
18469 tabGroup.showPanelNext();
18488 * @class Roo.bootstrap.DateField
18489 * @extends Roo.bootstrap.Input
18490 * Bootstrap DateField class
18491 * @cfg {Number} weekStart default 0
18492 * @cfg {String} viewMode default empty, (months|years)
18493 * @cfg {String} minViewMode default empty, (months|years)
18494 * @cfg {Number} startDate default -Infinity
18495 * @cfg {Number} endDate default Infinity
18496 * @cfg {Boolean} todayHighlight default false
18497 * @cfg {Boolean} todayBtn default false
18498 * @cfg {Boolean} calendarWeeks default false
18499 * @cfg {Object} daysOfWeekDisabled default empty
18500 * @cfg {Boolean} singleMode default false (true | false)
18502 * @cfg {Boolean} keyboardNavigation default true
18503 * @cfg {String} language default en
18506 * Create a new DateField
18507 * @param {Object} config The config object
18510 Roo.bootstrap.DateField = function(config){
18511 Roo.bootstrap.DateField.superclass.constructor.call(this, config);
18515 * Fires when this field show.
18516 * @param {Roo.bootstrap.DateField} this
18517 * @param {Mixed} date The date value
18522 * Fires when this field hide.
18523 * @param {Roo.bootstrap.DateField} this
18524 * @param {Mixed} date The date value
18529 * Fires when select a date.
18530 * @param {Roo.bootstrap.DateField} this
18531 * @param {Mixed} date The date value
18535 * @event beforeselect
18536 * Fires when before select a date.
18537 * @param {Roo.bootstrap.DateField} this
18538 * @param {Mixed} date The date value
18540 beforeselect : true
18544 Roo.extend(Roo.bootstrap.DateField, Roo.bootstrap.Input, {
18547 * @cfg {String} format
18548 * The default date format string which can be overriden for localization support. The format must be
18549 * valid according to {@link Date#parseDate} (defaults to 'm/d/y').
18553 * @cfg {String} altFormats
18554 * Multiple date formats separated by "|" to try when parsing a user input value and it doesn't match the defined
18555 * format (defaults to 'm/d/Y|m-d-y|m-d-Y|m/d|m-d|d').
18557 altFormats : "m/d/Y|m-d-y|m-d-Y|m/d|m-d|md|mdy|mdY|d",
18565 todayHighlight : false,
18571 keyboardNavigation: true,
18573 calendarWeeks: false,
18575 startDate: -Infinity,
18579 daysOfWeekDisabled: [],
18583 singleMode : false,
18585 UTCDate: function()
18587 return new Date(Date.UTC.apply(Date, arguments));
18590 UTCToday: function()
18592 var today = new Date();
18593 return this.UTCDate(today.getUTCFullYear(), today.getUTCMonth(), today.getUTCDate());
18596 getDate: function() {
18597 var d = this.getUTCDate();
18598 return new Date(d.getTime() + (d.getTimezoneOffset()*60000));
18601 getUTCDate: function() {
18605 setDate: function(d) {
18606 this.setUTCDate(new Date(d.getTime() - (d.getTimezoneOffset()*60000)));
18609 setUTCDate: function(d) {
18611 this.setValue(this.formatDate(this.date));
18614 onRender: function(ct, position)
18617 Roo.bootstrap.DateField.superclass.onRender.call(this, ct, position);
18619 this.language = this.language || 'en';
18620 this.language = this.language in Roo.bootstrap.DateField.dates ? this.language : this.language.split('-')[0];
18621 this.language = this.language in Roo.bootstrap.DateField.dates ? this.language : "en";
18623 this.isRTL = Roo.bootstrap.DateField.dates[this.language].rtl || false;
18624 this.format = this.format || 'm/d/y';
18625 this.isInline = false;
18626 this.isInput = true;
18627 this.component = this.el.select('.add-on', true).first() || false;
18628 this.component = (this.component && this.component.length === 0) ? false : this.component;
18629 this.hasInput = this.component && this.inputEl().length;
18631 if (typeof(this.minViewMode === 'string')) {
18632 switch (this.minViewMode) {
18634 this.minViewMode = 1;
18637 this.minViewMode = 2;
18640 this.minViewMode = 0;
18645 if (typeof(this.viewMode === 'string')) {
18646 switch (this.viewMode) {
18659 this.pickerEl = Roo.get(document.body).createChild(Roo.bootstrap.DateField.template);
18661 // this.el.select('>.input-group', true).first().createChild(Roo.bootstrap.DateField.template);
18663 this.picker().setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
18665 this.picker().on('mousedown', this.onMousedown, this);
18666 this.picker().on('click', this.onClick, this);
18668 this.picker().addClass('datepicker-dropdown');
18670 this.startViewMode = this.viewMode;
18672 if(this.singleMode){
18673 Roo.each(this.picker().select('thead > tr > th', true).elements, function(v){
18674 v.setVisibilityMode(Roo.Element.DISPLAY);
18678 Roo.each(this.picker().select('tbody > tr > td', true).elements, function(v){
18679 v.setStyle('width', '189px');
18683 Roo.each(this.picker().select('tfoot th.today', true).elements, function(v){
18684 if(!this.calendarWeeks){
18689 v.dom.innerHTML = Roo.bootstrap.DateField.dates[this.language].today;
18690 v.attr('colspan', function(i, val){
18691 return parseInt(val) + 1;
18696 this.weekEnd = this.weekStart === 0 ? 6 : this.weekStart - 1;
18698 this.setStartDate(this.startDate);
18699 this.setEndDate(this.endDate);
18701 this.setDaysOfWeekDisabled(this.daysOfWeekDisabled);
18708 if(this.isInline) {
18713 picker : function()
18715 return this.pickerEl;
18716 // return this.el.select('.datepicker', true).first();
18719 fillDow: function()
18721 var dowCnt = this.weekStart;
18730 if(this.calendarWeeks){
18738 while (dowCnt < this.weekStart + 7) {
18742 html: Roo.bootstrap.DateField.dates[this.language].daysMin[(dowCnt++)%7]
18746 this.picker().select('>.datepicker-days thead', true).first().createChild(dow);
18749 fillMonths: function()
18752 var months = this.picker().select('>.datepicker-months td', true).first();
18754 months.dom.innerHTML = '';
18760 html: Roo.bootstrap.DateField.dates[this.language].monthsShort[i++]
18763 months.createChild(month);
18770 this.date = (typeof(this.date) === 'undefined' || ((typeof(this.date) === 'string') && !this.date.length)) ? this.UTCToday() : (typeof(this.date) === 'string') ? this.parseDate(this.date) : this.date;
18772 if (this.date < this.startDate) {
18773 this.viewDate = new Date(this.startDate);
18774 } else if (this.date > this.endDate) {
18775 this.viewDate = new Date(this.endDate);
18777 this.viewDate = new Date(this.date);
18785 var d = new Date(this.viewDate),
18786 year = d.getUTCFullYear(),
18787 month = d.getUTCMonth(),
18788 startYear = this.startDate !== -Infinity ? this.startDate.getUTCFullYear() : -Infinity,
18789 startMonth = this.startDate !== -Infinity ? this.startDate.getUTCMonth() : -Infinity,
18790 endYear = this.endDate !== Infinity ? this.endDate.getUTCFullYear() : Infinity,
18791 endMonth = this.endDate !== Infinity ? this.endDate.getUTCMonth() : Infinity,
18792 currentDate = this.date && this.date.valueOf(),
18793 today = this.UTCToday();
18795 this.picker().select('>.datepicker-days thead th.switch', true).first().dom.innerHTML = Roo.bootstrap.DateField.dates[this.language].months[month]+' '+year;
18797 // this.picker().select('>tfoot th.today', true).first().dom.innerHTML = Roo.bootstrap.DateField.dates[this.language].today;
18799 // this.picker.select('>tfoot th.today').
18800 // .text(dates[this.language].today)
18801 // .toggle(this.todayBtn !== false);
18803 this.updateNavArrows();
18806 var prevMonth = this.UTCDate(year, month-1, 28,0,0,0,0),
18808 day = prevMonth.getDaysInMonth(prevMonth.getUTCFullYear(), prevMonth.getUTCMonth());
18810 prevMonth.setUTCDate(day);
18812 prevMonth.setUTCDate(day - (prevMonth.getUTCDay() - this.weekStart + 7)%7);
18814 var nextMonth = new Date(prevMonth);
18816 nextMonth.setUTCDate(nextMonth.getUTCDate() + 42);
18818 nextMonth = nextMonth.valueOf();
18820 var fillMonths = false;
18822 this.picker().select('>.datepicker-days tbody',true).first().dom.innerHTML = '';
18824 while(prevMonth.valueOf() <= nextMonth) {
18827 if (prevMonth.getUTCDay() === this.weekStart) {
18829 this.picker().select('>.datepicker-days tbody',true).first().createChild(fillMonths);
18837 if(this.calendarWeeks){
18838 // ISO 8601: First week contains first thursday.
18839 // ISO also states week starts on Monday, but we can be more abstract here.
18841 // Start of current week: based on weekstart/current date
18842 ws = new Date(+prevMonth + (this.weekStart - prevMonth.getUTCDay() - 7) % 7 * 864e5),
18843 // Thursday of this week
18844 th = new Date(+ws + (7 + 4 - ws.getUTCDay()) % 7 * 864e5),
18845 // First Thursday of year, year from thursday
18846 yth = new Date(+(yth = this.UTCDate(th.getUTCFullYear(), 0, 1)) + (7 + 4 - yth.getUTCDay())%7*864e5),
18847 // Calendar week: ms between thursdays, div ms per day, div 7 days
18848 calWeek = (th - yth) / 864e5 / 7 + 1;
18850 fillMonths.cn.push({
18858 if (prevMonth.getUTCFullYear() < year || (prevMonth.getUTCFullYear() == year && prevMonth.getUTCMonth() < month)) {
18860 } else if (prevMonth.getUTCFullYear() > year || (prevMonth.getUTCFullYear() == year && prevMonth.getUTCMonth() > month)) {
18863 if (this.todayHighlight &&
18864 prevMonth.getUTCFullYear() == today.getFullYear() &&
18865 prevMonth.getUTCMonth() == today.getMonth() &&
18866 prevMonth.getUTCDate() == today.getDate()) {
18867 clsName += ' today';
18870 if (currentDate && prevMonth.valueOf() === currentDate) {
18871 clsName += ' active';
18874 if (prevMonth.valueOf() < this.startDate || prevMonth.valueOf() > this.endDate ||
18875 this.daysOfWeekDisabled.indexOf(prevMonth.getUTCDay()) !== -1) {
18876 clsName += ' disabled';
18879 fillMonths.cn.push({
18881 cls: 'day ' + clsName,
18882 html: prevMonth.getDate()
18885 prevMonth.setDate(prevMonth.getDate()+1);
18888 var currentYear = this.date && this.date.getUTCFullYear();
18889 var currentMonth = this.date && this.date.getUTCMonth();
18891 this.picker().select('>.datepicker-months th.switch',true).first().dom.innerHTML = year;
18893 Roo.each(this.picker().select('>.datepicker-months tbody span',true).elements, function(v,k){
18894 v.removeClass('active');
18896 if(currentYear === year && k === currentMonth){
18897 v.addClass('active');
18900 if (year < startYear || year > endYear || (year == startYear && k < startMonth) || (year == endYear && k > endMonth)) {
18901 v.addClass('disabled');
18907 year = parseInt(year/10, 10) * 10;
18909 this.picker().select('>.datepicker-years th.switch', true).first().dom.innerHTML = year + '-' + (year + 9);
18911 this.picker().select('>.datepicker-years tbody td',true).first().dom.innerHTML = '';
18914 for (var i = -1; i < 11; i++) {
18915 this.picker().select('>.datepicker-years tbody td',true).first().createChild({
18917 cls: 'year' + (i === -1 || i === 10 ? ' old' : '') + (currentYear === year ? ' active' : '') + (year < startYear || year > endYear ? ' disabled' : ''),
18925 showMode: function(dir)
18928 this.viewMode = Math.max(this.minViewMode, Math.min(2, this.viewMode + dir));
18931 Roo.each(this.picker().select('>div',true).elements, function(v){
18932 v.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
18935 this.picker().select('>.datepicker-'+Roo.bootstrap.DateField.modes[this.viewMode].clsName, true).first().show();
18940 if(this.isInline) {
18944 this.picker().removeClass(['bottom', 'top']);
18946 if((Roo.lib.Dom.getViewHeight() + Roo.get(document.body).getScroll().top) - (this.inputEl().getBottom() + this.picker().getHeight()) < 0){
18948 * place to the top of element!
18952 this.picker().addClass('top');
18953 this.picker().setTop(this.inputEl().getTop() - this.picker().getHeight()).setLeft(this.inputEl().getLeft());
18958 this.picker().addClass('bottom');
18960 this.picker().setTop(this.inputEl().getBottom()).setLeft(this.inputEl().getLeft());
18963 parseDate : function(value)
18965 if(!value || value instanceof Date){
18968 var v = Date.parseDate(value, this.format);
18969 if (!v && (this.useIso || value.match(/^(\d{4})-0?(\d+)-0?(\d+)/))) {
18970 v = Date.parseDate(value, 'Y-m-d');
18972 if(!v && this.altFormats){
18973 if(!this.altFormatsArray){
18974 this.altFormatsArray = this.altFormats.split("|");
18976 for(var i = 0, len = this.altFormatsArray.length; i < len && !v; i++){
18977 v = Date.parseDate(value, this.altFormatsArray[i]);
18983 formatDate : function(date, fmt)
18985 return (!date || !(date instanceof Date)) ?
18986 date : date.dateFormat(fmt || this.format);
18989 onFocus : function()
18991 Roo.bootstrap.DateField.superclass.onFocus.call(this);
18995 onBlur : function()
18997 Roo.bootstrap.DateField.superclass.onBlur.call(this);
18999 var d = this.inputEl().getValue();
19006 showPopup : function()
19008 this.picker().show();
19012 this.fireEvent('showpopup', this, this.date);
19015 hidePopup : function()
19017 if(this.isInline) {
19020 this.picker().hide();
19021 this.viewMode = this.startViewMode;
19024 this.fireEvent('hidepopup', this, this.date);
19028 onMousedown: function(e)
19030 e.stopPropagation();
19031 e.preventDefault();
19036 Roo.bootstrap.DateField.superclass.keyup.call(this);
19040 setValue: function(v)
19042 if(this.fireEvent('beforeselect', this, v) !== false){
19043 var d = new Date(this.parseDate(v) ).clearTime();
19045 if(isNaN(d.getTime())){
19046 this.date = this.viewDate = '';
19047 Roo.bootstrap.DateField.superclass.setValue.call(this, '');
19051 v = this.formatDate(d);
19053 Roo.bootstrap.DateField.superclass.setValue.call(this, v);
19055 this.date = new Date(d.getTime() - d.getTimezoneOffset()*60000);
19059 this.fireEvent('select', this, this.date);
19063 getValue: function()
19065 return this.formatDate(this.date);
19068 fireKey: function(e)
19070 if (!this.picker().isVisible()){
19071 if (e.keyCode == 27) { // allow escape to hide and re-show picker
19077 var dateChanged = false,
19079 newDate, newViewDate;
19084 e.preventDefault();
19088 if (!this.keyboardNavigation) {
19091 dir = e.keyCode == 37 ? -1 : 1;
19094 newDate = this.moveYear(this.date, dir);
19095 newViewDate = this.moveYear(this.viewDate, dir);
19096 } else if (e.shiftKey){
19097 newDate = this.moveMonth(this.date, dir);
19098 newViewDate = this.moveMonth(this.viewDate, dir);
19100 newDate = new Date(this.date);
19101 newDate.setUTCDate(this.date.getUTCDate() + dir);
19102 newViewDate = new Date(this.viewDate);
19103 newViewDate.setUTCDate(this.viewDate.getUTCDate() + dir);
19105 if (this.dateWithinRange(newDate)){
19106 this.date = newDate;
19107 this.viewDate = newViewDate;
19108 this.setValue(this.formatDate(this.date));
19110 e.preventDefault();
19111 dateChanged = true;
19116 if (!this.keyboardNavigation) {
19119 dir = e.keyCode == 38 ? -1 : 1;
19121 newDate = this.moveYear(this.date, dir);
19122 newViewDate = this.moveYear(this.viewDate, dir);
19123 } else if (e.shiftKey){
19124 newDate = this.moveMonth(this.date, dir);
19125 newViewDate = this.moveMonth(this.viewDate, dir);
19127 newDate = new Date(this.date);
19128 newDate.setUTCDate(this.date.getUTCDate() + dir * 7);
19129 newViewDate = new Date(this.viewDate);
19130 newViewDate.setUTCDate(this.viewDate.getUTCDate() + dir * 7);
19132 if (this.dateWithinRange(newDate)){
19133 this.date = newDate;
19134 this.viewDate = newViewDate;
19135 this.setValue(this.formatDate(this.date));
19137 e.preventDefault();
19138 dateChanged = true;
19142 this.setValue(this.formatDate(this.date));
19144 e.preventDefault();
19147 this.setValue(this.formatDate(this.date));
19161 onClick: function(e)
19163 e.stopPropagation();
19164 e.preventDefault();
19166 var target = e.getTarget();
19168 if(target.nodeName.toLowerCase() === 'i'){
19169 target = Roo.get(target).dom.parentNode;
19172 var nodeName = target.nodeName;
19173 var className = target.className;
19174 var html = target.innerHTML;
19175 //Roo.log(nodeName);
19177 switch(nodeName.toLowerCase()) {
19179 switch(className) {
19185 var dir = Roo.bootstrap.DateField.modes[this.viewMode].navStep * (className == 'prev' ? -1 : 1);
19186 switch(this.viewMode){
19188 this.viewDate = this.moveMonth(this.viewDate, dir);
19192 this.viewDate = this.moveYear(this.viewDate, dir);
19198 var date = new Date();
19199 this.date = this.UTCDate(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0);
19201 this.setValue(this.formatDate(this.date));
19208 if (className.indexOf('disabled') < 0) {
19209 this.viewDate.setUTCDate(1);
19210 if (className.indexOf('month') > -1) {
19211 this.viewDate.setUTCMonth(Roo.bootstrap.DateField.dates[this.language].monthsShort.indexOf(html));
19213 var year = parseInt(html, 10) || 0;
19214 this.viewDate.setUTCFullYear(year);
19218 if(this.singleMode){
19219 this.setValue(this.formatDate(this.viewDate));
19230 //Roo.log(className);
19231 if (className.indexOf('day') > -1 && className.indexOf('disabled') < 0 ){
19232 var day = parseInt(html, 10) || 1;
19233 var year = this.viewDate.getUTCFullYear(),
19234 month = this.viewDate.getUTCMonth();
19236 if (className.indexOf('old') > -1) {
19243 } else if (className.indexOf('new') > -1) {
19251 //Roo.log([year,month,day]);
19252 this.date = this.UTCDate(year, month, day,0,0,0,0);
19253 this.viewDate = this.UTCDate(year, month, Math.min(28, day),0,0,0,0);
19255 //Roo.log(this.formatDate(this.date));
19256 this.setValue(this.formatDate(this.date));
19263 setStartDate: function(startDate)
19265 this.startDate = startDate || -Infinity;
19266 if (this.startDate !== -Infinity) {
19267 this.startDate = this.parseDate(this.startDate);
19270 this.updateNavArrows();
19273 setEndDate: function(endDate)
19275 this.endDate = endDate || Infinity;
19276 if (this.endDate !== Infinity) {
19277 this.endDate = this.parseDate(this.endDate);
19280 this.updateNavArrows();
19283 setDaysOfWeekDisabled: function(daysOfWeekDisabled)
19285 this.daysOfWeekDisabled = daysOfWeekDisabled || [];
19286 if (typeof(this.daysOfWeekDisabled) !== 'object') {
19287 this.daysOfWeekDisabled = this.daysOfWeekDisabled.split(/,\s*/);
19289 this.daysOfWeekDisabled = this.daysOfWeekDisabled.map(function (d) {
19290 return parseInt(d, 10);
19293 this.updateNavArrows();
19296 updateNavArrows: function()
19298 if(this.singleMode){
19302 var d = new Date(this.viewDate),
19303 year = d.getUTCFullYear(),
19304 month = d.getUTCMonth();
19306 Roo.each(this.picker().select('.prev', true).elements, function(v){
19308 switch (this.viewMode) {
19311 if (this.startDate !== -Infinity && year <= this.startDate.getUTCFullYear() && month <= this.startDate.getUTCMonth()) {
19317 if (this.startDate !== -Infinity && year <= this.startDate.getUTCFullYear()) {
19324 Roo.each(this.picker().select('.next', true).elements, function(v){
19326 switch (this.viewMode) {
19329 if (this.endDate !== Infinity && year >= this.endDate.getUTCFullYear() && month >= this.endDate.getUTCMonth()) {
19335 if (this.endDate !== Infinity && year >= this.endDate.getUTCFullYear()) {
19343 moveMonth: function(date, dir)
19348 var new_date = new Date(date.valueOf()),
19349 day = new_date.getUTCDate(),
19350 month = new_date.getUTCMonth(),
19351 mag = Math.abs(dir),
19353 dir = dir > 0 ? 1 : -1;
19356 // If going back one month, make sure month is not current month
19357 // (eg, Mar 31 -> Feb 31 == Feb 28, not Mar 02)
19359 return new_date.getUTCMonth() == month;
19361 // If going forward one month, make sure month is as expected
19362 // (eg, Jan 31 -> Feb 31 == Feb 28, not Mar 02)
19364 return new_date.getUTCMonth() != new_month;
19366 new_month = month + dir;
19367 new_date.setUTCMonth(new_month);
19368 // Dec -> Jan (12) or Jan -> Dec (-1) -- limit expected date to 0-11
19369 if (new_month < 0 || new_month > 11) {
19370 new_month = (new_month + 12) % 12;
19373 // For magnitudes >1, move one month at a time...
19374 for (var i=0; i<mag; i++) {
19375 // ...which might decrease the day (eg, Jan 31 to Feb 28, etc)...
19376 new_date = this.moveMonth(new_date, dir);
19378 // ...then reset the day, keeping it in the new month
19379 new_month = new_date.getUTCMonth();
19380 new_date.setUTCDate(day);
19382 return new_month != new_date.getUTCMonth();
19385 // Common date-resetting loop -- if date is beyond end of month, make it
19388 new_date.setUTCDate(--day);
19389 new_date.setUTCMonth(new_month);
19394 moveYear: function(date, dir)
19396 return this.moveMonth(date, dir*12);
19399 dateWithinRange: function(date)
19401 return date >= this.startDate && date <= this.endDate;
19407 this.picker().remove();
19410 validateValue : function(value)
19412 if(this.getVisibilityEl().hasClass('hidden')){
19416 if(value.length < 1) {
19417 if(this.allowBlank){
19423 if(value.length < this.minLength){
19426 if(value.length > this.maxLength){
19430 var vt = Roo.form.VTypes;
19431 if(!vt[this.vtype](value, this)){
19435 if(typeof this.validator == "function"){
19436 var msg = this.validator(value);
19442 if(this.regex && !this.regex.test(value)){
19446 if(typeof(this.parseDate(value)) == 'undefined'){
19450 if (this.endDate !== Infinity && this.parseDate(value).getTime() > this.endDate.getTime()) {
19454 if (this.startDate !== -Infinity && this.parseDate(value).getTime() < this.startDate.getTime()) {
19464 this.date = this.viewDate = '';
19466 Roo.bootstrap.DateField.superclass.setValue.call(this, '');
19471 Roo.apply(Roo.bootstrap.DateField, {
19482 html: '<i class="fa fa-arrow-left"/>'
19492 html: '<i class="fa fa-arrow-right"/>'
19534 days: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"],
19535 daysShort: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
19536 daysMin: ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"],
19537 months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
19538 monthsShort: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
19551 navFnc: 'FullYear',
19556 navFnc: 'FullYear',
19561 Roo.apply(Roo.bootstrap.DateField, {
19565 cls: 'datepicker dropdown-menu roo-dynamic',
19569 cls: 'datepicker-days',
19573 cls: 'table-condensed',
19575 Roo.bootstrap.DateField.head,
19579 Roo.bootstrap.DateField.footer
19586 cls: 'datepicker-months',
19590 cls: 'table-condensed',
19592 Roo.bootstrap.DateField.head,
19593 Roo.bootstrap.DateField.content,
19594 Roo.bootstrap.DateField.footer
19601 cls: 'datepicker-years',
19605 cls: 'table-condensed',
19607 Roo.bootstrap.DateField.head,
19608 Roo.bootstrap.DateField.content,
19609 Roo.bootstrap.DateField.footer
19628 * @class Roo.bootstrap.TimeField
19629 * @extends Roo.bootstrap.Input
19630 * Bootstrap DateField class
19634 * Create a new TimeField
19635 * @param {Object} config The config object
19638 Roo.bootstrap.TimeField = function(config){
19639 Roo.bootstrap.TimeField.superclass.constructor.call(this, config);
19643 * Fires when this field show.
19644 * @param {Roo.bootstrap.DateField} thisthis
19645 * @param {Mixed} date The date value
19650 * Fires when this field hide.
19651 * @param {Roo.bootstrap.DateField} this
19652 * @param {Mixed} date The date value
19657 * Fires when select a date.
19658 * @param {Roo.bootstrap.DateField} this
19659 * @param {Mixed} date The date value
19665 Roo.extend(Roo.bootstrap.TimeField, Roo.bootstrap.Input, {
19668 * @cfg {String} format
19669 * The default time format string which can be overriden for localization support. The format must be
19670 * valid according to {@link Date#parseDate} (defaults to 'H:i').
19674 onRender: function(ct, position)
19677 Roo.bootstrap.TimeField.superclass.onRender.call(this, ct, position);
19679 this.el.select('>.input-group', true).first().createChild(Roo.bootstrap.TimeField.template);
19681 this.picker().setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
19683 this.pop = this.picker().select('>.datepicker-time',true).first();
19684 this.pop.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
19686 this.picker().on('mousedown', this.onMousedown, this);
19687 this.picker().on('click', this.onClick, this);
19689 this.picker().addClass('datepicker-dropdown');
19694 this.pop.select('span.hours-up', true).first().on('click', this.onIncrementHours, this);
19695 this.pop.select('span.hours-down', true).first().on('click', this.onDecrementHours, this);
19696 this.pop.select('span.minutes-up', true).first().on('click', this.onIncrementMinutes, this);
19697 this.pop.select('span.minutes-down', true).first().on('click', this.onDecrementMinutes, this);
19698 this.pop.select('button.period', true).first().on('click', this.onTogglePeriod, this);
19699 this.pop.select('button.ok', true).first().on('click', this.setTime, this);
19703 fireKey: function(e){
19704 if (!this.picker().isVisible()){
19705 if (e.keyCode == 27) { // allow escape to hide and re-show picker
19711 e.preventDefault();
19719 this.onTogglePeriod();
19722 this.onIncrementMinutes();
19725 this.onDecrementMinutes();
19734 onClick: function(e) {
19735 e.stopPropagation();
19736 e.preventDefault();
19739 picker : function()
19741 return this.el.select('.datepicker', true).first();
19744 fillTime: function()
19746 var time = this.pop.select('tbody', true).first();
19748 time.dom.innerHTML = '';
19763 cls: 'hours-up glyphicon glyphicon-chevron-up'
19783 cls: 'minutes-up glyphicon glyphicon-chevron-up'
19804 cls: 'timepicker-hour',
19819 cls: 'timepicker-minute',
19834 cls: 'btn btn-primary period',
19856 cls: 'hours-down glyphicon glyphicon-chevron-down'
19876 cls: 'minutes-down glyphicon glyphicon-chevron-down'
19894 this.time = (typeof(this.time) === 'undefined') ? new Date() : this.time;
19901 var hours = this.time.getHours();
19902 var minutes = this.time.getMinutes();
19915 hours = hours - 12;
19919 hours = '0' + hours;
19923 minutes = '0' + minutes;
19926 this.pop.select('.timepicker-hour', true).first().dom.innerHTML = hours;
19927 this.pop.select('.timepicker-minute', true).first().dom.innerHTML = minutes;
19928 this.pop.select('button', true).first().dom.innerHTML = period;
19934 this.picker().removeClass(['bottom-left', 'bottom-right', 'top-left', 'top-right']);
19936 var cls = ['bottom'];
19938 if((Roo.lib.Dom.getViewHeight() + Roo.get(document.body).getScroll().top) - (this.inputEl().getBottom() + this.picker().getHeight()) < 0){ // top
19945 if((Roo.lib.Dom.getViewWidth() + Roo.get(document.body).getScroll().left) - (this.inputEl().getLeft() + this.picker().getWidth()) < 0){ // left
19950 this.picker().addClass(cls.join('-'));
19954 Roo.each(cls, function(c){
19956 _this.picker().setTop(_this.inputEl().getHeight());
19960 _this.picker().setTop(0 - _this.picker().getHeight());
19965 _this.picker().setLeft(_this.inputEl().getLeft() + _this.inputEl().getWidth() - _this.el.getLeft() - _this.picker().getWidth());
19969 _this.picker().setLeft(_this.inputEl().getLeft() - _this.el.getLeft());
19976 onFocus : function()
19978 Roo.bootstrap.TimeField.superclass.onFocus.call(this);
19982 onBlur : function()
19984 Roo.bootstrap.TimeField.superclass.onBlur.call(this);
19990 this.picker().show();
19995 this.fireEvent('show', this, this.date);
20000 this.picker().hide();
20003 this.fireEvent('hide', this, this.date);
20006 setTime : function()
20009 this.setValue(this.time.format(this.format));
20011 this.fireEvent('select', this, this.date);
20016 onMousedown: function(e){
20017 e.stopPropagation();
20018 e.preventDefault();
20021 onIncrementHours: function()
20023 Roo.log('onIncrementHours');
20024 this.time = this.time.add(Date.HOUR, 1);
20029 onDecrementHours: function()
20031 Roo.log('onDecrementHours');
20032 this.time = this.time.add(Date.HOUR, -1);
20036 onIncrementMinutes: function()
20038 Roo.log('onIncrementMinutes');
20039 this.time = this.time.add(Date.MINUTE, 1);
20043 onDecrementMinutes: function()
20045 Roo.log('onDecrementMinutes');
20046 this.time = this.time.add(Date.MINUTE, -1);
20050 onTogglePeriod: function()
20052 Roo.log('onTogglePeriod');
20053 this.time = this.time.add(Date.HOUR, 12);
20060 Roo.apply(Roo.bootstrap.TimeField, {
20090 cls: 'btn btn-info ok',
20102 Roo.apply(Roo.bootstrap.TimeField, {
20106 cls: 'datepicker dropdown-menu',
20110 cls: 'datepicker-time',
20114 cls: 'table-condensed',
20116 Roo.bootstrap.TimeField.content,
20117 Roo.bootstrap.TimeField.footer
20136 * @class Roo.bootstrap.MonthField
20137 * @extends Roo.bootstrap.Input
20138 * Bootstrap MonthField class
20140 * @cfg {String} language default en
20143 * Create a new MonthField
20144 * @param {Object} config The config object
20147 Roo.bootstrap.MonthField = function(config){
20148 Roo.bootstrap.MonthField.superclass.constructor.call(this, config);
20153 * Fires when this field show.
20154 * @param {Roo.bootstrap.MonthField} this
20155 * @param {Mixed} date The date value
20160 * Fires when this field hide.
20161 * @param {Roo.bootstrap.MonthField} this
20162 * @param {Mixed} date The date value
20167 * Fires when select a date.
20168 * @param {Roo.bootstrap.MonthField} this
20169 * @param {String} oldvalue The old value
20170 * @param {String} newvalue The new value
20176 Roo.extend(Roo.bootstrap.MonthField, Roo.bootstrap.Input, {
20178 onRender: function(ct, position)
20181 Roo.bootstrap.MonthField.superclass.onRender.call(this, ct, position);
20183 this.language = this.language || 'en';
20184 this.language = this.language in Roo.bootstrap.MonthField.dates ? this.language : this.language.split('-')[0];
20185 this.language = this.language in Roo.bootstrap.MonthField.dates ? this.language : "en";
20187 this.isRTL = Roo.bootstrap.MonthField.dates[this.language].rtl || false;
20188 this.isInline = false;
20189 this.isInput = true;
20190 this.component = this.el.select('.add-on', true).first() || false;
20191 this.component = (this.component && this.component.length === 0) ? false : this.component;
20192 this.hasInput = this.component && this.inputEL().length;
20194 this.pickerEl = Roo.get(document.body).createChild(Roo.bootstrap.MonthField.template);
20196 this.picker().setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
20198 this.picker().on('mousedown', this.onMousedown, this);
20199 this.picker().on('click', this.onClick, this);
20201 this.picker().addClass('datepicker-dropdown');
20203 Roo.each(this.picker().select('tbody > tr > td', true).elements, function(v){
20204 v.setStyle('width', '189px');
20211 if(this.isInline) {
20217 setValue: function(v, suppressEvent)
20219 var o = this.getValue();
20221 Roo.bootstrap.MonthField.superclass.setValue.call(this, v);
20225 if(suppressEvent !== true){
20226 this.fireEvent('select', this, o, v);
20231 getValue: function()
20236 onClick: function(e)
20238 e.stopPropagation();
20239 e.preventDefault();
20241 var target = e.getTarget();
20243 if(target.nodeName.toLowerCase() === 'i'){
20244 target = Roo.get(target).dom.parentNode;
20247 var nodeName = target.nodeName;
20248 var className = target.className;
20249 var html = target.innerHTML;
20251 if(nodeName.toLowerCase() != 'span' || className.indexOf('disabled') > -1 || className.indexOf('month') == -1){
20255 this.vIndex = Roo.bootstrap.MonthField.dates[this.language].monthsShort.indexOf(html);
20257 this.setValue(Roo.bootstrap.MonthField.dates[this.language].months[this.vIndex]);
20263 picker : function()
20265 return this.pickerEl;
20268 fillMonths: function()
20271 var months = this.picker().select('>.datepicker-months td', true).first();
20273 months.dom.innerHTML = '';
20279 html: Roo.bootstrap.MonthField.dates[this.language].monthsShort[i++]
20282 months.createChild(month);
20291 if(typeof(this.vIndex) == 'undefined' && this.value.length){
20292 this.vIndex = Roo.bootstrap.MonthField.dates[this.language].months.indexOf(this.value);
20295 Roo.each(this.pickerEl.select('> .datepicker-months tbody > tr > td > span', true).elements, function(e, k){
20296 e.removeClass('active');
20298 if(typeof(_this.vIndex) != 'undefined' && k == _this.vIndex){
20299 e.addClass('active');
20306 if(this.isInline) {
20310 this.picker().removeClass(['bottom', 'top']);
20312 if((Roo.lib.Dom.getViewHeight() + Roo.get(document.body).getScroll().top) - (this.inputEl().getBottom() + this.picker().getHeight()) < 0){
20314 * place to the top of element!
20318 this.picker().addClass('top');
20319 this.picker().setTop(this.inputEl().getTop() - this.picker().getHeight()).setLeft(this.inputEl().getLeft());
20324 this.picker().addClass('bottom');
20326 this.picker().setTop(this.inputEl().getBottom()).setLeft(this.inputEl().getLeft());
20329 onFocus : function()
20331 Roo.bootstrap.MonthField.superclass.onFocus.call(this);
20335 onBlur : function()
20337 Roo.bootstrap.MonthField.superclass.onBlur.call(this);
20339 var d = this.inputEl().getValue();
20348 this.picker().show();
20349 this.picker().select('>.datepicker-months', true).first().show();
20353 this.fireEvent('show', this, this.date);
20358 if(this.isInline) {
20361 this.picker().hide();
20362 this.fireEvent('hide', this, this.date);
20366 onMousedown: function(e)
20368 e.stopPropagation();
20369 e.preventDefault();
20374 Roo.bootstrap.MonthField.superclass.keyup.call(this);
20378 fireKey: function(e)
20380 if (!this.picker().isVisible()){
20381 if (e.keyCode == 27) {// allow escape to hide and re-show picker
20392 e.preventDefault();
20396 dir = e.keyCode == 37 ? -1 : 1;
20398 this.vIndex = this.vIndex + dir;
20400 if(this.vIndex < 0){
20404 if(this.vIndex > 11){
20408 if(isNaN(this.vIndex)){
20412 this.setValue(Roo.bootstrap.MonthField.dates[this.language].months[this.vIndex]);
20418 dir = e.keyCode == 38 ? -1 : 1;
20420 this.vIndex = this.vIndex + dir * 4;
20422 if(this.vIndex < 0){
20426 if(this.vIndex > 11){
20430 if(isNaN(this.vIndex)){
20434 this.setValue(Roo.bootstrap.MonthField.dates[this.language].months[this.vIndex]);
20439 if(typeof(this.vIndex) != 'undefined' && !isNaN(this.vIndex)){
20440 this.setValue(Roo.bootstrap.MonthField.dates[this.language].months[this.vIndex]);
20444 e.preventDefault();
20447 if(typeof(this.vIndex) != 'undefined' && !isNaN(this.vIndex)){
20448 this.setValue(Roo.bootstrap.MonthField.dates[this.language].months[this.vIndex]);
20464 this.picker().remove();
20469 Roo.apply(Roo.bootstrap.MonthField, {
20488 months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
20489 monthsShort: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
20494 Roo.apply(Roo.bootstrap.MonthField, {
20498 cls: 'datepicker dropdown-menu roo-dynamic',
20502 cls: 'datepicker-months',
20506 cls: 'table-condensed',
20508 Roo.bootstrap.DateField.content
20528 * @class Roo.bootstrap.CheckBox
20529 * @extends Roo.bootstrap.Input
20530 * Bootstrap CheckBox class
20532 * @cfg {String} valueOff The value that should go into the generated input element's value when unchecked.
20533 * @cfg {String} inputValue The value that should go into the generated input element's value when checked.
20534 * @cfg {String} boxLabel The text that appears beside the checkbox
20535 * @cfg {String} weight (primary|warning|info|danger|success) The text that appears beside the checkbox
20536 * @cfg {Boolean} checked initnal the element
20537 * @cfg {Boolean} inline inline the element (default false)
20538 * @cfg {String} groupId the checkbox group id // normal just use for checkbox
20539 * @cfg {String} tooltip label tooltip
20542 * Create a new CheckBox
20543 * @param {Object} config The config object
20546 Roo.bootstrap.CheckBox = function(config){
20547 Roo.bootstrap.CheckBox.superclass.constructor.call(this, config);
20552 * Fires when the element is checked or unchecked.
20553 * @param {Roo.bootstrap.CheckBox} this This input
20554 * @param {Boolean} checked The new checked value
20559 * Fires when the element is click.
20560 * @param {Roo.bootstrap.CheckBox} this This input
20567 Roo.extend(Roo.bootstrap.CheckBox, Roo.bootstrap.Input, {
20569 inputType: 'checkbox',
20578 getAutoCreate : function()
20580 var align = (!this.labelAlign) ? this.parentLabelAlign() : this.labelAlign;
20586 cfg.cls = 'form-group ' + this.inputType; //input-group
20589 cfg.cls += ' ' + this.inputType + '-inline';
20595 type : this.inputType,
20596 value : this.inputValue,
20597 cls : 'roo-' + this.inputType, //'form-box',
20598 placeholder : this.placeholder || ''
20602 if(this.inputType != 'radio'){
20606 cls : 'roo-hidden-value',
20607 value : this.checked ? this.inputValue : this.valueOff
20612 if (this.weight) { // Validity check?
20613 cfg.cls += " " + this.inputType + "-" + this.weight;
20616 if (this.disabled) {
20617 input.disabled=true;
20621 input.checked = this.checked;
20626 input.name = this.name;
20628 if(this.inputType != 'radio'){
20629 hidden.name = this.name;
20630 input.name = '_hidden_' + this.name;
20635 input.cls += ' input-' + this.size;
20640 ['xs','sm','md','lg'].map(function(size){
20641 if (settings[size]) {
20642 cfg.cls += ' col-' + size + '-' + settings[size];
20646 var inputblock = input;
20648 if (this.before || this.after) {
20651 cls : 'input-group',
20656 inputblock.cn.push({
20658 cls : 'input-group-addon',
20663 inputblock.cn.push(input);
20665 if(this.inputType != 'radio'){
20666 inputblock.cn.push(hidden);
20670 inputblock.cn.push({
20672 cls : 'input-group-addon',
20679 if (align ==='left' && this.fieldLabel.length) {
20680 // Roo.log("left and has label");
20685 cls : 'control-label',
20686 html : this.fieldLabel
20696 if(this.labelWidth > 12){
20697 cfg.cn[0].style = "width: " + this.labelWidth + 'px';
20700 if(this.labelWidth < 13 && this.labelmd == 0){
20701 this.labelmd = this.labelWidth;
20704 if(this.labellg > 0){
20705 cfg.cn[0].cls += ' col-lg-' + this.labellg;
20706 cfg.cn[1].cls += ' col-lg-' + (12 - this.labellg);
20709 if(this.labelmd > 0){
20710 cfg.cn[0].cls += ' col-md-' + this.labelmd;
20711 cfg.cn[1].cls += ' col-md-' + (12 - this.labelmd);
20714 if(this.labelsm > 0){
20715 cfg.cn[0].cls += ' col-sm-' + this.labelsm;
20716 cfg.cn[1].cls += ' col-sm-' + (12 - this.labelsm);
20719 if(this.labelxs > 0){
20720 cfg.cn[0].cls += ' col-xs-' + this.labelxs;
20721 cfg.cn[1].cls += ' col-xs-' + (12 - this.labelxs);
20724 } else if ( this.fieldLabel.length) {
20725 // Roo.log(" label");
20729 tag: this.boxLabel ? 'span' : 'label',
20731 cls: 'control-label box-input-label',
20732 //cls : 'input-group-addon',
20733 html : this.fieldLabel
20742 // Roo.log(" no label && no align");
20743 cfg.cn = [ inputblock ] ;
20749 var boxLabelCfg = {
20751 //'for': id, // box label is handled by onclick - so no for...
20753 html: this.boxLabel
20757 boxLabelCfg.tooltip = this.tooltip;
20760 cfg.cn.push(boxLabelCfg);
20763 if(this.inputType != 'radio'){
20764 cfg.cn.push(hidden);
20772 * return the real input element.
20774 inputEl: function ()
20776 return this.el.select('input.roo-' + this.inputType,true).first();
20778 hiddenEl: function ()
20780 return this.el.select('input.roo-hidden-value',true).first();
20783 labelEl: function()
20785 return this.el.select('label.control-label',true).first();
20787 /* depricated... */
20791 return this.labelEl();
20794 boxLabelEl: function()
20796 return this.el.select('label.box-label',true).first();
20799 initEvents : function()
20801 // Roo.bootstrap.CheckBox.superclass.initEvents.call(this);
20803 this.inputEl().on('click', this.onClick, this);
20805 if (this.boxLabel) {
20806 this.el.select('label.box-label',true).first().on('click', this.onClick, this);
20809 this.startValue = this.getValue();
20812 Roo.bootstrap.CheckBox.register(this);
20816 onClick : function(e)
20818 if(this.fireEvent('click', this, e) !== false){
20819 this.setChecked(!this.checked);
20824 setChecked : function(state,suppressEvent)
20826 this.startValue = this.getValue();
20828 if(this.inputType == 'radio'){
20830 Roo.each(this.el.up('form').select('input[name='+this.name+']', true).elements, function(e){
20831 e.dom.checked = false;
20834 this.inputEl().dom.checked = true;
20836 this.inputEl().dom.value = this.inputValue;
20838 if(suppressEvent !== true){
20839 this.fireEvent('check', this, true);
20847 this.checked = state;
20849 this.inputEl().dom.checked = state;
20852 this.hiddenEl().dom.value = state ? this.inputValue : this.valueOff;
20854 if(suppressEvent !== true){
20855 this.fireEvent('check', this, state);
20861 getValue : function()
20863 if(this.inputType == 'radio'){
20864 return this.getGroupValue();
20867 return this.hiddenEl().dom.value;
20871 getGroupValue : function()
20873 if(typeof(this.el.up('form').child('input[name='+this.name+']:checked', true)) == 'undefined'){
20877 return this.el.up('form').child('input[name='+this.name+']:checked', true).value;
20880 setValue : function(v,suppressEvent)
20882 if(this.inputType == 'radio'){
20883 this.setGroupValue(v, suppressEvent);
20887 this.setChecked(((typeof(v) == 'undefined') ? this.checked : (String(v) === String(this.inputValue))), suppressEvent);
20892 setGroupValue : function(v, suppressEvent)
20894 this.startValue = this.getValue();
20896 Roo.each(this.el.up('form').select('input[name='+this.name+']', true).elements, function(e){
20897 e.dom.checked = false;
20899 if(e.dom.value == v){
20900 e.dom.checked = true;
20904 if(suppressEvent !== true){
20905 this.fireEvent('check', this, true);
20913 validate : function()
20915 if(this.getVisibilityEl().hasClass('hidden')){
20921 (this.inputType == 'radio' && this.validateRadio()) ||
20922 (this.inputType == 'checkbox' && this.validateCheckbox())
20928 this.markInvalid();
20932 validateRadio : function()
20934 if(this.getVisibilityEl().hasClass('hidden')){
20938 if(this.allowBlank){
20944 Roo.each(this.el.up('form').select('input[name='+this.name+']', true).elements, function(e){
20945 if(!e.dom.checked){
20957 validateCheckbox : function()
20960 return (this.getValue() == this.inputValue || this.allowBlank) ? true : false;
20961 //return (this.getValue() == this.inputValue) ? true : false;
20964 var group = Roo.bootstrap.CheckBox.get(this.groupId);
20972 for(var i in group){
20973 if(group[i].el.isVisible(true)){
20981 for(var i in group){
20986 r = (group[i].getValue() == group[i].inputValue) ? true : false;
20993 * Mark this field as valid
20995 markValid : function()
20999 this.fireEvent('valid', this);
21001 var label = Roo.bootstrap.FieldLabel.get(this.name + '-group');
21004 label = Roo.bootstrap.FieldLabel.get(this.groupId + '-group');
21011 if(this.inputType == 'radio'){
21012 Roo.each(this.el.up('form').select('input[name='+this.name+']', true).elements, function(e){
21013 e.findParent('.form-group', false, true).removeClass([_this.invalidClass, _this.validClass]);
21014 e.findParent('.form-group', false, true).addClass(_this.validClass);
21021 this.el.findParent('.form-group', false, true).removeClass([this.invalidClass, this.validClass]);
21022 this.el.findParent('.form-group', false, true).addClass(this.validClass);
21026 var group = Roo.bootstrap.CheckBox.get(this.groupId);
21032 for(var i in group){
21033 group[i].el.findParent('.form-group', false, true).removeClass([this.invalidClass, this.validClass]);
21034 group[i].el.findParent('.form-group', false, true).addClass(this.validClass);
21039 * Mark this field as invalid
21040 * @param {String} msg The validation message
21042 markInvalid : function(msg)
21044 if(this.allowBlank){
21050 this.fireEvent('invalid', this, msg);
21052 var label = Roo.bootstrap.FieldLabel.get(this.name + '-group');
21055 label = Roo.bootstrap.FieldLabel.get(this.groupId + '-group');
21059 label.markInvalid();
21062 if(this.inputType == 'radio'){
21063 Roo.each(this.el.up('form').select('input[name='+this.name+']', true).elements, function(e){
21064 e.findParent('.form-group', false, true).removeClass([_this.invalidClass, _this.validClass]);
21065 e.findParent('.form-group', false, true).addClass(_this.invalidClass);
21072 this.el.findParent('.form-group', false, true).removeClass([this.invalidClass, this.validClass]);
21073 this.el.findParent('.form-group', false, true).addClass(this.invalidClass);
21077 var group = Roo.bootstrap.CheckBox.get(this.groupId);
21083 for(var i in group){
21084 group[i].el.findParent('.form-group', false, true).removeClass([this.invalidClass, this.validClass]);
21085 group[i].el.findParent('.form-group', false, true).addClass(this.invalidClass);
21090 clearInvalid : function()
21092 Roo.bootstrap.Input.prototype.clearInvalid.call(this);
21094 // this.el.findParent('.form-group', false, true).removeClass([this.invalidClass, this.validClass]);
21096 var label = Roo.bootstrap.FieldLabel.get(this.name + '-group');
21098 if (label && label.iconEl) {
21099 label.iconEl.removeClass(label.validClass);
21100 label.iconEl.removeClass(label.invalidClass);
21104 disable : function()
21106 if(this.inputType != 'radio'){
21107 Roo.bootstrap.CheckBox.superclass.disable.call(this);
21114 Roo.each(this.el.up('form').select('input[name='+this.name+']', true).elements, function(e){
21115 _this.getActionEl().addClass(this.disabledClass);
21116 e.dom.disabled = true;
21120 this.disabled = true;
21121 this.fireEvent("disable", this);
21125 enable : function()
21127 if(this.inputType != 'radio'){
21128 Roo.bootstrap.CheckBox.superclass.enable.call(this);
21135 Roo.each(this.el.up('form').select('input[name='+this.name+']', true).elements, function(e){
21136 _this.getActionEl().removeClass(this.disabledClass);
21137 e.dom.disabled = false;
21141 this.disabled = false;
21142 this.fireEvent("enable", this);
21146 setBoxLabel : function(v)
21151 this.el.select('label.box-label',true).first().dom.innerHTML = (v === null || v === undefined ? '' : v);
21157 Roo.apply(Roo.bootstrap.CheckBox, {
21162 * register a CheckBox Group
21163 * @param {Roo.bootstrap.CheckBox} the CheckBox to add
21165 register : function(checkbox)
21167 if(typeof(this.groups[checkbox.groupId]) == 'undefined'){
21168 this.groups[checkbox.groupId] = {};
21171 if(this.groups[checkbox.groupId].hasOwnProperty(checkbox.name)){
21175 this.groups[checkbox.groupId][checkbox.name] = checkbox;
21179 * fetch a CheckBox Group based on the group ID
21180 * @param {string} the group ID
21181 * @returns {Roo.bootstrap.CheckBox} the CheckBox group
21183 get: function(groupId) {
21184 if (typeof(this.groups[groupId]) == 'undefined') {
21188 return this.groups[groupId] ;
21201 * @class Roo.bootstrap.Radio
21202 * @extends Roo.bootstrap.Component
21203 * Bootstrap Radio class
21204 * @cfg {String} boxLabel - the label associated
21205 * @cfg {String} value - the value of radio
21208 * Create a new Radio
21209 * @param {Object} config The config object
21211 Roo.bootstrap.Radio = function(config){
21212 Roo.bootstrap.Radio.superclass.constructor.call(this, config);
21216 Roo.extend(Roo.bootstrap.Radio, Roo.bootstrap.Component, {
21222 getAutoCreate : function()
21226 cls : 'form-group radio',
21231 html : this.boxLabel
21239 initEvents : function()
21241 this.parent().register(this);
21243 this.el.on('click', this.onClick, this);
21247 onClick : function(e)
21249 if(this.parent().fireEvent('click', this.parent(), this, e) !== false){
21250 this.setChecked(true);
21254 setChecked : function(state, suppressEvent)
21256 this.parent().setValue(this.value, suppressEvent);
21260 setBoxLabel : function(v)
21265 this.el.select('label.box-label',true).first().dom.innerHTML = (v === null || v === undefined ? '' : v);
21280 * @class Roo.bootstrap.SecurePass
21281 * @extends Roo.bootstrap.Input
21282 * Bootstrap SecurePass class
21286 * Create a new SecurePass
21287 * @param {Object} config The config object
21290 Roo.bootstrap.SecurePass = function (config) {
21291 // these go here, so the translation tool can replace them..
21293 PwdEmpty: "Please type a password, and then retype it to confirm.",
21294 PwdShort: "Your password must be at least 6 characters long. Please type a different password.",
21295 PwdLong: "Your password can't contain more than 16 characters. Please type a different password.",
21296 PwdBadChar: "The password contains characters that aren't allowed. Please type a different password.",
21297 IDInPwd: "Your password can't include the part of your ID. Please type a different password.",
21298 FNInPwd: "Your password can't contain your first name. Please type a different password.",
21299 LNInPwd: "Your password can't contain your last name. Please type a different password.",
21300 TooWeak: "Your password is Too Weak."
21302 this.meterLabel = "Password strength:";
21303 this.pwdStrengths = ["Too Weak", "Weak", "Medium", "Strong"];
21304 this.meterClass = [
21305 "roo-password-meter-tooweak",
21306 "roo-password-meter-weak",
21307 "roo-password-meter-medium",
21308 "roo-password-meter-strong",
21309 "roo-password-meter-grey"
21314 Roo.bootstrap.SecurePass.superclass.constructor.call(this, config);
21317 Roo.extend(Roo.bootstrap.SecurePass, Roo.bootstrap.Input, {
21319 * @cfg {String/Object} errors A Error spec, or true for a default spec (defaults to
21321 * PwdEmpty: "Please type a password, and then retype it to confirm.",
21322 * PwdShort: "Your password must be at least 6 characters long. Please type a different password.",
21323 * PwdLong: "Your password can't contain more than 16 characters. Please type a different password.",
21324 * PwdBadChar: "The password contains characters that aren't allowed. Please type a different password.",
21325 * IDInPwd: "Your password can't include the part of your ID. Please type a different password.",
21326 * FNInPwd: "Your password can't contain your first name. Please type a different password.",
21327 * LNInPwd: "Your password can't contain your last name. Please type a different password."
21337 * @cfg {String/Object} Label for the strength meter (defaults to
21338 * 'Password strength:')
21343 * @cfg {String/Object} pwdStrengths A pwdStrengths spec, or true for a default spec (defaults to
21344 * ['Weak', 'Medium', 'Strong'])
21347 pwdStrengths: false,
21360 initEvents: function ()
21362 Roo.bootstrap.SecurePass.superclass.initEvents.call(this);
21364 if (this.el.is('input[type=password]') && Roo.isSafari) {
21365 this.el.on('keydown', this.SafariOnKeyDown, this);
21368 this.el.on('keyup', this.checkStrength, this, {buffer: 50});
21371 onRender: function (ct, position)
21373 Roo.bootstrap.SecurePass.superclass.onRender.call(this, ct, position);
21374 this.wrap = this.el.wrap({cls: 'x-form-field-wrap'});
21375 this.trigger = this.wrap.createChild({tag: 'div', cls: 'StrengthMeter ' + this.triggerClass});
21377 this.trigger.createChild({
21382 cls: 'roo-password-meter-grey col-xs-12',
21385 //width: this.meterWidth + 'px'
21389 cls: 'roo-password-meter-text'
21395 if (this.hideTrigger) {
21396 this.trigger.setDisplayed(false);
21398 this.setSize(this.width || '', this.height || '');
21401 onDestroy: function ()
21403 if (this.trigger) {
21404 this.trigger.removeAllListeners();
21405 this.trigger.remove();
21408 this.wrap.remove();
21410 Roo.bootstrap.TriggerField.superclass.onDestroy.call(this);
21413 checkStrength: function ()
21415 var pwd = this.inputEl().getValue();
21416 if (pwd == this._lastPwd) {
21421 if (this.ClientSideStrongPassword(pwd)) {
21423 } else if (this.ClientSideMediumPassword(pwd)) {
21425 } else if (this.ClientSideWeakPassword(pwd)) {
21431 Roo.log('strength1: ' + strength);
21433 //var pm = this.trigger.child('div/div/div').dom;
21434 var pm = this.trigger.child('div/div');
21435 pm.removeClass(this.meterClass);
21436 pm.addClass(this.meterClass[strength]);
21439 var pt = this.trigger.child('/div').child('>*[class=roo-password-meter-text]').dom;
21441 pt.innerHTML = this.meterLabel + ' ' + this.pwdStrengths[strength];
21443 this._lastPwd = pwd;
21447 Roo.bootstrap.SecurePass.superclass.reset.call(this);
21449 this._lastPwd = '';
21451 var pm = this.trigger.child('div/div');
21452 pm.removeClass(this.meterClass);
21453 pm.addClass('roo-password-meter-grey');
21456 var pt = this.trigger.child('/div').child('>*[class=roo-password-meter-text]').dom;
21459 this.inputEl().dom.type='password';
21462 validateValue: function (value)
21465 if (!Roo.bootstrap.SecurePass.superclass.validateValue.call(this, value)) {
21468 if (value.length == 0) {
21469 if (this.allowBlank) {
21470 this.clearInvalid();
21474 this.markInvalid(this.errors.PwdEmpty);
21475 this.errorMsg = this.errors.PwdEmpty;
21483 if ('[\x21-\x7e]*'.match(value)) {
21484 this.markInvalid(this.errors.PwdBadChar);
21485 this.errorMsg = this.errors.PwdBadChar;
21488 if (value.length < 6) {
21489 this.markInvalid(this.errors.PwdShort);
21490 this.errorMsg = this.errors.PwdShort;
21493 if (value.length > 16) {
21494 this.markInvalid(this.errors.PwdLong);
21495 this.errorMsg = this.errors.PwdLong;
21499 if (this.ClientSideStrongPassword(value)) {
21501 } else if (this.ClientSideMediumPassword(value)) {
21503 } else if (this.ClientSideWeakPassword(value)) {
21510 if (strength < 2) {
21511 //this.markInvalid(this.errors.TooWeak);
21512 this.errorMsg = this.errors.TooWeak;
21517 console.log('strength2: ' + strength);
21519 //var pm = this.trigger.child('div/div/div').dom;
21521 var pm = this.trigger.child('div/div');
21522 pm.removeClass(this.meterClass);
21523 pm.addClass(this.meterClass[strength]);
21525 var pt = this.trigger.child('/div').child('>*[class=roo-password-meter-text]').dom;
21527 pt.innerHTML = this.meterLabel + ' ' + this.pwdStrengths[strength];
21529 this.errorMsg = '';
21533 CharacterSetChecks: function (type)
21536 this.fResult = false;
21539 isctype: function (character, type)
21542 case this.kCapitalLetter:
21543 if (character >= 'A' && character <= 'Z') {
21548 case this.kSmallLetter:
21549 if (character >= 'a' && character <= 'z') {
21555 if (character >= '0' && character <= '9') {
21560 case this.kPunctuation:
21561 if ('!@#$%^&*()_+-=\'";:[{]}|.>,</?`~'.indexOf(character) >= 0) {
21572 IsLongEnough: function (pwd, size)
21574 return !(pwd == null || isNaN(size) || pwd.length < size);
21577 SpansEnoughCharacterSets: function (word, nb)
21579 if (!this.IsLongEnough(word, nb))
21584 var characterSetChecks = new Array(
21585 new this.CharacterSetChecks(this.kCapitalLetter), new this.CharacterSetChecks(this.kSmallLetter),
21586 new this.CharacterSetChecks(this.kDigit), new this.CharacterSetChecks(this.kPunctuation)
21589 for (var index = 0; index < word.length; ++index) {
21590 for (var nCharSet = 0; nCharSet < characterSetChecks.length; ++nCharSet) {
21591 if (!characterSetChecks[nCharSet].fResult && this.isctype(word.charAt(index), characterSetChecks[nCharSet].type)) {
21592 characterSetChecks[nCharSet].fResult = true;
21599 for (var nCharSet = 0; nCharSet < characterSetChecks.length; ++nCharSet) {
21600 if (characterSetChecks[nCharSet].fResult) {
21605 if (nCharSets < nb) {
21611 ClientSideStrongPassword: function (pwd)
21613 return this.IsLongEnough(pwd, 8) && this.SpansEnoughCharacterSets(pwd, 3);
21616 ClientSideMediumPassword: function (pwd)
21618 return this.IsLongEnough(pwd, 7) && this.SpansEnoughCharacterSets(pwd, 2);
21621 ClientSideWeakPassword: function (pwd)
21623 return this.IsLongEnough(pwd, 6) || !this.IsLongEnough(pwd, 0);
21626 })//<script type="text/javascript">
21629 * Based Ext JS Library 1.1.1
21630 * Copyright(c) 2006-2007, Ext JS, LLC.
21636 * @class Roo.HtmlEditorCore
21637 * @extends Roo.Component
21638 * Provides a the editing component for the HTML editors in Roo. (bootstrap and Roo.form)
21640 * any element that has display set to 'none' can cause problems in Safari and Firefox.<br/><br/>
21643 Roo.HtmlEditorCore = function(config){
21646 Roo.HtmlEditorCore.superclass.constructor.call(this, config);
21651 * @event initialize
21652 * Fires when the editor is fully initialized (including the iframe)
21653 * @param {Roo.HtmlEditorCore} this
21658 * Fires when the editor is first receives the focus. Any insertion must wait
21659 * until after this event.
21660 * @param {Roo.HtmlEditorCore} this
21664 * @event beforesync
21665 * Fires before the textarea is updated with content from the editor iframe. Return false
21666 * to cancel the sync.
21667 * @param {Roo.HtmlEditorCore} this
21668 * @param {String} html
21672 * @event beforepush
21673 * Fires before the iframe editor is updated with content from the textarea. Return false
21674 * to cancel the push.
21675 * @param {Roo.HtmlEditorCore} this
21676 * @param {String} html
21681 * Fires when the textarea is updated with content from the editor iframe.
21682 * @param {Roo.HtmlEditorCore} this
21683 * @param {String} html
21688 * Fires when the iframe editor is updated with content from the textarea.
21689 * @param {Roo.HtmlEditorCore} this
21690 * @param {String} html
21695 * @event editorevent
21696 * Fires when on any editor (mouse up/down cursor movement etc.) - used for toolbar hooks.
21697 * @param {Roo.HtmlEditorCore} this
21703 // at this point this.owner is set, so we can start working out the whitelisted / blacklisted elements
21705 // defaults : white / black...
21706 this.applyBlacklists();
21713 Roo.extend(Roo.HtmlEditorCore, Roo.Component, {
21717 * @cfg {Roo.form.HtmlEditor|Roo.bootstrap.HtmlEditor} the owner field
21723 * @cfg {String} resizable 's' or 'se' or 'e' - wrapps the element in a
21728 * @cfg {Number} height (in pixels)
21732 * @cfg {Number} width (in pixels)
21737 * @cfg {Array} stylesheets url of stylesheets. set to [] to disable stylesheets.
21740 stylesheets: false,
21745 // private properties
21746 validationEvent : false,
21748 initialized : false,
21750 sourceEditMode : false,
21751 onFocus : Roo.emptyFn,
21753 hideMode:'offsets',
21757 // blacklist + whitelisted elements..
21764 * Protected method that will not generally be called directly. It
21765 * is called when the editor initializes the iframe with HTML contents. Override this method if you
21766 * want to change the initialization markup of the iframe (e.g. to add stylesheets).
21768 getDocMarkup : function(){
21772 // inherit styels from page...??
21773 if (this.stylesheets === false) {
21775 Roo.get(document.head).select('style').each(function(node) {
21776 st += node.dom.outerHTML || new XMLSerializer().serializeToString(node.dom);
21779 Roo.get(document.head).select('link').each(function(node) {
21780 st += node.dom.outerHTML || new XMLSerializer().serializeToString(node.dom);
21783 } else if (!this.stylesheets.length) {
21785 st = '<style type="text/css">' +
21786 'body{border:0;margin:0;padding:3px;height:98%;cursor:text;}' +
21789 st = '<style type="text/css">' +
21794 st += '<style type="text/css">' +
21795 'IMG { cursor: pointer } ' +
21798 var cls = 'roo-htmleditor-body';
21800 if(this.bodyCls.length){
21801 cls += ' ' + this.bodyCls;
21804 return '<html><head>' + st +
21805 //<style type="text/css">' +
21806 //'body{border:0;margin:0;padding:3px;height:98%;cursor:text;}' +
21808 ' </head><body class="' + cls + '"></body></html>';
21812 onRender : function(ct, position)
21815 //Roo.HtmlEditorCore.superclass.onRender.call(this, ct, position);
21816 this.el = this.owner.inputEl ? this.owner.inputEl() : this.owner.el;
21819 this.el.dom.style.border = '0 none';
21820 this.el.dom.setAttribute('tabIndex', -1);
21821 this.el.addClass('x-hidden hide');
21825 if(Roo.isIE){ // fix IE 1px bogus margin
21826 this.el.applyStyles('margin-top:-1px;margin-bottom:-1px;')
21830 this.frameId = Roo.id();
21834 var iframe = this.owner.wrap.createChild({
21836 cls: 'form-control', // bootstrap..
21838 name: this.frameId,
21839 frameBorder : 'no',
21840 'src' : Roo.SSL_SECURE_URL ? Roo.SSL_SECURE_URL : "javascript:false"
21845 this.iframe = iframe.dom;
21847 this.assignDocWin();
21849 this.doc.designMode = 'on';
21852 this.doc.write(this.getDocMarkup());
21856 var task = { // must defer to wait for browser to be ready
21858 //console.log("run task?" + this.doc.readyState);
21859 this.assignDocWin();
21860 if(this.doc.body || this.doc.readyState == 'complete'){
21862 this.doc.designMode="on";
21866 Roo.TaskMgr.stop(task);
21867 this.initEditor.defer(10, this);
21874 Roo.TaskMgr.start(task);
21879 onResize : function(w, h)
21881 Roo.log('resize: ' +w + ',' + h );
21882 //Roo.HtmlEditorCore.superclass.onResize.apply(this, arguments);
21886 if(typeof w == 'number'){
21888 this.iframe.style.width = w + 'px';
21890 if(typeof h == 'number'){
21892 this.iframe.style.height = h + 'px';
21894 (this.doc.body || this.doc.documentElement).style.height = (h - (this.iframePad*2)) + 'px';
21901 * Toggles the editor between standard and source edit mode.
21902 * @param {Boolean} sourceEdit (optional) True for source edit, false for standard
21904 toggleSourceEdit : function(sourceEditMode){
21906 this.sourceEditMode = sourceEditMode === true;
21908 if(this.sourceEditMode){
21910 Roo.get(this.iframe).addClass(['x-hidden','hide']); //FIXME - what's the BS styles for these
21913 Roo.get(this.iframe).removeClass(['x-hidden','hide']);
21914 //this.iframe.className = '';
21917 //this.setSize(this.owner.wrap.getSize());
21918 //this.fireEvent('editmodechange', this, this.sourceEditMode);
21925 * Protected method that will not generally be called directly. If you need/want
21926 * custom HTML cleanup, this is the method you should override.
21927 * @param {String} html The HTML to be cleaned
21928 * return {String} The cleaned HTML
21930 cleanHtml : function(html){
21931 html = String(html);
21932 if(html.length > 5){
21933 if(Roo.isSafari){ // strip safari nonsense
21934 html = html.replace(/\sclass="(?:Apple-style-span|khtml-block-placeholder)"/gi, '');
21937 if(html == ' '){
21944 * HTML Editor -> Textarea
21945 * Protected method that will not generally be called directly. Syncs the contents
21946 * of the editor iframe with the textarea.
21948 syncValue : function(){
21949 if(this.initialized){
21950 var bd = (this.doc.body || this.doc.documentElement);
21951 //this.cleanUpPaste(); -- this is done else where and causes havoc..
21952 var html = bd.innerHTML;
21954 var bs = bd.getAttribute('style'); // Safari puts text-align styles on the body element!
21955 var m = bs ? bs.match(/text-align:(.*?);/i) : false;
21957 html = '<div style="'+m[0]+'">' + html + '</div>';
21960 html = this.cleanHtml(html);
21961 // fix up the special chars.. normaly like back quotes in word...
21962 // however we do not want to do this with chinese..
21963 html = html.replace(/([\x80-\uffff])/g, function (a, b) {
21964 var cc = b.charCodeAt();
21966 (cc >= 0x4E00 && cc < 0xA000 ) ||
21967 (cc >= 0x3400 && cc < 0x4E00 ) ||
21968 (cc >= 0xf900 && cc < 0xfb00 )
21974 if(this.owner.fireEvent('beforesync', this, html) !== false){
21975 this.el.dom.value = html;
21976 this.owner.fireEvent('sync', this, html);
21982 * Protected method that will not generally be called directly. Pushes the value of the textarea
21983 * into the iframe editor.
21985 pushValue : function(){
21986 if(this.initialized){
21987 var v = this.el.dom.value.trim();
21989 // if(v.length < 1){
21993 if(this.owner.fireEvent('beforepush', this, v) !== false){
21994 var d = (this.doc.body || this.doc.documentElement);
21996 this.cleanUpPaste();
21997 this.el.dom.value = d.innerHTML;
21998 this.owner.fireEvent('push', this, v);
22004 deferFocus : function(){
22005 this.focus.defer(10, this);
22009 focus : function(){
22010 if(this.win && !this.sourceEditMode){
22017 assignDocWin: function()
22019 var iframe = this.iframe;
22022 this.doc = iframe.contentWindow.document;
22023 this.win = iframe.contentWindow;
22025 // if (!Roo.get(this.frameId)) {
22028 // this.doc = (iframe.contentDocument || Roo.get(this.frameId).dom.document);
22029 // this.win = Roo.get(this.frameId).dom.contentWindow;
22031 if (!Roo.get(this.frameId) && !iframe.contentDocument) {
22035 this.doc = (iframe.contentDocument || Roo.get(this.frameId).dom.document);
22036 this.win = (iframe.contentWindow || Roo.get(this.frameId).dom.contentWindow);
22041 initEditor : function(){
22042 //console.log("INIT EDITOR");
22043 this.assignDocWin();
22047 this.doc.designMode="on";
22049 this.doc.write(this.getDocMarkup());
22052 var dbody = (this.doc.body || this.doc.documentElement);
22053 //var ss = this.el.getStyles('font-size', 'font-family', 'background-image', 'background-repeat');
22054 // this copies styles from the containing element into thsi one..
22055 // not sure why we need all of this..
22056 //var ss = this.el.getStyles('font-size', 'background-image', 'background-repeat');
22058 //var ss = this.el.getStyles( 'background-image', 'background-repeat');
22059 //ss['background-attachment'] = 'fixed'; // w3c
22060 dbody.bgProperties = 'fixed'; // ie
22061 //Roo.DomHelper.applyStyles(dbody, ss);
22062 Roo.EventManager.on(this.doc, {
22063 //'mousedown': this.onEditorEvent,
22064 'mouseup': this.onEditorEvent,
22065 'dblclick': this.onEditorEvent,
22066 'click': this.onEditorEvent,
22067 'keyup': this.onEditorEvent,
22072 Roo.EventManager.on(this.doc, 'keypress', this.mozKeyPress, this);
22074 if(Roo.isIE || Roo.isSafari || Roo.isOpera){
22075 Roo.EventManager.on(this.doc, 'keydown', this.fixKeys, this);
22077 this.initialized = true;
22079 this.owner.fireEvent('initialize', this);
22084 onDestroy : function(){
22090 //for (var i =0; i < this.toolbars.length;i++) {
22091 // // fixme - ask toolbars for heights?
22092 // this.toolbars[i].onDestroy();
22095 //this.wrap.dom.innerHTML = '';
22096 //this.wrap.remove();
22101 onFirstFocus : function(){
22103 this.assignDocWin();
22106 this.activated = true;
22109 if(Roo.isGecko){ // prevent silly gecko errors
22111 var s = this.win.getSelection();
22112 if(!s.focusNode || s.focusNode.nodeType != 3){
22113 var r = s.getRangeAt(0);
22114 r.selectNodeContents((this.doc.body || this.doc.documentElement));
22119 this.execCmd('useCSS', true);
22120 this.execCmd('styleWithCSS', false);
22123 this.owner.fireEvent('activate', this);
22127 adjustFont: function(btn){
22128 var adjust = btn.cmd == 'increasefontsize' ? 1 : -1;
22129 //if(Roo.isSafari){ // safari
22132 var v = parseInt(this.doc.queryCommandValue('FontSize')|| 3, 10);
22133 if(Roo.isSafari){ // safari
22134 var sm = { 10 : 1, 13: 2, 16:3, 18:4, 24: 5, 32:6, 48: 7 };
22135 v = (v < 10) ? 10 : v;
22136 v = (v > 48) ? 48 : v;
22137 v = typeof(sm[v]) == 'undefined' ? 1 : sm[v];
22142 v = Math.max(1, v+adjust);
22144 this.execCmd('FontSize', v );
22147 onEditorEvent : function(e)
22149 this.owner.fireEvent('editorevent', this, e);
22150 // this.updateToolbar();
22151 this.syncValue(); //we can not sync so often.. sync cleans, so this breaks stuff
22154 insertTag : function(tg)
22156 // could be a bit smarter... -> wrap the current selected tRoo..
22157 if (tg.toLowerCase() == 'span' || tg.toLowerCase() == 'code') {
22159 range = this.createRange(this.getSelection());
22160 var wrappingNode = this.doc.createElement(tg.toLowerCase());
22161 wrappingNode.appendChild(range.extractContents());
22162 range.insertNode(wrappingNode);
22169 this.execCmd("formatblock", tg);
22173 insertText : function(txt)
22177 var range = this.createRange();
22178 range.deleteContents();
22179 //alert(Sender.getAttribute('label'));
22181 range.insertNode(this.doc.createTextNode(txt));
22187 * Executes a Midas editor command on the editor document and performs necessary focus and
22188 * toolbar updates. <b>This should only be called after the editor is initialized.</b>
22189 * @param {String} cmd The Midas command
22190 * @param {String/Boolean} value (optional) The value to pass to the command (defaults to null)
22192 relayCmd : function(cmd, value){
22194 this.execCmd(cmd, value);
22195 this.owner.fireEvent('editorevent', this);
22196 //this.updateToolbar();
22197 this.owner.deferFocus();
22201 * Executes a Midas editor command directly on the editor document.
22202 * For visual commands, you should use {@link #relayCmd} instead.
22203 * <b>This should only be called after the editor is initialized.</b>
22204 * @param {String} cmd The Midas command
22205 * @param {String/Boolean} value (optional) The value to pass to the command (defaults to null)
22207 execCmd : function(cmd, value){
22208 this.doc.execCommand(cmd, false, value === undefined ? null : value);
22215 * Inserts the passed text at the current cursor position. Note: the editor must be initialized and activated
22217 * @param {String} text | dom node..
22219 insertAtCursor : function(text)
22222 if(!this.activated){
22228 var r = this.doc.selection.createRange();
22239 if(Roo.isGecko || Roo.isOpera || Roo.isSafari){
22243 // from jquery ui (MIT licenced)
22245 var win = this.win;
22247 if (win.getSelection && win.getSelection().getRangeAt) {
22248 range = win.getSelection().getRangeAt(0);
22249 node = typeof(text) == 'string' ? range.createContextualFragment(text) : text;
22250 range.insertNode(node);
22251 } else if (win.document.selection && win.document.selection.createRange) {
22252 // no firefox support
22253 var txt = typeof(text) == 'string' ? text : text.outerHTML;
22254 win.document.selection.createRange().pasteHTML(txt);
22256 // no firefox support
22257 var txt = typeof(text) == 'string' ? text : text.outerHTML;
22258 this.execCmd('InsertHTML', txt);
22267 mozKeyPress : function(e){
22269 var c = e.getCharCode(), cmd;
22272 c = String.fromCharCode(c).toLowerCase();
22286 this.cleanUpPaste.defer(100, this);
22294 e.preventDefault();
22302 fixKeys : function(){ // load time branching for fastest keydown performance
22304 return function(e){
22305 var k = e.getKey(), r;
22308 r = this.doc.selection.createRange();
22311 r.pasteHTML('    ');
22318 r = this.doc.selection.createRange();
22320 var target = r.parentElement();
22321 if(!target || target.tagName.toLowerCase() != 'li'){
22323 r.pasteHTML('<br />');
22329 if (String.fromCharCode(k).toLowerCase() == 'v') { // paste
22330 this.cleanUpPaste.defer(100, this);
22336 }else if(Roo.isOpera){
22337 return function(e){
22338 var k = e.getKey();
22342 this.execCmd('InsertHTML','    ');
22345 if (String.fromCharCode(k).toLowerCase() == 'v') { // paste
22346 this.cleanUpPaste.defer(100, this);
22351 }else if(Roo.isSafari){
22352 return function(e){
22353 var k = e.getKey();
22357 this.execCmd('InsertText','\t');
22361 if (String.fromCharCode(k).toLowerCase() == 'v') { // paste
22362 this.cleanUpPaste.defer(100, this);
22370 getAllAncestors: function()
22372 var p = this.getSelectedNode();
22375 a.push(p); // push blank onto stack..
22376 p = this.getParentElement();
22380 while (p && (p.nodeType == 1) && (p.tagName.toLowerCase() != 'body')) {
22384 a.push(this.doc.body);
22388 lastSelNode : false,
22391 getSelection : function()
22393 this.assignDocWin();
22394 return Roo.isIE ? this.doc.selection : this.win.getSelection();
22397 getSelectedNode: function()
22399 // this may only work on Gecko!!!
22401 // should we cache this!!!!
22406 var range = this.createRange(this.getSelection()).cloneRange();
22409 var parent = range.parentElement();
22411 var testRange = range.duplicate();
22412 testRange.moveToElementText(parent);
22413 if (testRange.inRange(range)) {
22416 if ((parent.nodeType != 1) || (parent.tagName.toLowerCase() == 'body')) {
22419 parent = parent.parentElement;
22424 // is ancestor a text element.
22425 var ac = range.commonAncestorContainer;
22426 if (ac.nodeType == 3) {
22427 ac = ac.parentNode;
22430 var ar = ac.childNodes;
22433 var other_nodes = [];
22434 var has_other_nodes = false;
22435 for (var i=0;i<ar.length;i++) {
22436 if ((ar[i].nodeType == 3) && (!ar[i].data.length)) { // empty text ?
22439 // fullly contained node.
22441 if (this.rangeIntersectsNode(range,ar[i]) && this.rangeCompareNode(range,ar[i]) == 3) {
22446 // probably selected..
22447 if ((ar[i].nodeType == 1) && this.rangeIntersectsNode(range,ar[i]) && (this.rangeCompareNode(range,ar[i]) > 0)) {
22448 other_nodes.push(ar[i]);
22452 if (!this.rangeIntersectsNode(range,ar[i])|| (this.rangeCompareNode(range,ar[i]) == 0)) {
22457 has_other_nodes = true;
22459 if (!nodes.length && other_nodes.length) {
22460 nodes= other_nodes;
22462 if (has_other_nodes || !nodes.length || (nodes.length > 1)) {
22468 createRange: function(sel)
22470 // this has strange effects when using with
22471 // top toolbar - not sure if it's a great idea.
22472 //this.editor.contentWindow.focus();
22473 if (typeof sel != "undefined") {
22475 return sel.getRangeAt ? sel.getRangeAt(0) : sel.createRange();
22477 return this.doc.createRange();
22480 return this.doc.createRange();
22483 getParentElement: function()
22486 this.assignDocWin();
22487 var sel = Roo.isIE ? this.doc.selection : this.win.getSelection();
22489 var range = this.createRange(sel);
22492 var p = range.commonAncestorContainer;
22493 while (p.nodeType == 3) { // text node
22504 * Range intersection.. the hard stuff...
22508 * [ -- selected range --- ]
22512 * if end is before start or hits it. fail.
22513 * if start is after end or hits it fail.
22515 * if either hits (but other is outside. - then it's not
22521 // @see http://www.thismuchiknow.co.uk/?p=64.
22522 rangeIntersectsNode : function(range, node)
22524 var nodeRange = node.ownerDocument.createRange();
22526 nodeRange.selectNode(node);
22528 nodeRange.selectNodeContents(node);
22531 var rangeStartRange = range.cloneRange();
22532 rangeStartRange.collapse(true);
22534 var rangeEndRange = range.cloneRange();
22535 rangeEndRange.collapse(false);
22537 var nodeStartRange = nodeRange.cloneRange();
22538 nodeStartRange.collapse(true);
22540 var nodeEndRange = nodeRange.cloneRange();
22541 nodeEndRange.collapse(false);
22543 return rangeStartRange.compareBoundaryPoints(
22544 Range.START_TO_START, nodeEndRange) == -1 &&
22545 rangeEndRange.compareBoundaryPoints(
22546 Range.START_TO_START, nodeStartRange) == 1;
22550 rangeCompareNode : function(range, node)
22552 var nodeRange = node.ownerDocument.createRange();
22554 nodeRange.selectNode(node);
22556 nodeRange.selectNodeContents(node);
22560 range.collapse(true);
22562 nodeRange.collapse(true);
22564 var ss = range.compareBoundaryPoints( Range.START_TO_START, nodeRange);
22565 var ee = range.compareBoundaryPoints( Range.END_TO_END, nodeRange);
22567 //Roo.log(node.tagName + ': ss='+ss +', ee='+ee)
22569 var nodeIsBefore = ss == 1;
22570 var nodeIsAfter = ee == -1;
22572 if (nodeIsBefore && nodeIsAfter) {
22575 if (!nodeIsBefore && nodeIsAfter) {
22576 return 1; //right trailed.
22579 if (nodeIsBefore && !nodeIsAfter) {
22580 return 2; // left trailed.
22586 // private? - in a new class?
22587 cleanUpPaste : function()
22589 // cleans up the whole document..
22590 Roo.log('cleanuppaste');
22592 this.cleanUpChildren(this.doc.body);
22593 var clean = this.cleanWordChars(this.doc.body.innerHTML);
22594 if (clean != this.doc.body.innerHTML) {
22595 this.doc.body.innerHTML = clean;
22600 cleanWordChars : function(input) {// change the chars to hex code
22601 var he = Roo.HtmlEditorCore;
22603 var output = input;
22604 Roo.each(he.swapCodes, function(sw) {
22605 var swapper = new RegExp("\\u" + sw[0].toString(16), "g"); // hex codes
22607 output = output.replace(swapper, sw[1]);
22614 cleanUpChildren : function (n)
22616 if (!n.childNodes.length) {
22619 for (var i = n.childNodes.length-1; i > -1 ; i--) {
22620 this.cleanUpChild(n.childNodes[i]);
22627 cleanUpChild : function (node)
22630 //console.log(node);
22631 if (node.nodeName == "#text") {
22632 // clean up silly Windows -- stuff?
22635 if (node.nodeName == "#comment") {
22636 node.parentNode.removeChild(node);
22637 // clean up silly Windows -- stuff?
22640 var lcname = node.tagName.toLowerCase();
22641 // we ignore whitelists... ?? = not really the way to go, but we probably have not got a full
22642 // whitelist of tags..
22644 if (this.black.indexOf(lcname) > -1 && this.clearUp ) {
22646 node.parentNode.removeChild(node);
22651 var remove_keep_children= Roo.HtmlEditorCore.remove.indexOf(node.tagName.toLowerCase()) > -1;
22653 // remove <a name=....> as rendering on yahoo mailer is borked with this.
22654 // this will have to be flaged elsewhere - perhaps ablack=name... on the mailer..
22656 //if (node.tagName.toLowerCase() == 'a' && !node.hasAttribute('href')) {
22657 // remove_keep_children = true;
22660 if (remove_keep_children) {
22661 this.cleanUpChildren(node);
22662 // inserts everything just before this node...
22663 while (node.childNodes.length) {
22664 var cn = node.childNodes[0];
22665 node.removeChild(cn);
22666 node.parentNode.insertBefore(cn, node);
22668 node.parentNode.removeChild(node);
22672 if (!node.attributes || !node.attributes.length) {
22673 this.cleanUpChildren(node);
22677 function cleanAttr(n,v)
22680 if (v.match(/^\./) || v.match(/^\//)) {
22683 if (v.match(/^(http|https):\/\//) || v.match(/^mailto:/) || v.match(/^ftp:/)) {
22686 if (v.match(/^#/)) {
22689 // Roo.log("(REMOVE TAG)"+ node.tagName +'.' + n + '=' + v);
22690 node.removeAttribute(n);
22694 var cwhite = this.cwhite;
22695 var cblack = this.cblack;
22697 function cleanStyle(n,v)
22699 if (v.match(/expression/)) { //XSS?? should we even bother..
22700 node.removeAttribute(n);
22704 var parts = v.split(/;/);
22707 Roo.each(parts, function(p) {
22708 p = p.replace(/^\s+/g,'').replace(/\s+$/g,'');
22712 var l = p.split(':').shift().replace(/\s+/g,'');
22713 l = l.replace(/^\s+/g,'').replace(/\s+$/g,'');
22715 if ( cwhite.length && cblack.indexOf(l) > -1) {
22716 // Roo.log('(REMOVE CSS)' + node.tagName +'.' + n + ':'+l + '=' + v);
22717 //node.removeAttribute(n);
22721 // only allow 'c whitelisted system attributes'
22722 if ( cwhite.length && cwhite.indexOf(l) < 0) {
22723 // Roo.log('(REMOVE CSS)' + node.tagName +'.' + n + ':'+l + '=' + v);
22724 //node.removeAttribute(n);
22734 if (clean.length) {
22735 node.setAttribute(n, clean.join(';'));
22737 node.removeAttribute(n);
22743 for (var i = node.attributes.length-1; i > -1 ; i--) {
22744 var a = node.attributes[i];
22747 if (a.name.toLowerCase().substr(0,2)=='on') {
22748 node.removeAttribute(a.name);
22751 if (Roo.HtmlEditorCore.ablack.indexOf(a.name.toLowerCase()) > -1) {
22752 node.removeAttribute(a.name);
22755 if (Roo.HtmlEditorCore.aclean.indexOf(a.name.toLowerCase()) > -1) {
22756 cleanAttr(a.name,a.value); // fixme..
22759 if (a.name == 'style') {
22760 cleanStyle(a.name,a.value);
22763 /// clean up MS crap..
22764 // tecnically this should be a list of valid class'es..
22767 if (a.name == 'class') {
22768 if (a.value.match(/^Mso/)) {
22769 node.className = '';
22772 if (a.value.match(/^body$/)) {
22773 node.className = '';
22784 this.cleanUpChildren(node);
22790 * Clean up MS wordisms...
22792 cleanWord : function(node)
22797 this.cleanWord(this.doc.body);
22800 if (node.nodeName == "#text") {
22801 // clean up silly Windows -- stuff?
22804 if (node.nodeName == "#comment") {
22805 node.parentNode.removeChild(node);
22806 // clean up silly Windows -- stuff?
22810 if (node.tagName.toLowerCase().match(/^(style|script|applet|embed|noframes|noscript)$/)) {
22811 node.parentNode.removeChild(node);
22815 // remove - but keep children..
22816 if (node.tagName.toLowerCase().match(/^(meta|link|\\?xml:|st1:|o:|font)/)) {
22817 while (node.childNodes.length) {
22818 var cn = node.childNodes[0];
22819 node.removeChild(cn);
22820 node.parentNode.insertBefore(cn, node);
22822 node.parentNode.removeChild(node);
22823 this.iterateChildren(node, this.cleanWord);
22827 if (node.className.length) {
22829 var cn = node.className.split(/\W+/);
22831 Roo.each(cn, function(cls) {
22832 if (cls.match(/Mso[a-zA-Z]+/)) {
22837 node.className = cna.length ? cna.join(' ') : '';
22839 node.removeAttribute("class");
22843 if (node.hasAttribute("lang")) {
22844 node.removeAttribute("lang");
22847 if (node.hasAttribute("style")) {
22849 var styles = node.getAttribute("style").split(";");
22851 Roo.each(styles, function(s) {
22852 if (!s.match(/:/)) {
22855 var kv = s.split(":");
22856 if (kv[0].match(/^(mso-|line|font|background|margin|padding|color)/)) {
22859 // what ever is left... we allow.
22862 node.setAttribute("style", nstyle.length ? nstyle.join(';') : '');
22863 if (!nstyle.length) {
22864 node.removeAttribute('style');
22867 this.iterateChildren(node, this.cleanWord);
22873 * iterateChildren of a Node, calling fn each time, using this as the scole..
22874 * @param {DomNode} node node to iterate children of.
22875 * @param {Function} fn method of this class to call on each item.
22877 iterateChildren : function(node, fn)
22879 if (!node.childNodes.length) {
22882 for (var i = node.childNodes.length-1; i > -1 ; i--) {
22883 fn.call(this, node.childNodes[i])
22889 * cleanTableWidths.
22891 * Quite often pasting from word etc.. results in tables with column and widths.
22892 * This does not work well on fluid HTML layouts - like emails. - so this code should hunt an destroy them..
22895 cleanTableWidths : function(node)
22900 this.cleanTableWidths(this.doc.body);
22905 if (node.nodeName == "#text" || node.nodeName == "#comment") {
22908 Roo.log(node.tagName);
22909 if (!node.tagName.toLowerCase().match(/^(table|td|tr)$/)) {
22910 this.iterateChildren(node, this.cleanTableWidths);
22913 if (node.hasAttribute('width')) {
22914 node.removeAttribute('width');
22918 if (node.hasAttribute("style")) {
22921 var styles = node.getAttribute("style").split(";");
22923 Roo.each(styles, function(s) {
22924 if (!s.match(/:/)) {
22927 var kv = s.split(":");
22928 if (kv[0].match(/^\s*(width|min-width)\s*$/)) {
22931 // what ever is left... we allow.
22934 node.setAttribute("style", nstyle.length ? nstyle.join(';') : '');
22935 if (!nstyle.length) {
22936 node.removeAttribute('style');
22940 this.iterateChildren(node, this.cleanTableWidths);
22948 domToHTML : function(currentElement, depth, nopadtext) {
22950 depth = depth || 0;
22951 nopadtext = nopadtext || false;
22953 if (!currentElement) {
22954 return this.domToHTML(this.doc.body);
22957 //Roo.log(currentElement);
22959 var allText = false;
22960 var nodeName = currentElement.nodeName;
22961 var tagName = Roo.util.Format.htmlEncode(currentElement.tagName);
22963 if (nodeName == '#text') {
22965 return nopadtext ? currentElement.nodeValue : currentElement.nodeValue.trim();
22970 if (nodeName != 'BODY') {
22973 // Prints the node tagName, such as <A>, <IMG>, etc
22976 for(i = 0; i < currentElement.attributes.length;i++) {
22978 var aname = currentElement.attributes.item(i).name;
22979 if (!currentElement.attributes.item(i).value.length) {
22982 attr.push(aname + '="' + Roo.util.Format.htmlEncode(currentElement.attributes.item(i).value) + '"' );
22985 ret = "<"+currentElement.tagName+ ( attr.length ? (' ' + attr.join(' ') ) : '') + ">";
22994 if (['IMG', 'BR', 'HR', 'INPUT'].indexOf(tagName) > -1) {
22997 if (['PRE', 'TEXTAREA', 'TD', 'A', 'SPAN'].indexOf(tagName) > -1) { // or code?
23002 // Traverse the tree
23004 var currentElementChild = currentElement.childNodes.item(i);
23005 var allText = true;
23006 var innerHTML = '';
23008 while (currentElementChild) {
23009 // Formatting code (indent the tree so it looks nice on the screen)
23010 var nopad = nopadtext;
23011 if (lastnode == 'SPAN') {
23015 if (currentElementChild.nodeName == '#text') {
23016 var toadd = Roo.util.Format.htmlEncode(currentElementChild.nodeValue);
23017 toadd = nopadtext ? toadd : toadd.trim();
23018 if (!nopad && toadd.length > 80) {
23019 innerHTML += "\n" + (new Array( depth + 1 )).join( " " );
23021 innerHTML += toadd;
23024 currentElementChild = currentElement.childNodes.item(i);
23030 innerHTML += nopad ? '' : "\n" + (new Array( depth + 1 )).join( " " );
23032 // Recursively traverse the tree structure of the child node
23033 innerHTML += this.domToHTML(currentElementChild, depth+1, nopadtext);
23034 lastnode = currentElementChild.nodeName;
23036 currentElementChild=currentElement.childNodes.item(i);
23042 // The remaining code is mostly for formatting the tree
23043 ret+= nopadtext ? '' : "\n" + (new Array( depth )).join( " " );
23048 ret+= "</"+tagName+">";
23054 applyBlacklists : function()
23056 var w = typeof(this.owner.white) != 'undefined' && this.owner.white ? this.owner.white : [];
23057 var b = typeof(this.owner.black) != 'undefined' && this.owner.black ? this.owner.black : [];
23061 Roo.each(Roo.HtmlEditorCore.white, function(tag) {
23062 if (b.indexOf(tag) > -1) {
23065 this.white.push(tag);
23069 Roo.each(w, function(tag) {
23070 if (b.indexOf(tag) > -1) {
23073 if (this.white.indexOf(tag) > -1) {
23076 this.white.push(tag);
23081 Roo.each(Roo.HtmlEditorCore.black, function(tag) {
23082 if (w.indexOf(tag) > -1) {
23085 this.black.push(tag);
23089 Roo.each(b, function(tag) {
23090 if (w.indexOf(tag) > -1) {
23093 if (this.black.indexOf(tag) > -1) {
23096 this.black.push(tag);
23101 w = typeof(this.owner.cwhite) != 'undefined' && this.owner.cwhite ? this.owner.cwhite : [];
23102 b = typeof(this.owner.cblack) != 'undefined' && this.owner.cblack ? this.owner.cblack : [];
23106 Roo.each(Roo.HtmlEditorCore.cwhite, function(tag) {
23107 if (b.indexOf(tag) > -1) {
23110 this.cwhite.push(tag);
23114 Roo.each(w, function(tag) {
23115 if (b.indexOf(tag) > -1) {
23118 if (this.cwhite.indexOf(tag) > -1) {
23121 this.cwhite.push(tag);
23126 Roo.each(Roo.HtmlEditorCore.cblack, function(tag) {
23127 if (w.indexOf(tag) > -1) {
23130 this.cblack.push(tag);
23134 Roo.each(b, function(tag) {
23135 if (w.indexOf(tag) > -1) {
23138 if (this.cblack.indexOf(tag) > -1) {
23141 this.cblack.push(tag);
23146 setStylesheets : function(stylesheets)
23148 if(typeof(stylesheets) == 'string'){
23149 Roo.get(this.iframe.contentDocument.head).createChild({
23151 rel : 'stylesheet',
23160 Roo.each(stylesheets, function(s) {
23165 Roo.get(_this.iframe.contentDocument.head).createChild({
23167 rel : 'stylesheet',
23176 removeStylesheets : function()
23180 Roo.each(Roo.get(_this.iframe.contentDocument.head).select('link[rel=stylesheet]', true).elements, function(s){
23185 setStyle : function(style)
23187 Roo.get(this.iframe.contentDocument.head).createChild({
23196 // hide stuff that is not compatible
23210 * @event specialkey
23214 * @cfg {String} fieldClass @hide
23217 * @cfg {String} focusClass @hide
23220 * @cfg {String} autoCreate @hide
23223 * @cfg {String} inputType @hide
23226 * @cfg {String} invalidClass @hide
23229 * @cfg {String} invalidText @hide
23232 * @cfg {String} msgFx @hide
23235 * @cfg {String} validateOnBlur @hide
23239 Roo.HtmlEditorCore.white = [
23240 'area', 'br', 'img', 'input', 'hr', 'wbr',
23242 'address', 'blockquote', 'center', 'dd', 'dir', 'div',
23243 'dl', 'dt', 'h1', 'h2', 'h3', 'h4',
23244 'h5', 'h6', 'hr', 'isindex', 'listing', 'marquee',
23245 'menu', 'multicol', 'ol', 'p', 'plaintext', 'pre',
23246 'table', 'ul', 'xmp',
23248 'caption', 'col', 'colgroup', 'tbody', 'td', 'tfoot', 'th',
23251 'dir', 'menu', 'ol', 'ul', 'dl',
23257 Roo.HtmlEditorCore.black = [
23258 // 'embed', 'object', // enable - backend responsiblity to clean thiese
23260 'base', 'basefont', 'bgsound', 'blink', 'body',
23261 'frame', 'frameset', 'head', 'html', 'ilayer',
23262 'iframe', 'layer', 'link', 'meta', 'object',
23263 'script', 'style' ,'title', 'xml' // clean later..
23265 Roo.HtmlEditorCore.clean = [
23266 'script', 'style', 'title', 'xml'
23268 Roo.HtmlEditorCore.remove = [
23273 Roo.HtmlEditorCore.ablack = [
23277 Roo.HtmlEditorCore.aclean = [
23278 'action', 'background', 'codebase', 'dynsrc', 'href', 'lowsrc'
23282 Roo.HtmlEditorCore.pwhite= [
23283 'http', 'https', 'mailto'
23286 // white listed style attributes.
23287 Roo.HtmlEditorCore.cwhite= [
23288 // 'text-align', /// default is to allow most things..
23294 // black listed style attributes.
23295 Roo.HtmlEditorCore.cblack= [
23296 // 'font-size' -- this can be set by the project
23300 Roo.HtmlEditorCore.swapCodes =[
23319 * @class Roo.bootstrap.HtmlEditor
23320 * @extends Roo.bootstrap.TextArea
23321 * Bootstrap HtmlEditor class
23324 * Create a new HtmlEditor
23325 * @param {Object} config The config object
23328 Roo.bootstrap.HtmlEditor = function(config){
23329 Roo.bootstrap.HtmlEditor.superclass.constructor.call(this, config);
23330 if (!this.toolbars) {
23331 this.toolbars = [];
23334 this.editorcore = new Roo.HtmlEditorCore(Roo.apply({ owner : this} , config));
23337 * @event initialize
23338 * Fires when the editor is fully initialized (including the iframe)
23339 * @param {HtmlEditor} this
23344 * Fires when the editor is first receives the focus. Any insertion must wait
23345 * until after this event.
23346 * @param {HtmlEditor} this
23350 * @event beforesync
23351 * Fires before the textarea is updated with content from the editor iframe. Return false
23352 * to cancel the sync.
23353 * @param {HtmlEditor} this
23354 * @param {String} html
23358 * @event beforepush
23359 * Fires before the iframe editor is updated with content from the textarea. Return false
23360 * to cancel the push.
23361 * @param {HtmlEditor} this
23362 * @param {String} html
23367 * Fires when the textarea is updated with content from the editor iframe.
23368 * @param {HtmlEditor} this
23369 * @param {String} html
23374 * Fires when the iframe editor is updated with content from the textarea.
23375 * @param {HtmlEditor} this
23376 * @param {String} html
23380 * @event editmodechange
23381 * Fires when the editor switches edit modes
23382 * @param {HtmlEditor} this
23383 * @param {Boolean} sourceEdit True if source edit, false if standard editing.
23385 editmodechange: true,
23387 * @event editorevent
23388 * Fires when on any editor (mouse up/down cursor movement etc.) - used for toolbar hooks.
23389 * @param {HtmlEditor} this
23393 * @event firstfocus
23394 * Fires when on first focus - needed by toolbars..
23395 * @param {HtmlEditor} this
23400 * Auto save the htmlEditor value as a file into Events
23401 * @param {HtmlEditor} this
23405 * @event savedpreview
23406 * preview the saved version of htmlEditor
23407 * @param {HtmlEditor} this
23414 Roo.extend(Roo.bootstrap.HtmlEditor, Roo.bootstrap.TextArea, {
23418 * @cfg {Array} toolbars Array of toolbars. - defaults to just the Standard one
23423 * @cfg {Array} buttons Array of toolbar's buttons. - defaults to empty
23428 * @cfg {String} resizable 's' or 'se' or 'e' - wrapps the element in a
23433 * @cfg {Number} height (in pixels)
23437 * @cfg {Number} width (in pixels)
23442 * @cfg {Array} stylesheets url of stylesheets. set to [] to disable stylesheets.
23445 stylesheets: false,
23450 // private properties
23451 validationEvent : false,
23453 initialized : false,
23456 onFocus : Roo.emptyFn,
23458 hideMode:'offsets',
23460 tbContainer : false,
23464 toolbarContainer :function() {
23465 return this.wrap.select('.x-html-editor-tb',true).first();
23469 * Protected method that will not generally be called directly. It
23470 * is called when the editor creates its toolbar. Override this method if you need to
23471 * add custom toolbar buttons.
23472 * @param {HtmlEditor} editor
23474 createToolbar : function(){
23475 Roo.log('renewing');
23476 Roo.log("create toolbars");
23478 this.toolbars = [ new Roo.bootstrap.htmleditor.ToolbarStandard({editor: this} ) ];
23479 this.toolbars[0].render(this.toolbarContainer());
23483 // if (!editor.toolbars || !editor.toolbars.length) {
23484 // editor.toolbars = [ new Roo.bootstrap.HtmlEditor.ToolbarStandard() ]; // can be empty?
23487 // for (var i =0 ; i < editor.toolbars.length;i++) {
23488 // editor.toolbars[i] = Roo.factory(
23489 // typeof(editor.toolbars[i]) == 'string' ?
23490 // { xtype: editor.toolbars[i]} : editor.toolbars[i],
23491 // Roo.bootstrap.HtmlEditor);
23492 // editor.toolbars[i].init(editor);
23498 onRender : function(ct, position)
23500 // Roo.log("Call onRender: " + this.xtype);
23502 Roo.bootstrap.HtmlEditor.superclass.onRender.call(this, ct, position);
23504 this.wrap = this.inputEl().wrap({
23505 cls:'x-html-editor-wrap', cn:{cls:'x-html-editor-tb'}
23508 this.editorcore.onRender(ct, position);
23510 if (this.resizable) {
23511 this.resizeEl = new Roo.Resizable(this.wrap, {
23515 minHeight : this.height,
23516 height: this.height,
23517 handles : this.resizable,
23520 resize : function(r, w, h) {
23521 _t.onResize(w,h); // -something
23527 this.createToolbar(this);
23530 if(!this.width && this.resizable){
23531 this.setSize(this.wrap.getSize());
23533 if (this.resizeEl) {
23534 this.resizeEl.resizeTo.defer(100, this.resizeEl,[ this.width,this.height ] );
23535 // should trigger onReize..
23541 onResize : function(w, h)
23543 Roo.log('resize: ' +w + ',' + h );
23544 Roo.bootstrap.HtmlEditor.superclass.onResize.apply(this, arguments);
23548 if(this.inputEl() ){
23549 if(typeof w == 'number'){
23550 var aw = w - this.wrap.getFrameWidth('lr');
23551 this.inputEl().setWidth(this.adjustWidth('textarea', aw));
23554 if(typeof h == 'number'){
23555 var tbh = -11; // fixme it needs to tool bar size!
23556 for (var i =0; i < this.toolbars.length;i++) {
23557 // fixme - ask toolbars for heights?
23558 tbh += this.toolbars[i].el.getHeight();
23559 //if (this.toolbars[i].footer) {
23560 // tbh += this.toolbars[i].footer.el.getHeight();
23568 var ah = h - this.wrap.getFrameWidth('tb') - tbh;// this.tb.el.getHeight();
23569 ah -= 5; // knock a few pixes off for look..
23570 this.inputEl().setHeight(this.adjustWidth('textarea', ah));
23574 Roo.log('onResize:' + [w,h,ew,eh].join(',') );
23575 this.editorcore.onResize(ew,eh);
23580 * Toggles the editor between standard and source edit mode.
23581 * @param {Boolean} sourceEdit (optional) True for source edit, false for standard
23583 toggleSourceEdit : function(sourceEditMode)
23585 this.editorcore.toggleSourceEdit(sourceEditMode);
23587 if(this.editorcore.sourceEditMode){
23588 Roo.log('editor - showing textarea');
23591 // Roo.log(this.syncValue());
23593 this.inputEl().removeClass(['hide', 'x-hidden']);
23594 this.inputEl().dom.removeAttribute('tabIndex');
23595 this.inputEl().focus();
23597 Roo.log('editor - hiding textarea');
23599 // Roo.log(this.pushValue());
23602 this.inputEl().addClass(['hide', 'x-hidden']);
23603 this.inputEl().dom.setAttribute('tabIndex', -1);
23604 //this.deferFocus();
23607 if(this.resizable){
23608 this.setSize(this.wrap.getSize());
23611 this.fireEvent('editmodechange', this, this.editorcore.sourceEditMode);
23614 // private (for BoxComponent)
23615 adjustSize : Roo.BoxComponent.prototype.adjustSize,
23617 // private (for BoxComponent)
23618 getResizeEl : function(){
23622 // private (for BoxComponent)
23623 getPositionEl : function(){
23628 initEvents : function(){
23629 this.originalValue = this.getValue();
23633 // * Overridden and disabled. The editor element does not support standard valid/invalid marking. @hide
23636 // markInvalid : Roo.emptyFn,
23638 // * Overridden and disabled. The editor element does not support standard valid/invalid marking. @hide
23641 // clearInvalid : Roo.emptyFn,
23643 setValue : function(v){
23644 Roo.bootstrap.HtmlEditor.superclass.setValue.call(this, v);
23645 this.editorcore.pushValue();
23650 deferFocus : function(){
23651 this.focus.defer(10, this);
23655 focus : function(){
23656 this.editorcore.focus();
23662 onDestroy : function(){
23668 for (var i =0; i < this.toolbars.length;i++) {
23669 // fixme - ask toolbars for heights?
23670 this.toolbars[i].onDestroy();
23673 this.wrap.dom.innerHTML = '';
23674 this.wrap.remove();
23679 onFirstFocus : function(){
23680 //Roo.log("onFirstFocus");
23681 this.editorcore.onFirstFocus();
23682 for (var i =0; i < this.toolbars.length;i++) {
23683 this.toolbars[i].onFirstFocus();
23689 syncValue : function()
23691 this.editorcore.syncValue();
23694 pushValue : function()
23696 this.editorcore.pushValue();
23700 // hide stuff that is not compatible
23714 * @event specialkey
23718 * @cfg {String} fieldClass @hide
23721 * @cfg {String} focusClass @hide
23724 * @cfg {String} autoCreate @hide
23727 * @cfg {String} inputType @hide
23730 * @cfg {String} invalidClass @hide
23733 * @cfg {String} invalidText @hide
23736 * @cfg {String} msgFx @hide
23739 * @cfg {String} validateOnBlur @hide
23748 Roo.namespace('Roo.bootstrap.htmleditor');
23750 * @class Roo.bootstrap.HtmlEditorToolbar1
23755 new Roo.bootstrap.HtmlEditor({
23758 new Roo.bootstrap.HtmlEditorToolbar1({
23759 disable : { fonts: 1 , format: 1, ..., ... , ...],
23765 * @cfg {Object} disable List of elements to disable..
23766 * @cfg {Array} btns List of additional buttons.
23770 * .x-html-editor-tb .x-edit-none .x-btn-text { background: none; }
23773 Roo.bootstrap.htmleditor.ToolbarStandard = function(config)
23776 Roo.apply(this, config);
23778 // default disabled, based on 'good practice'..
23779 this.disable = this.disable || {};
23780 Roo.applyIf(this.disable, {
23783 specialElements : true
23785 Roo.bootstrap.htmleditor.ToolbarStandard.superclass.constructor.call(this, config);
23787 this.editor = config.editor;
23788 this.editorcore = config.editor.editorcore;
23790 this.buttons = new Roo.util.MixedCollection(false, function(o) { return o.cmd; });
23792 //Roo.form.HtmlEditorToolbar1.superclass.constructor.call(this, editor.wrap.dom.firstChild, [], config);
23793 // dont call parent... till later.
23795 Roo.extend(Roo.bootstrap.htmleditor.ToolbarStandard, Roo.bootstrap.NavSimplebar, {
23800 editorcore : false,
23805 "h1","h2","h3","h4","h5","h6",
23807 "abbr", "acronym", "address", "cite", "samp", "var",
23811 onRender : function(ct, position)
23813 // Roo.log("Call onRender: " + this.xtype);
23815 Roo.bootstrap.htmleditor.ToolbarStandard.superclass.onRender.call(this, ct, position);
23817 this.el.dom.style.marginBottom = '0';
23819 var editorcore = this.editorcore;
23820 var editor= this.editor;
23823 var btn = function(id,cmd , toggle, handler, html){
23825 var event = toggle ? 'toggle' : 'click';
23830 xns: Roo.bootstrap,
23833 enableToggle:toggle !== false,
23835 pressed : toggle ? false : null,
23838 a.listeners[toggle ? 'toggle' : 'click'] = function() {
23839 handler ? handler.call(_this,this) :_this.onBtnClick.call(_this, cmd || id);
23845 // var cb_box = function...
23850 xns: Roo.bootstrap,
23851 glyphicon : 'font',
23855 xns: Roo.bootstrap,
23859 Roo.each(this.formats, function(f) {
23860 style.menu.items.push({
23862 xns: Roo.bootstrap,
23863 html : '<'+ f+' style="margin:2px">'+f +'</'+ f+'>',
23868 editorcore.insertTag(this.tagname);
23875 children.push(style);
23877 btn('bold',false,true);
23878 btn('italic',false,true);
23879 btn('align-left', 'justifyleft',true);
23880 btn('align-center', 'justifycenter',true);
23881 btn('align-right' , 'justifyright',true);
23882 btn('link', false, false, function(btn) {
23883 //Roo.log("create link?");
23884 var url = prompt(this.createLinkText, this.defaultLinkValue);
23885 if(url && url != 'http:/'+'/'){
23886 this.editorcore.relayCmd('createlink', url);
23889 btn('list','insertunorderedlist',true);
23890 btn('pencil', false,true, function(btn){
23892 this.toggleSourceEdit(btn.pressed);
23895 if (this.editor.btns.length > 0) {
23896 for (var i = 0; i<this.editor.btns.length; i++) {
23897 children.push(this.editor.btns[i]);
23905 xns: Roo.bootstrap,
23910 xns: Roo.bootstrap,
23915 cog.menu.items.push({
23917 xns: Roo.bootstrap,
23918 html : Clean styles,
23923 editorcore.insertTag(this.tagname);
23932 this.xtype = 'NavSimplebar';
23934 for(var i=0;i< children.length;i++) {
23936 this.buttons.add(this.addxtypeChild(children[i]));
23940 editor.on('editorevent', this.updateToolbar, this);
23942 onBtnClick : function(id)
23944 this.editorcore.relayCmd(id);
23945 this.editorcore.focus();
23949 * Protected method that will not generally be called directly. It triggers
23950 * a toolbar update by reading the markup state of the current selection in the editor.
23952 updateToolbar: function(){
23954 if(!this.editorcore.activated){
23955 this.editor.onFirstFocus(); // is this neeed?
23959 var btns = this.buttons;
23960 var doc = this.editorcore.doc;
23961 btns.get('bold').setActive(doc.queryCommandState('bold'));
23962 btns.get('italic').setActive(doc.queryCommandState('italic'));
23963 //btns.get('underline').setActive(doc.queryCommandState('underline'));
23965 btns.get('align-left').setActive(doc.queryCommandState('justifyleft'));
23966 btns.get('align-center').setActive(doc.queryCommandState('justifycenter'));
23967 btns.get('align-right').setActive(doc.queryCommandState('justifyright'));
23969 //btns[frameId + '-insertorderedlist').setActive(doc.queryCommandState('insertorderedlist'));
23970 btns.get('list').setActive(doc.queryCommandState('insertunorderedlist'));
23973 var ans = this.editorcore.getAllAncestors();
23974 if (this.formatCombo) {
23977 var store = this.formatCombo.store;
23978 this.formatCombo.setValue("");
23979 for (var i =0; i < ans.length;i++) {
23980 if (ans[i] && store.query('tag',ans[i].tagName.toLowerCase(), false).length) {
23982 this.formatCombo.setValue(ans[i].tagName.toLowerCase());
23990 // hides menus... - so this cant be on a menu...
23991 Roo.bootstrap.MenuMgr.hideAll();
23993 Roo.bootstrap.MenuMgr.hideAll();
23994 //this.editorsyncValue();
23996 onFirstFocus: function() {
23997 this.buttons.each(function(item){
24001 toggleSourceEdit : function(sourceEditMode){
24004 if(sourceEditMode){
24005 Roo.log("disabling buttons");
24006 this.buttons.each( function(item){
24007 if(item.cmd != 'pencil'){
24013 Roo.log("enabling buttons");
24014 if(this.editorcore.initialized){
24015 this.buttons.each( function(item){
24021 Roo.log("calling toggole on editor");
24022 // tell the editor that it's been pressed..
24023 this.editor.toggleSourceEdit(sourceEditMode);
24033 * @class Roo.bootstrap.Table.AbstractSelectionModel
24034 * @extends Roo.util.Observable
24035 * Abstract base class for grid SelectionModels. It provides the interface that should be
24036 * implemented by descendant classes. This class should not be directly instantiated.
24039 Roo.bootstrap.Table.AbstractSelectionModel = function(){
24040 this.locked = false;
24041 Roo.bootstrap.Table.AbstractSelectionModel.superclass.constructor.call(this);
24045 Roo.extend(Roo.bootstrap.Table.AbstractSelectionModel, Roo.util.Observable, {
24046 /** @ignore Called by the grid automatically. Do not call directly. */
24047 init : function(grid){
24053 * Locks the selections.
24056 this.locked = true;
24060 * Unlocks the selections.
24062 unlock : function(){
24063 this.locked = false;
24067 * Returns true if the selections are locked.
24068 * @return {Boolean}
24070 isLocked : function(){
24071 return this.locked;
24075 * @extends Roo.bootstrap.Table.AbstractSelectionModel
24076 * @class Roo.bootstrap.Table.RowSelectionModel
24077 * The default SelectionModel used by {@link Roo.bootstrap.Table}.
24078 * It supports multiple selections and keyboard selection/navigation.
24080 * @param {Object} config
24083 Roo.bootstrap.Table.RowSelectionModel = function(config){
24084 Roo.apply(this, config);
24085 this.selections = new Roo.util.MixedCollection(false, function(o){
24090 this.lastActive = false;
24094 * @event selectionchange
24095 * Fires when the selection changes
24096 * @param {SelectionModel} this
24098 "selectionchange" : true,
24100 * @event afterselectionchange
24101 * Fires after the selection changes (eg. by key press or clicking)
24102 * @param {SelectionModel} this
24104 "afterselectionchange" : true,
24106 * @event beforerowselect
24107 * Fires when a row is selected being selected, return false to cancel.
24108 * @param {SelectionModel} this
24109 * @param {Number} rowIndex The selected index
24110 * @param {Boolean} keepExisting False if other selections will be cleared
24112 "beforerowselect" : true,
24115 * Fires when a row is selected.
24116 * @param {SelectionModel} this
24117 * @param {Number} rowIndex The selected index
24118 * @param {Roo.data.Record} r The record
24120 "rowselect" : true,
24122 * @event rowdeselect
24123 * Fires when a row is deselected.
24124 * @param {SelectionModel} this
24125 * @param {Number} rowIndex The selected index
24127 "rowdeselect" : true
24129 Roo.bootstrap.Table.RowSelectionModel.superclass.constructor.call(this);
24130 this.locked = false;
24133 Roo.extend(Roo.bootstrap.Table.RowSelectionModel, Roo.bootstrap.Table.AbstractSelectionModel, {
24135 * @cfg {Boolean} singleSelect
24136 * True to allow selection of only one row at a time (defaults to false)
24138 singleSelect : false,
24141 initEvents : function()
24144 //if(!this.grid.enableDragDrop && !this.grid.enableDrag){
24145 // this.growclickrid.on("mousedown", this.handleMouseDown, this);
24146 //}else{ // allow click to work like normal
24147 // this.grid.on("rowclick", this.handleDragableRowClick, this);
24149 //this.grid.on("rowdblclick", this.handleMouseDBClick, this);
24150 this.grid.on("rowclick", this.handleMouseDown, this);
24152 this.rowNav = new Roo.KeyNav(this.grid.getGridEl(), {
24153 "up" : function(e){
24155 this.selectPrevious(e.shiftKey);
24156 }else if(this.last !== false && this.lastActive !== false){
24157 var last = this.last;
24158 this.selectRange(this.last, this.lastActive-1);
24159 this.grid.getView().focusRow(this.lastActive);
24160 if(last !== false){
24164 this.selectFirstRow();
24166 this.fireEvent("afterselectionchange", this);
24168 "down" : function(e){
24170 this.selectNext(e.shiftKey);
24171 }else if(this.last !== false && this.lastActive !== false){
24172 var last = this.last;
24173 this.selectRange(this.last, this.lastActive+1);
24174 this.grid.getView().focusRow(this.lastActive);
24175 if(last !== false){
24179 this.selectFirstRow();
24181 this.fireEvent("afterselectionchange", this);
24185 this.grid.store.on('load', function(){
24186 this.selections.clear();
24189 var view = this.grid.view;
24190 view.on("refresh", this.onRefresh, this);
24191 view.on("rowupdated", this.onRowUpdated, this);
24192 view.on("rowremoved", this.onRemove, this);
24197 onRefresh : function()
24199 var ds = this.grid.store, i, v = this.grid.view;
24200 var s = this.selections;
24201 s.each(function(r){
24202 if((i = ds.indexOfId(r.id)) != -1){
24211 onRemove : function(v, index, r){
24212 this.selections.remove(r);
24216 onRowUpdated : function(v, index, r){
24217 if(this.isSelected(r)){
24218 v.onRowSelect(index);
24224 * @param {Array} records The records to select
24225 * @param {Boolean} keepExisting (optional) True to keep existing selections
24227 selectRecords : function(records, keepExisting)
24230 this.clearSelections();
24232 var ds = this.grid.store;
24233 for(var i = 0, len = records.length; i < len; i++){
24234 this.selectRow(ds.indexOf(records[i]), true);
24239 * Gets the number of selected rows.
24242 getCount : function(){
24243 return this.selections.length;
24247 * Selects the first row in the grid.
24249 selectFirstRow : function(){
24254 * Select the last row.
24255 * @param {Boolean} keepExisting (optional) True to keep existing selections
24257 selectLastRow : function(keepExisting){
24258 //this.selectRow(this.grid.dataSource.getCount() - 1, keepExisting);
24259 this.selectRow(this.grid.store.getCount() - 1, keepExisting);
24263 * Selects the row immediately following the last selected row.
24264 * @param {Boolean} keepExisting (optional) True to keep existing selections
24266 selectNext : function(keepExisting)
24268 if(this.last !== false && (this.last+1) < this.grid.store.getCount()){
24269 this.selectRow(this.last+1, keepExisting);
24270 this.grid.getView().focusRow(this.last);
24275 * Selects the row that precedes the last selected row.
24276 * @param {Boolean} keepExisting (optional) True to keep existing selections
24278 selectPrevious : function(keepExisting){
24280 this.selectRow(this.last-1, keepExisting);
24281 this.grid.getView().focusRow(this.last);
24286 * Returns the selected records
24287 * @return {Array} Array of selected records
24289 getSelections : function(){
24290 return [].concat(this.selections.items);
24294 * Returns the first selected record.
24297 getSelected : function(){
24298 return this.selections.itemAt(0);
24303 * Clears all selections.
24305 clearSelections : function(fast)
24311 var ds = this.grid.store;
24312 var s = this.selections;
24313 s.each(function(r){
24314 this.deselectRow(ds.indexOfId(r.id));
24318 this.selections.clear();
24325 * Selects all rows.
24327 selectAll : function(){
24331 this.selections.clear();
24332 for(var i = 0, len = this.grid.store.getCount(); i < len; i++){
24333 this.selectRow(i, true);
24338 * Returns True if there is a selection.
24339 * @return {Boolean}
24341 hasSelection : function(){
24342 return this.selections.length > 0;
24346 * Returns True if the specified row is selected.
24347 * @param {Number/Record} record The record or index of the record to check
24348 * @return {Boolean}
24350 isSelected : function(index){
24351 var r = typeof index == "number" ? this.grid.store.getAt(index) : index;
24352 return (r && this.selections.key(r.id) ? true : false);
24356 * Returns True if the specified record id is selected.
24357 * @param {String} id The id of record to check
24358 * @return {Boolean}
24360 isIdSelected : function(id){
24361 return (this.selections.key(id) ? true : false);
24366 handleMouseDBClick : function(e, t){
24370 handleMouseDown : function(e, t)
24372 var rowIndex = this.grid.headerShow ? t.dom.rowIndex - 1 : t.dom.rowIndex ; // first row is header???
24373 if(this.isLocked() || rowIndex < 0 ){
24376 if(e.shiftKey && this.last !== false){
24377 var last = this.last;
24378 this.selectRange(last, rowIndex, e.ctrlKey);
24379 this.last = last; // reset the last
24383 var isSelected = this.isSelected(rowIndex);
24384 //Roo.log("select row:" + rowIndex);
24386 this.deselectRow(rowIndex);
24388 this.selectRow(rowIndex, true);
24392 if(e.button !== 0 && isSelected){
24393 alert('rowIndex 2: ' + rowIndex);
24394 view.focusRow(rowIndex);
24395 }else if(e.ctrlKey && isSelected){
24396 this.deselectRow(rowIndex);
24397 }else if(!isSelected){
24398 this.selectRow(rowIndex, e.button === 0 && (e.ctrlKey || e.shiftKey));
24399 view.focusRow(rowIndex);
24403 this.fireEvent("afterselectionchange", this);
24406 handleDragableRowClick : function(grid, rowIndex, e)
24408 if(e.button === 0 && !e.shiftKey && !e.ctrlKey) {
24409 this.selectRow(rowIndex, false);
24410 grid.view.focusRow(rowIndex);
24411 this.fireEvent("afterselectionchange", this);
24416 * Selects multiple rows.
24417 * @param {Array} rows Array of the indexes of the row to select
24418 * @param {Boolean} keepExisting (optional) True to keep existing selections
24420 selectRows : function(rows, keepExisting){
24422 this.clearSelections();
24424 for(var i = 0, len = rows.length; i < len; i++){
24425 this.selectRow(rows[i], true);
24430 * Selects a range of rows. All rows in between startRow and endRow are also selected.
24431 * @param {Number} startRow The index of the first row in the range
24432 * @param {Number} endRow The index of the last row in the range
24433 * @param {Boolean} keepExisting (optional) True to retain existing selections
24435 selectRange : function(startRow, endRow, keepExisting){
24440 this.clearSelections();
24442 if(startRow <= endRow){
24443 for(var i = startRow; i <= endRow; i++){
24444 this.selectRow(i, true);
24447 for(var i = startRow; i >= endRow; i--){
24448 this.selectRow(i, true);
24454 * Deselects a range of rows. All rows in between startRow and endRow are also deselected.
24455 * @param {Number} startRow The index of the first row in the range
24456 * @param {Number} endRow The index of the last row in the range
24458 deselectRange : function(startRow, endRow, preventViewNotify){
24462 for(var i = startRow; i <= endRow; i++){
24463 this.deselectRow(i, preventViewNotify);
24469 * @param {Number} row The index of the row to select
24470 * @param {Boolean} keepExisting (optional) True to keep existing selections
24472 selectRow : function(index, keepExisting, preventViewNotify)
24474 if(this.locked || (index < 0 || index > this.grid.store.getCount())) {
24477 if(this.fireEvent("beforerowselect", this, index, keepExisting) !== false){
24478 if(!keepExisting || this.singleSelect){
24479 this.clearSelections();
24482 var r = this.grid.store.getAt(index);
24483 //console.log('selectRow - record id :' + r.id);
24485 this.selections.add(r);
24486 this.last = this.lastActive = index;
24487 if(!preventViewNotify){
24488 var proxy = new Roo.Element(
24489 this.grid.getRowDom(index)
24491 proxy.addClass('bg-info info');
24493 this.fireEvent("rowselect", this, index, r);
24494 this.fireEvent("selectionchange", this);
24500 * @param {Number} row The index of the row to deselect
24502 deselectRow : function(index, preventViewNotify)
24507 if(this.last == index){
24510 if(this.lastActive == index){
24511 this.lastActive = false;
24514 var r = this.grid.store.getAt(index);
24519 this.selections.remove(r);
24520 //.console.log('deselectRow - record id :' + r.id);
24521 if(!preventViewNotify){
24523 var proxy = new Roo.Element(
24524 this.grid.getRowDom(index)
24526 proxy.removeClass('bg-info info');
24528 this.fireEvent("rowdeselect", this, index);
24529 this.fireEvent("selectionchange", this);
24533 restoreLast : function(){
24535 this.last = this._last;
24540 acceptsNav : function(row, col, cm){
24541 return !cm.isHidden(col) && cm.isCellEditable(col, row);
24545 onEditorKey : function(field, e){
24546 var k = e.getKey(), newCell, g = this.grid, ed = g.activeEditor;
24551 newCell = g.walkCells(ed.row, ed.col-1, -1, this.acceptsNav, this);
24553 newCell = g.walkCells(ed.row, ed.col+1, 1, this.acceptsNav, this);
24555 }else if(k == e.ENTER && !e.ctrlKey){
24559 newCell = g.walkCells(ed.row-1, ed.col, -1, this.acceptsNav, this);
24561 newCell = g.walkCells(ed.row+1, ed.col, 1, this.acceptsNav, this);
24563 }else if(k == e.ESC){
24567 g.startEditing(newCell[0], newCell[1]);
24573 * Ext JS Library 1.1.1
24574 * Copyright(c) 2006-2007, Ext JS, LLC.
24576 * Originally Released Under LGPL - original licence link has changed is not relivant.
24579 * <script type="text/javascript">
24583 * @class Roo.bootstrap.PagingToolbar
24584 * @extends Roo.bootstrap.NavSimplebar
24585 * A specialized toolbar that is bound to a {@link Roo.data.Store} and provides automatic paging controls.
24587 * Create a new PagingToolbar
24588 * @param {Object} config The config object
24589 * @param {Roo.data.Store} store
24591 Roo.bootstrap.PagingToolbar = function(config)
24593 // old args format still supported... - xtype is prefered..
24594 // created from xtype...
24596 this.ds = config.dataSource;
24598 if (config.store && !this.ds) {
24599 this.store= Roo.factory(config.store, Roo.data);
24600 this.ds = this.store;
24601 this.ds.xmodule = this.xmodule || false;
24604 this.toolbarItems = [];
24605 if (config.items) {
24606 this.toolbarItems = config.items;
24609 Roo.bootstrap.PagingToolbar.superclass.constructor.call(this, config);
24614 this.bind(this.ds);
24617 this.navgroup = new Roo.bootstrap.NavGroup({ cls: 'pagination' });
24621 Roo.extend(Roo.bootstrap.PagingToolbar, Roo.bootstrap.NavSimplebar, {
24623 * @cfg {Roo.data.Store} dataSource
24624 * The underlying data store providing the paged data
24627 * @cfg {String/HTMLElement/Element} container
24628 * container The id or element that will contain the toolbar
24631 * @cfg {Boolean} displayInfo
24632 * True to display the displayMsg (defaults to false)
24635 * @cfg {Number} pageSize
24636 * The number of records to display per page (defaults to 20)
24640 * @cfg {String} displayMsg
24641 * The paging status message to display (defaults to "Displaying {start} - {end} of {total}")
24643 displayMsg : 'Displaying {0} - {1} of {2}',
24645 * @cfg {String} emptyMsg
24646 * The message to display when no records are found (defaults to "No data to display")
24648 emptyMsg : 'No data to display',
24650 * Customizable piece of the default paging text (defaults to "Page")
24653 beforePageText : "Page",
24655 * Customizable piece of the default paging text (defaults to "of %0")
24658 afterPageText : "of {0}",
24660 * Customizable piece of the default paging text (defaults to "First Page")
24663 firstText : "First Page",
24665 * Customizable piece of the default paging text (defaults to "Previous Page")
24668 prevText : "Previous Page",
24670 * Customizable piece of the default paging text (defaults to "Next Page")
24673 nextText : "Next Page",
24675 * Customizable piece of the default paging text (defaults to "Last Page")
24678 lastText : "Last Page",
24680 * Customizable piece of the default paging text (defaults to "Refresh")
24683 refreshText : "Refresh",
24687 onRender : function(ct, position)
24689 Roo.bootstrap.PagingToolbar.superclass.onRender.call(this, ct, position);
24690 this.navgroup.parentId = this.id;
24691 this.navgroup.onRender(this.el, null);
24692 // add the buttons to the navgroup
24694 if(this.displayInfo){
24695 this.el.select('ul.navbar-nav',true).first().createChild({cls:'x-paging-info'});
24696 this.displayEl = this.el.select('.x-paging-info', true).first();
24697 // var navel = this.navgroup.addItem( { tagtype : 'span', html : '', cls : 'x-paging-info', preventDefault : true } );
24698 // this.displayEl = navel.el.select('span',true).first();
24704 Roo.each(_this.buttons, function(e){ // this might need to use render????
24705 Roo.factory(e).render(_this.el);
24709 Roo.each(_this.toolbarItems, function(e) {
24710 _this.navgroup.addItem(e);
24714 this.first = this.navgroup.addItem({
24715 tooltip: this.firstText,
24717 icon : 'fa fa-backward',
24719 preventDefault: true,
24720 listeners : { click : this.onClick.createDelegate(this, ["first"]) }
24723 this.prev = this.navgroup.addItem({
24724 tooltip: this.prevText,
24726 icon : 'fa fa-step-backward',
24728 preventDefault: true,
24729 listeners : { click : this.onClick.createDelegate(this, ["prev"]) }
24731 //this.addSeparator();
24734 var field = this.navgroup.addItem( {
24736 cls : 'x-paging-position',
24738 html : this.beforePageText +
24739 '<input type="text" size="3" value="1" class="x-grid-page-number">' +
24740 '<span class="x-paging-after">' + String.format(this.afterPageText, 1) + '</span>'
24743 this.field = field.el.select('input', true).first();
24744 this.field.on("keydown", this.onPagingKeydown, this);
24745 this.field.on("focus", function(){this.dom.select();});
24748 this.afterTextEl = field.el.select('.x-paging-after',true).first();
24749 //this.field.setHeight(18);
24750 //this.addSeparator();
24751 this.next = this.navgroup.addItem({
24752 tooltip: this.nextText,
24754 html : ' <i class="fa fa-step-forward">',
24756 preventDefault: true,
24757 listeners : { click : this.onClick.createDelegate(this, ["next"]) }
24759 this.last = this.navgroup.addItem({
24760 tooltip: this.lastText,
24761 icon : 'fa fa-forward',
24764 preventDefault: true,
24765 listeners : { click : this.onClick.createDelegate(this, ["last"]) }
24767 //this.addSeparator();
24768 this.loading = this.navgroup.addItem({
24769 tooltip: this.refreshText,
24770 icon: 'fa fa-refresh',
24771 preventDefault: true,
24772 listeners : { click : this.onClick.createDelegate(this, ["refresh"]) }
24778 updateInfo : function(){
24779 if(this.displayEl){
24780 var count = (typeof(this.getCount) == 'undefined') ? this.ds.getCount() : this.getCount();
24781 var msg = count == 0 ?
24785 this.cursor+1, this.cursor+count, this.ds.getTotalCount()
24787 this.displayEl.update(msg);
24792 onLoad : function(ds, r, o)
24794 this.cursor = o.params.start ? o.params.start : 0;
24796 var d = this.getPageData(),
24801 this.afterTextEl.dom.innerHTML = String.format(this.afterPageText, d.pages);
24802 this.field.dom.value = ap;
24803 this.first.setDisabled(ap == 1);
24804 this.prev.setDisabled(ap == 1);
24805 this.next.setDisabled(ap == ps);
24806 this.last.setDisabled(ap == ps);
24807 this.loading.enable();
24812 getPageData : function(){
24813 var total = this.ds.getTotalCount();
24816 activePage : Math.ceil((this.cursor+this.pageSize)/this.pageSize),
24817 pages : total < this.pageSize ? 1 : Math.ceil(total/this.pageSize)
24822 onLoadError : function(){
24823 this.loading.enable();
24827 onPagingKeydown : function(e){
24828 var k = e.getKey();
24829 var d = this.getPageData();
24831 var v = this.field.dom.value, pageNum;
24832 if(!v || isNaN(pageNum = parseInt(v, 10))){
24833 this.field.dom.value = d.activePage;
24836 pageNum = Math.min(Math.max(1, pageNum), d.pages) - 1;
24837 this.ds.load({params:{start: pageNum * this.pageSize, limit: this.pageSize}});
24840 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))
24842 var pageNum = (k == e.HOME || (k == e.DOWN && e.ctrlKey) || (k == e.LEFT && e.ctrlKey) || (k == e.PAGEDOWN && e.ctrlKey)) ? 1 : d.pages;
24843 this.field.dom.value = pageNum;
24844 this.ds.load({params:{start: (pageNum - 1) * this.pageSize, limit: this.pageSize}});
24847 else if(k == e.UP || k == e.RIGHT || k == e.PAGEUP || k == e.DOWN || k == e.LEFT || k == e.PAGEDOWN)
24849 var v = this.field.dom.value, pageNum;
24850 var increment = (e.shiftKey) ? 10 : 1;
24851 if(k == e.DOWN || k == e.LEFT || k == e.PAGEDOWN) {
24854 if(!v || isNaN(pageNum = parseInt(v, 10))) {
24855 this.field.dom.value = d.activePage;
24858 else if(parseInt(v, 10) + increment >= 1 & parseInt(v, 10) + increment <= d.pages)
24860 this.field.dom.value = parseInt(v, 10) + increment;
24861 pageNum = Math.min(Math.max(1, pageNum + increment), d.pages) - 1;
24862 this.ds.load({params:{start: pageNum * this.pageSize, limit: this.pageSize}});
24869 beforeLoad : function(){
24871 this.loading.disable();
24876 onClick : function(which){
24885 ds.load({params:{start: 0, limit: this.pageSize}});
24888 ds.load({params:{start: Math.max(0, this.cursor-this.pageSize), limit: this.pageSize}});
24891 ds.load({params:{start: this.cursor+this.pageSize, limit: this.pageSize}});
24894 var total = ds.getTotalCount();
24895 var extra = total % this.pageSize;
24896 var lastStart = extra ? (total - extra) : total-this.pageSize;
24897 ds.load({params:{start: lastStart, limit: this.pageSize}});
24900 ds.load({params:{start: this.cursor, limit: this.pageSize}});
24906 * Unbinds the paging toolbar from the specified {@link Roo.data.Store}
24907 * @param {Roo.data.Store} store The data store to unbind
24909 unbind : function(ds){
24910 ds.un("beforeload", this.beforeLoad, this);
24911 ds.un("load", this.onLoad, this);
24912 ds.un("loadexception", this.onLoadError, this);
24913 ds.un("remove", this.updateInfo, this);
24914 ds.un("add", this.updateInfo, this);
24915 this.ds = undefined;
24919 * Binds the paging toolbar to the specified {@link Roo.data.Store}
24920 * @param {Roo.data.Store} store The data store to bind
24922 bind : function(ds){
24923 ds.on("beforeload", this.beforeLoad, this);
24924 ds.on("load", this.onLoad, this);
24925 ds.on("loadexception", this.onLoadError, this);
24926 ds.on("remove", this.updateInfo, this);
24927 ds.on("add", this.updateInfo, this);
24938 * @class Roo.bootstrap.MessageBar
24939 * @extends Roo.bootstrap.Component
24940 * Bootstrap MessageBar class
24941 * @cfg {String} html contents of the MessageBar
24942 * @cfg {String} weight (info | success | warning | danger) default info
24943 * @cfg {String} beforeClass insert the bar before the given class
24944 * @cfg {Boolean} closable (true | false) default false
24945 * @cfg {Boolean} fixed (true | false) default false, fix the bar at the top
24948 * Create a new Element
24949 * @param {Object} config The config object
24952 Roo.bootstrap.MessageBar = function(config){
24953 Roo.bootstrap.MessageBar.superclass.constructor.call(this, config);
24956 Roo.extend(Roo.bootstrap.MessageBar, Roo.bootstrap.Component, {
24962 beforeClass: 'bootstrap-sticky-wrap',
24964 getAutoCreate : function(){
24968 cls: 'alert alert-dismissable alert-' + this.weight,
24973 html: this.html || ''
24979 cfg.cls += ' alert-messages-fixed';
24993 onRender : function(ct, position)
24995 Roo.bootstrap.Component.superclass.onRender.call(this, ct, position);
24998 var cfg = Roo.apply({}, this.getAutoCreate());
25002 cfg.cls += ' ' + this.cls;
25005 cfg.style = this.style;
25007 this.el = Roo.get(document.body).createChild(cfg, Roo.select('.'+this.beforeClass, true).first());
25009 this.el.setVisibilityMode(Roo.Element.DISPLAY);
25012 this.el.select('>button.close').on('click', this.hide, this);
25018 if (!this.rendered) {
25024 this.fireEvent('show', this);
25030 if (!this.rendered) {
25036 this.fireEvent('hide', this);
25039 update : function()
25041 // var e = this.el.dom.firstChild;
25043 // if(this.closable){
25044 // e = e.nextSibling;
25047 // e.data = this.html || '';
25049 this.el.select('>.message', true).first().dom.innerHTML = this.html || '';
25065 * @class Roo.bootstrap.Graph
25066 * @extends Roo.bootstrap.Component
25067 * Bootstrap Graph class
25071 @cfg {String} graphtype bar | vbar | pie
25072 @cfg {number} g_x coodinator | centre x (pie)
25073 @cfg {number} g_y coodinator | centre y (pie)
25074 @cfg {number} g_r radius (pie)
25075 @cfg {number} g_height height of the chart (respected by all elements in the set)
25076 @cfg {number} g_width width of the chart (respected by all elements in the set)
25077 @cfg {Object} title The title of the chart
25080 -opts (object) options for the chart
25082 o type (string) type of endings of the bar. Default: 'square'. Other options are: 'round', 'sharp', 'soft'.
25083 o gutter (number)(string) default '20%' (WHAT DOES IT DO?)
25085 o colors (array) colors be used repeatedly to plot the bars. If multicolumn bar is used each sequence of bars with use a different color.
25086 o stacked (boolean) whether or not to tread values as in a stacked bar chart
25088 o stretch (boolean)
25090 -opts (object) options for the pie
25093 o startAngle (number)
25094 o endAngle (number)
25098 * Create a new Input
25099 * @param {Object} config The config object
25102 Roo.bootstrap.Graph = function(config){
25103 Roo.bootstrap.Graph.superclass.constructor.call(this, config);
25109 * The img click event for the img.
25110 * @param {Roo.EventObject} e
25116 Roo.extend(Roo.bootstrap.Graph, Roo.bootstrap.Component, {
25127 //g_colors: this.colors,
25134 getAutoCreate : function(){
25145 onRender : function(ct,position){
25148 Roo.bootstrap.Graph.superclass.onRender.call(this,ct,position);
25150 if (typeof(Raphael) == 'undefined') {
25151 Roo.bootstrap.MessageBox.alert("Error","Raphael is not availabe");
25155 this.raphael = Raphael(this.el.dom);
25157 // data1 = [[55, 20, 13, 32, 5, 1, 2, 10], [10, 2, 1, 5, 32, 13, 20, 55], [12, 20, 30]],
25158 // data2 = [[55, 20, 13, 32, 5, 1, 2, 10], [10, 2, 1, 5, 32, 13, 20, 55], [12, 20, 30]],
25159 // data3 = [[55, 20, 13, 32, 5, 1, 2, 10], [10, 2, 1, 5, 32, 13, 20, 55], [12, 20, 30]],
25160 // txtattr = { font: "12px 'Fontin Sans', Fontin-Sans, sans-serif" };
25162 r.text(160, 10, "Single Series Chart").attr(txtattr);
25163 r.text(480, 10, "Multiline Series Chart").attr(txtattr);
25164 r.text(160, 250, "Multiple Series Stacked Chart").attr(txtattr);
25165 r.text(480, 250, 'Multiline Series Stacked Vertical Chart. Type "round"').attr(txtattr);
25167 r.barchart(10, 10, 300, 220, [[55, 20, 13, 32, 5, 1, 2, 10]], 0, {type: "sharp"});
25168 r.barchart(330, 10, 300, 220, data1);
25169 r.barchart(10, 250, 300, 220, data2, {stacked: true});
25170 r.barchart(330, 250, 300, 220, data3, {stacked: true, type: "round"});
25173 // var xdata = [55, 20, 13, 32, 5, 1, 2, 10,5 , 10];
25174 // r.barchart(30, 30, 560, 250, xdata, {
25175 // labels : [55, 20, 13, 32, 5, 1, 2, 10,5 , 10],
25176 // axis : "0 0 1 1",
25177 // axisxlabels : xdata
25178 // //yvalues : cols,
25181 // var xdata = [55, 20, 13, 32, 5, 1, 2, 10,5 , 10];
25183 // this.load(null,xdata,{
25184 // axis : "0 0 1 1",
25185 // axisxlabels : xdata
25190 load : function(graphtype,xdata,opts)
25192 this.raphael.clear();
25194 graphtype = this.graphtype;
25199 var r = this.raphael,
25200 fin = function () {
25201 this.flag = r.popup(this.bar.x, this.bar.y, this.bar.value || "0").insertBefore(this);
25203 fout = function () {
25204 this.flag.animate({opacity: 0}, 300, function () {this.remove();});
25206 pfin = function() {
25207 this.sector.stop();
25208 this.sector.scale(1.1, 1.1, this.cx, this.cy);
25211 this.label[0].stop();
25212 this.label[0].attr({ r: 7.5 });
25213 this.label[1].attr({ "font-weight": 800 });
25216 pfout = function() {
25217 this.sector.animate({ transform: 's1 1 ' + this.cx + ' ' + this.cy }, 500, "bounce");
25220 this.label[0].animate({ r: 5 }, 500, "bounce");
25221 this.label[1].attr({ "font-weight": 400 });
25227 this.raphael.barchart(this.g_x,this.g_y,this.g_width,this.g_height,xdata,opts).hover(fin,fout);
25230 this.raphael.hbarchart(this.g_x,this.g_y,this.g_width,this.g_height,xdata,opts).hover(fin,fout);
25233 // opts = { legend: ["%% - Enterprise Users", "% - ddd","Chrome Users"], legendpos: "west",
25234 // href: ["http://raphaeljs.com", "http://g.raphaeljs.com"]};
25236 this.raphael.piechart(this.g_x,this.g_y,this.g_r,xdata,opts).hover(pfin, pfout);
25243 this.raphael.text(this.title.x, this.title.y, this.title.text).attr(this.title.attr);
25248 setTitle: function(o)
25253 initEvents: function() {
25256 this.el.on('click', this.onClick, this);
25260 onClick : function(e)
25262 Roo.log('img onclick');
25263 this.fireEvent('click', this, e);
25275 Roo.bootstrap.dash = Roo.bootstrap.dash || {};
25278 * @class Roo.bootstrap.dash.NumberBox
25279 * @extends Roo.bootstrap.Component
25280 * Bootstrap NumberBox class
25281 * @cfg {String} headline Box headline
25282 * @cfg {String} content Box content
25283 * @cfg {String} icon Box icon
25284 * @cfg {String} footer Footer text
25285 * @cfg {String} fhref Footer href
25288 * Create a new NumberBox
25289 * @param {Object} config The config object
25293 Roo.bootstrap.dash.NumberBox = function(config){
25294 Roo.bootstrap.dash.NumberBox.superclass.constructor.call(this, config);
25298 Roo.extend(Roo.bootstrap.dash.NumberBox, Roo.bootstrap.Component, {
25307 getAutoCreate : function(){
25311 cls : 'small-box ',
25319 cls : 'roo-headline',
25320 html : this.headline
25324 cls : 'roo-content',
25325 html : this.content
25339 cls : 'ion ' + this.icon
25348 cls : 'small-box-footer',
25349 href : this.fhref || '#',
25353 cfg.cn.push(footer);
25360 onRender : function(ct,position){
25361 Roo.bootstrap.dash.NumberBox.superclass.onRender.call(this,ct,position);
25368 setHeadline: function (value)
25370 this.el.select('.roo-headline',true).first().dom.innerHTML = value;
25373 setFooter: function (value, href)
25375 this.el.select('a.small-box-footer',true).first().dom.innerHTML = value;
25378 this.el.select('a.small-box-footer',true).first().attr('href', href);
25383 setContent: function (value)
25385 this.el.select('.roo-content',true).first().dom.innerHTML = value;
25388 initEvents: function()
25402 Roo.bootstrap.dash = Roo.bootstrap.dash || {};
25405 * @class Roo.bootstrap.dash.TabBox
25406 * @extends Roo.bootstrap.Component
25407 * Bootstrap TabBox class
25408 * @cfg {String} title Title of the TabBox
25409 * @cfg {String} icon Icon of the TabBox
25410 * @cfg {Boolean} showtabs (true|false) show the tabs default true
25411 * @cfg {Boolean} tabScrollable (true|false) tab scrollable when mobile view default false
25414 * Create a new TabBox
25415 * @param {Object} config The config object
25419 Roo.bootstrap.dash.TabBox = function(config){
25420 Roo.bootstrap.dash.TabBox.superclass.constructor.call(this, config);
25425 * When a pane is added
25426 * @param {Roo.bootstrap.dash.TabPane} pane
25430 * @event activatepane
25431 * When a pane is activated
25432 * @param {Roo.bootstrap.dash.TabPane} pane
25434 "activatepane" : true
25442 Roo.extend(Roo.bootstrap.dash.TabBox, Roo.bootstrap.Component, {
25447 tabScrollable : false,
25449 getChildContainer : function()
25451 return this.el.select('.tab-content', true).first();
25454 getAutoCreate : function(){
25458 cls: 'pull-left header',
25466 cls: 'fa ' + this.icon
25472 cls: 'nav nav-tabs pull-right',
25478 if(this.tabScrollable){
25485 cls: 'nav nav-tabs pull-right',
25496 cls: 'nav-tabs-custom',
25501 cls: 'tab-content no-padding',
25509 initEvents : function()
25511 //Roo.log('add add pane handler');
25512 this.on('addpane', this.onAddPane, this);
25515 * Updates the box title
25516 * @param {String} html to set the title to.
25518 setTitle : function(value)
25520 this.el.select('.nav-tabs .header', true).first().dom.innerHTML = value;
25522 onAddPane : function(pane)
25524 this.panes.push(pane);
25525 //Roo.log('addpane');
25527 // tabs are rendere left to right..
25528 if(!this.showtabs){
25532 var ctr = this.el.select('.nav-tabs', true).first();
25535 var existing = ctr.select('.nav-tab',true);
25536 var qty = existing.getCount();;
25539 var tab = ctr.createChild({
25541 cls : 'nav-tab' + (qty ? '' : ' active'),
25549 }, qty ? existing.first().dom : ctr.select('.header', true).first().dom );
25552 tab.on('click', this.onTabClick.createDelegate(this, [pane], true));
25554 pane.el.addClass('active');
25559 onTabClick : function(ev,un,ob,pane)
25561 //Roo.log('tab - prev default');
25562 ev.preventDefault();
25565 this.el.select('.nav-tabs li.nav-tab', true).removeClass('active');
25566 pane.tab.addClass('active');
25567 //Roo.log(pane.title);
25568 this.getChildContainer().select('.tab-pane',true).removeClass('active');
25569 // technically we should have a deactivate event.. but maybe add later.
25570 // and it should not de-activate the selected tab...
25571 this.fireEvent('activatepane', pane);
25572 pane.el.addClass('active');
25573 pane.fireEvent('activate');
25578 getActivePane : function()
25581 Roo.each(this.panes, function(p) {
25582 if(p.el.hasClass('active')){
25603 Roo.bootstrap.dash = Roo.bootstrap.dash || {};
25605 * @class Roo.bootstrap.TabPane
25606 * @extends Roo.bootstrap.Component
25607 * Bootstrap TabPane class
25608 * @cfg {Boolean} active (false | true) Default false
25609 * @cfg {String} title title of panel
25613 * Create a new TabPane
25614 * @param {Object} config The config object
25617 Roo.bootstrap.dash.TabPane = function(config){
25618 Roo.bootstrap.dash.TabPane.superclass.constructor.call(this, config);
25624 * When a pane is activated
25625 * @param {Roo.bootstrap.dash.TabPane} pane
25632 Roo.extend(Roo.bootstrap.dash.TabPane, Roo.bootstrap.Component, {
25637 // the tabBox that this is attached to.
25640 getAutoCreate : function()
25648 cfg.cls += ' active';
25653 initEvents : function()
25655 //Roo.log('trigger add pane handler');
25656 this.parent().fireEvent('addpane', this)
25660 * Updates the tab title
25661 * @param {String} html to set the title to.
25663 setTitle: function(str)
25669 this.tab.select('a', true).first().dom.innerHTML = str;
25686 Roo.bootstrap.menu = Roo.bootstrap.menu || {};
25689 * @class Roo.bootstrap.menu.Menu
25690 * @extends Roo.bootstrap.Component
25691 * Bootstrap Menu class - container for Menu
25692 * @cfg {String} html Text of the menu
25693 * @cfg {String} weight (default | primary | success | info | warning | danger | inverse)
25694 * @cfg {String} icon Font awesome icon
25695 * @cfg {String} pos Menu align to (top | bottom) default bottom
25699 * Create a new Menu
25700 * @param {Object} config The config object
25704 Roo.bootstrap.menu.Menu = function(config){
25705 Roo.bootstrap.menu.Menu.superclass.constructor.call(this, config);
25709 * @event beforeshow
25710 * Fires before this menu is displayed
25711 * @param {Roo.bootstrap.menu.Menu} this
25715 * @event beforehide
25716 * Fires before this menu is hidden
25717 * @param {Roo.bootstrap.menu.Menu} this
25722 * Fires after this menu is displayed
25723 * @param {Roo.bootstrap.menu.Menu} this
25728 * Fires after this menu is hidden
25729 * @param {Roo.bootstrap.menu.Menu} this
25734 * Fires when this menu is clicked (or when the enter key is pressed while it is active)
25735 * @param {Roo.bootstrap.menu.Menu} this
25736 * @param {Roo.EventObject} e
25743 Roo.extend(Roo.bootstrap.menu.Menu, Roo.bootstrap.Component, {
25747 weight : 'default',
25752 getChildContainer : function() {
25753 if(this.isSubMenu){
25757 return this.el.select('ul.dropdown-menu', true).first();
25760 getAutoCreate : function()
25765 cls : 'roo-menu-text',
25773 cls : 'fa ' + this.icon
25784 cls : 'dropdown-button btn btn-' + this.weight,
25789 cls : 'dropdown-toggle btn btn-' + this.weight,
25799 cls : 'dropdown-menu'
25805 if(this.pos == 'top'){
25806 cfg.cls += ' dropup';
25809 if(this.isSubMenu){
25812 cls : 'dropdown-menu'
25819 onRender : function(ct, position)
25821 this.isSubMenu = ct.hasClass('dropdown-submenu');
25823 Roo.bootstrap.menu.Menu.superclass.onRender.call(this, ct, position);
25826 initEvents : function()
25828 if(this.isSubMenu){
25832 this.hidden = true;
25834 this.triggerEl = this.el.select('button.dropdown-toggle', true).first();
25835 this.triggerEl.on('click', this.onTriggerPress, this);
25837 this.buttonEl = this.el.select('button.dropdown-button', true).first();
25838 this.buttonEl.on('click', this.onClick, this);
25844 if(this.isSubMenu){
25848 return this.el.select('ul.dropdown-menu', true).first();
25851 onClick : function(e)
25853 this.fireEvent("click", this, e);
25856 onTriggerPress : function(e)
25858 if (this.isVisible()) {
25865 isVisible : function(){
25866 return !this.hidden;
25871 this.fireEvent("beforeshow", this);
25873 this.hidden = false;
25874 this.el.addClass('open');
25876 Roo.get(document).on("mouseup", this.onMouseUp, this);
25878 this.fireEvent("show", this);
25885 this.fireEvent("beforehide", this);
25887 this.hidden = true;
25888 this.el.removeClass('open');
25890 Roo.get(document).un("mouseup", this.onMouseUp);
25892 this.fireEvent("hide", this);
25895 onMouseUp : function()
25909 Roo.bootstrap.menu = Roo.bootstrap.menu || {};
25912 * @class Roo.bootstrap.menu.Item
25913 * @extends Roo.bootstrap.Component
25914 * Bootstrap MenuItem class
25915 * @cfg {Boolean} submenu (true | false) default false
25916 * @cfg {String} html text of the item
25917 * @cfg {String} href the link
25918 * @cfg {Boolean} disable (true | false) default false
25919 * @cfg {Boolean} preventDefault (true | false) default true
25920 * @cfg {String} icon Font awesome icon
25921 * @cfg {String} pos Submenu align to (left | right) default right
25925 * Create a new Item
25926 * @param {Object} config The config object
25930 Roo.bootstrap.menu.Item = function(config){
25931 Roo.bootstrap.menu.Item.superclass.constructor.call(this, config);
25935 * Fires when the mouse is hovering over this menu
25936 * @param {Roo.bootstrap.menu.Item} this
25937 * @param {Roo.EventObject} e
25942 * Fires when the mouse exits this menu
25943 * @param {Roo.bootstrap.menu.Item} this
25944 * @param {Roo.EventObject} e
25950 * The raw click event for the entire grid.
25951 * @param {Roo.EventObject} e
25957 Roo.extend(Roo.bootstrap.menu.Item, Roo.bootstrap.Component, {
25962 preventDefault: true,
25967 getAutoCreate : function()
25972 cls : 'roo-menu-item-text',
25980 cls : 'fa ' + this.icon
25989 href : this.href || '#',
25996 cfg.cls = (typeof(cfg.cls) == 'undefined') ? 'disabled' : (cfg.cls + ' disabled');
26000 cfg.cls = (typeof(cfg.cls) == 'undefined') ? 'dropdown-submenu' : (cfg.cls + ' dropdown-submenu');
26002 if(this.pos == 'left'){
26003 cfg.cls = (typeof(cfg.cls) == 'undefined') ? 'pull-left' : (cfg.cls + ' pull-left');
26010 initEvents : function()
26012 this.el.on('mouseover', this.onMouseOver, this);
26013 this.el.on('mouseout', this.onMouseOut, this);
26015 this.el.select('a', true).first().on('click', this.onClick, this);
26019 onClick : function(e)
26021 if(this.preventDefault){
26022 e.preventDefault();
26025 this.fireEvent("click", this, e);
26028 onMouseOver : function(e)
26030 if(this.submenu && this.pos == 'left'){
26031 this.el.select('ul.dropdown-menu', true).first().setLeft(this.el.select('ul.dropdown-menu', true).first().getWidth() * -1);
26034 this.fireEvent("mouseover", this, e);
26037 onMouseOut : function(e)
26039 this.fireEvent("mouseout", this, e);
26051 Roo.bootstrap.menu = Roo.bootstrap.menu || {};
26054 * @class Roo.bootstrap.menu.Separator
26055 * @extends Roo.bootstrap.Component
26056 * Bootstrap Separator class
26059 * Create a new Separator
26060 * @param {Object} config The config object
26064 Roo.bootstrap.menu.Separator = function(config){
26065 Roo.bootstrap.menu.Separator.superclass.constructor.call(this, config);
26068 Roo.extend(Roo.bootstrap.menu.Separator, Roo.bootstrap.Component, {
26070 getAutoCreate : function(){
26091 * @class Roo.bootstrap.Tooltip
26092 * Bootstrap Tooltip class
26093 * This is basic at present - all componets support it by default, however they should add tooltipEl() method
26094 * to determine which dom element triggers the tooltip.
26096 * It needs to add support for additional attributes like tooltip-position
26099 * Create a new Toolti
26100 * @param {Object} config The config object
26103 Roo.bootstrap.Tooltip = function(config){
26104 Roo.bootstrap.Tooltip.superclass.constructor.call(this, config);
26106 this.alignment = Roo.bootstrap.Tooltip.alignment;
26108 if(typeof(config) != 'undefined' && typeof(config.alignment) != 'undefined'){
26109 this.alignment = config.alignment;
26114 Roo.apply(Roo.bootstrap.Tooltip, {
26116 * @function init initialize tooltip monitoring.
26120 currentTip : false,
26121 currentRegion : false,
26127 Roo.get(document).on('mouseover', this.enter ,this);
26128 Roo.get(document).on('mouseout', this.leave, this);
26131 this.currentTip = new Roo.bootstrap.Tooltip();
26134 enter : function(ev)
26136 var dom = ev.getTarget();
26138 //Roo.log(['enter',dom]);
26139 var el = Roo.fly(dom);
26140 if (this.currentEl) {
26142 //Roo.log(this.currentEl);
26143 //Roo.log(this.currentEl.contains(dom));
26144 if (this.currentEl == el) {
26147 if (dom != this.currentEl.dom && this.currentEl.contains(dom)) {
26153 if (this.currentTip.el) {
26154 this.currentTip.el.setVisibilityMode(Roo.Element.DISPLAY).hide(); // force hiding...
26158 if(!el || el.dom == document){
26164 // you can not look for children, as if el is the body.. then everythign is the child..
26165 if (!el.attr('tooltip')) { //
26166 if (!el.select("[tooltip]").elements.length) {
26169 // is the mouse over this child...?
26170 bindEl = el.select("[tooltip]").first();
26171 var xy = ev.getXY();
26172 if (!bindEl.getRegion().contains( { top : xy[1] ,right : xy[0] , bottom : xy[1], left : xy[0]})) {
26173 //Roo.log("not in region.");
26176 //Roo.log("child element over..");
26179 this.currentEl = bindEl;
26180 this.currentTip.bind(bindEl);
26181 this.currentRegion = Roo.lib.Region.getRegion(dom);
26182 this.currentTip.enter();
26185 leave : function(ev)
26187 var dom = ev.getTarget();
26188 //Roo.log(['leave',dom]);
26189 if (!this.currentEl) {
26194 if (dom != this.currentEl.dom) {
26197 var xy = ev.getXY();
26198 if (this.currentRegion.contains( new Roo.lib.Region( xy[1], xy[0] ,xy[1], xy[0] ))) {
26201 // only activate leave if mouse cursor is outside... bounding box..
26206 if (this.currentTip) {
26207 this.currentTip.leave();
26209 //Roo.log('clear currentEl');
26210 this.currentEl = false;
26215 'left' : ['r-l', [-2,0], 'right'],
26216 'right' : ['l-r', [2,0], 'left'],
26217 'bottom' : ['t-b', [0,2], 'top'],
26218 'top' : [ 'b-t', [0,-2], 'bottom']
26224 Roo.extend(Roo.bootstrap.Tooltip, Roo.bootstrap.Component, {
26229 delay : null, // can be { show : 300 , hide: 500}
26233 hoverState : null, //???
26235 placement : 'bottom',
26239 getAutoCreate : function(){
26246 cls : 'tooltip-arrow'
26249 cls : 'tooltip-inner'
26256 bind : function(el)
26262 enter : function () {
26264 if (this.timeout != null) {
26265 clearTimeout(this.timeout);
26268 this.hoverState = 'in';
26269 //Roo.log("enter - show");
26270 if (!this.delay || !this.delay.show) {
26275 this.timeout = setTimeout(function () {
26276 if (_t.hoverState == 'in') {
26279 }, this.delay.show);
26283 clearTimeout(this.timeout);
26285 this.hoverState = 'out';
26286 if (!this.delay || !this.delay.hide) {
26292 this.timeout = setTimeout(function () {
26293 //Roo.log("leave - timeout");
26295 if (_t.hoverState == 'out') {
26297 Roo.bootstrap.Tooltip.currentEl = false;
26302 show : function (msg)
26305 this.render(document.body);
26308 //Roo.log([this.bindEl, this.bindEl.attr('tooltip')]);
26310 var tip = msg || this.bindEl.attr('tooltip') || this.bindEl.select("[tooltip]").first().attr('tooltip');
26312 this.el.select('.tooltip-inner',true).first().dom.innerHTML = tip;
26314 this.el.removeClass(['fade','top','bottom', 'left', 'right','in']);
26316 var placement = typeof this.placement == 'function' ?
26317 this.placement.call(this, this.el, on_el) :
26320 var autoToken = /\s?auto?\s?/i;
26321 var autoPlace = autoToken.test(placement);
26323 placement = placement.replace(autoToken, '') || 'top';
26327 //this.el.setXY([0,0]);
26329 //this.el.dom.style.display='block';
26331 //this.el.appendTo(on_el);
26333 var p = this.getPosition();
26334 var box = this.el.getBox();
26340 var align = this.alignment[placement];
26342 var xy = this.el.getAlignToXY(this.bindEl, align[0], align[1]);
26344 if(placement == 'top' || placement == 'bottom'){
26346 placement = 'right';
26349 if(xy[0] + this.el.getWidth() > Roo.lib.Dom.getViewWidth()){
26350 placement = 'left';
26353 var scroll = Roo.select('body', true).first().getScroll();
26355 if(xy[1] > Roo.lib.Dom.getViewHeight() + scroll.top - this.el.getHeight()){
26359 align = this.alignment[placement];
26362 this.el.alignTo(this.bindEl, align[0],align[1]);
26363 //var arrow = this.el.select('.arrow',true).first();
26364 //arrow.set(align[2],
26366 this.el.addClass(placement);
26368 this.el.addClass('in fade');
26370 this.hoverState = null;
26372 if (this.el.hasClass('fade')) {
26383 //this.el.setXY([0,0]);
26384 this.el.removeClass('in');
26400 * @class Roo.bootstrap.LocationPicker
26401 * @extends Roo.bootstrap.Component
26402 * Bootstrap LocationPicker class
26403 * @cfg {Number} latitude Position when init default 0
26404 * @cfg {Number} longitude Position when init default 0
26405 * @cfg {Number} zoom default 15
26406 * @cfg {String} mapTypeId default google.maps.MapTypeId.ROADMAP
26407 * @cfg {Boolean} mapTypeControl default false
26408 * @cfg {Boolean} disableDoubleClickZoom default false
26409 * @cfg {Boolean} scrollwheel default true
26410 * @cfg {Boolean} streetViewControl default false
26411 * @cfg {Number} radius default 0
26412 * @cfg {String} locationName
26413 * @cfg {Boolean} draggable default true
26414 * @cfg {Boolean} enableAutocomplete default false
26415 * @cfg {Boolean} enableReverseGeocode default true
26416 * @cfg {String} markerTitle
26419 * Create a new LocationPicker
26420 * @param {Object} config The config object
26424 Roo.bootstrap.LocationPicker = function(config){
26426 Roo.bootstrap.LocationPicker.superclass.constructor.call(this, config);
26431 * Fires when the picker initialized.
26432 * @param {Roo.bootstrap.LocationPicker} this
26433 * @param {Google Location} location
26437 * @event positionchanged
26438 * Fires when the picker position changed.
26439 * @param {Roo.bootstrap.LocationPicker} this
26440 * @param {Google Location} location
26442 positionchanged : true,
26445 * Fires when the map resize.
26446 * @param {Roo.bootstrap.LocationPicker} this
26451 * Fires when the map show.
26452 * @param {Roo.bootstrap.LocationPicker} this
26457 * Fires when the map hide.
26458 * @param {Roo.bootstrap.LocationPicker} this
26463 * Fires when click the map.
26464 * @param {Roo.bootstrap.LocationPicker} this
26465 * @param {Map event} e
26469 * @event mapRightClick
26470 * Fires when right click the map.
26471 * @param {Roo.bootstrap.LocationPicker} this
26472 * @param {Map event} e
26474 mapRightClick : true,
26476 * @event markerClick
26477 * Fires when click the marker.
26478 * @param {Roo.bootstrap.LocationPicker} this
26479 * @param {Map event} e
26481 markerClick : true,
26483 * @event markerRightClick
26484 * Fires when right click the marker.
26485 * @param {Roo.bootstrap.LocationPicker} this
26486 * @param {Map event} e
26488 markerRightClick : true,
26490 * @event OverlayViewDraw
26491 * Fires when OverlayView Draw
26492 * @param {Roo.bootstrap.LocationPicker} this
26494 OverlayViewDraw : true,
26496 * @event OverlayViewOnAdd
26497 * Fires when OverlayView Draw
26498 * @param {Roo.bootstrap.LocationPicker} this
26500 OverlayViewOnAdd : true,
26502 * @event OverlayViewOnRemove
26503 * Fires when OverlayView Draw
26504 * @param {Roo.bootstrap.LocationPicker} this
26506 OverlayViewOnRemove : true,
26508 * @event OverlayViewShow
26509 * Fires when OverlayView Draw
26510 * @param {Roo.bootstrap.LocationPicker} this
26511 * @param {Pixel} cpx
26513 OverlayViewShow : true,
26515 * @event OverlayViewHide
26516 * Fires when OverlayView Draw
26517 * @param {Roo.bootstrap.LocationPicker} this
26519 OverlayViewHide : true,
26521 * @event loadexception
26522 * Fires when load google lib failed.
26523 * @param {Roo.bootstrap.LocationPicker} this
26525 loadexception : true
26530 Roo.extend(Roo.bootstrap.LocationPicker, Roo.bootstrap.Component, {
26532 gMapContext: false,
26538 mapTypeControl: false,
26539 disableDoubleClickZoom: false,
26541 streetViewControl: false,
26545 enableAutocomplete: false,
26546 enableReverseGeocode: true,
26549 getAutoCreate: function()
26554 cls: 'roo-location-picker'
26560 initEvents: function(ct, position)
26562 if(!this.el.getWidth() || this.isApplied()){
26566 this.el.setVisibilityMode(Roo.Element.DISPLAY);
26571 initial: function()
26573 if(typeof(google) == 'undefined' || typeof(google.maps) == 'undefined'){
26574 this.fireEvent('loadexception', this);
26578 if(!this.mapTypeId){
26579 this.mapTypeId = google.maps.MapTypeId.ROADMAP;
26582 this.gMapContext = this.GMapContext();
26584 this.initOverlayView();
26586 this.OverlayView = new Roo.bootstrap.LocationPicker.OverlayView(this.gMapContext.map);
26590 google.maps.event.addListener(this.gMapContext.marker, "dragend", function(event) {
26591 _this.setPosition(_this.gMapContext.marker.position);
26594 google.maps.event.addListener(this.gMapContext.map, 'click', function(event){
26595 _this.fireEvent('mapClick', this, event);
26599 google.maps.event.addListener(this.gMapContext.map, 'rightclick', function(event){
26600 _this.fireEvent('mapRightClick', this, event);
26604 google.maps.event.addListener(this.gMapContext.marker, 'click', function(event){
26605 _this.fireEvent('markerClick', this, event);
26609 google.maps.event.addListener(this.gMapContext.marker, 'rightclick', function(event){
26610 _this.fireEvent('markerRightClick', this, event);
26614 this.setPosition(this.gMapContext.location);
26616 this.fireEvent('initial', this, this.gMapContext.location);
26619 initOverlayView: function()
26623 Roo.bootstrap.LocationPicker.OverlayView.prototype = Roo.apply(new google.maps.OverlayView(), {
26627 _this.fireEvent('OverlayViewDraw', _this);
26632 _this.fireEvent('OverlayViewOnAdd', _this);
26635 onRemove: function()
26637 _this.fireEvent('OverlayViewOnRemove', _this);
26640 show: function(cpx)
26642 _this.fireEvent('OverlayViewShow', _this, cpx);
26647 _this.fireEvent('OverlayViewHide', _this);
26653 fromLatLngToContainerPixel: function(event)
26655 return this.OverlayView.getProjection().fromLatLngToContainerPixel(event.latLng);
26658 isApplied: function()
26660 return this.getGmapContext() == false ? false : true;
26663 getGmapContext: function()
26665 return (typeof(this.gMapContext) == 'undefined') ? false : this.gMapContext;
26668 GMapContext: function()
26670 var position = new google.maps.LatLng(this.latitude, this.longitude);
26672 var _map = new google.maps.Map(this.el.dom, {
26675 mapTypeId: this.mapTypeId,
26676 mapTypeControl: this.mapTypeControl,
26677 disableDoubleClickZoom: this.disableDoubleClickZoom,
26678 scrollwheel: this.scrollwheel,
26679 streetViewControl: this.streetViewControl,
26680 locationName: this.locationName,
26681 draggable: this.draggable,
26682 enableAutocomplete: this.enableAutocomplete,
26683 enableReverseGeocode: this.enableReverseGeocode
26686 var _marker = new google.maps.Marker({
26687 position: position,
26689 title: this.markerTitle,
26690 draggable: this.draggable
26697 location: position,
26698 radius: this.radius,
26699 locationName: this.locationName,
26700 addressComponents: {
26701 formatted_address: null,
26702 addressLine1: null,
26703 addressLine2: null,
26705 streetNumber: null,
26709 stateOrProvince: null
26712 domContainer: this.el.dom,
26713 geodecoder: new google.maps.Geocoder()
26717 drawCircle: function(center, radius, options)
26719 if (this.gMapContext.circle != null) {
26720 this.gMapContext.circle.setMap(null);
26724 options = Roo.apply({}, options, {
26725 strokeColor: "#0000FF",
26726 strokeOpacity: .35,
26728 fillColor: "#0000FF",
26732 options.map = this.gMapContext.map;
26733 options.radius = radius;
26734 options.center = center;
26735 this.gMapContext.circle = new google.maps.Circle(options);
26736 return this.gMapContext.circle;
26742 setPosition: function(location)
26744 this.gMapContext.location = location;
26745 this.gMapContext.marker.setPosition(location);
26746 this.gMapContext.map.panTo(location);
26747 this.drawCircle(location, this.gMapContext.radius, {});
26751 if (this.gMapContext.settings.enableReverseGeocode) {
26752 this.gMapContext.geodecoder.geocode({
26753 latLng: this.gMapContext.location
26754 }, function(results, status) {
26756 if (status == google.maps.GeocoderStatus.OK && results.length > 0) {
26757 _this.gMapContext.locationName = results[0].formatted_address;
26758 _this.gMapContext.addressComponents = _this.address_component_from_google_geocode(results[0].address_components);
26760 _this.fireEvent('positionchanged', this, location);
26767 this.fireEvent('positionchanged', this, location);
26772 google.maps.event.trigger(this.gMapContext.map, "resize");
26774 this.gMapContext.map.setCenter(this.gMapContext.marker.position);
26776 this.fireEvent('resize', this);
26779 setPositionByLatLng: function(latitude, longitude)
26781 this.setPosition(new google.maps.LatLng(latitude, longitude));
26784 getCurrentPosition: function()
26787 latitude: this.gMapContext.location.lat(),
26788 longitude: this.gMapContext.location.lng()
26792 getAddressName: function()
26794 return this.gMapContext.locationName;
26797 getAddressComponents: function()
26799 return this.gMapContext.addressComponents;
26802 address_component_from_google_geocode: function(address_components)
26806 for (var i = 0; i < address_components.length; i++) {
26807 var component = address_components[i];
26808 if (component.types.indexOf("postal_code") >= 0) {
26809 result.postalCode = component.short_name;
26810 } else if (component.types.indexOf("street_number") >= 0) {
26811 result.streetNumber = component.short_name;
26812 } else if (component.types.indexOf("route") >= 0) {
26813 result.streetName = component.short_name;
26814 } else if (component.types.indexOf("neighborhood") >= 0) {
26815 result.city = component.short_name;
26816 } else if (component.types.indexOf("locality") >= 0) {
26817 result.city = component.short_name;
26818 } else if (component.types.indexOf("sublocality") >= 0) {
26819 result.district = component.short_name;
26820 } else if (component.types.indexOf("administrative_area_level_1") >= 0) {
26821 result.stateOrProvince = component.short_name;
26822 } else if (component.types.indexOf("country") >= 0) {
26823 result.country = component.short_name;
26827 result.addressLine1 = [ result.streetNumber, result.streetName ].join(" ").trim();
26828 result.addressLine2 = "";
26832 setZoomLevel: function(zoom)
26834 this.gMapContext.map.setZoom(zoom);
26847 this.fireEvent('show', this);
26858 this.fireEvent('hide', this);
26863 Roo.apply(Roo.bootstrap.LocationPicker, {
26865 OverlayView : function(map, options)
26867 options = options || {};
26881 * @class Roo.bootstrap.Alert
26882 * @extends Roo.bootstrap.Component
26883 * Bootstrap Alert class
26884 * @cfg {String} title The title of alert
26885 * @cfg {String} html The content of alert
26886 * @cfg {String} weight ( success | info | warning | danger )
26887 * @cfg {String} faicon font-awesomeicon
26890 * Create a new alert
26891 * @param {Object} config The config object
26895 Roo.bootstrap.Alert = function(config){
26896 Roo.bootstrap.Alert.superclass.constructor.call(this, config);
26900 Roo.extend(Roo.bootstrap.Alert, Roo.bootstrap.Component, {
26907 getAutoCreate : function()
26916 cls : 'roo-alert-icon'
26921 cls : 'roo-alert-title',
26926 cls : 'roo-alert-text',
26933 cfg.cn[0].cls += ' fa ' + this.faicon;
26937 cfg.cls += ' alert-' + this.weight;
26943 initEvents: function()
26945 this.el.setVisibilityMode(Roo.Element.DISPLAY);
26948 setTitle : function(str)
26950 this.el.select('.roo-alert-title',true).first().dom.innerHTML = str;
26953 setText : function(str)
26955 this.el.select('.roo-alert-text',true).first().dom.innerHTML = str;
26958 setWeight : function(weight)
26961 this.el.select('.alert',true).first().removeClass('alert-' + this.weight);
26964 this.weight = weight;
26966 this.el.select('.alert',true).first().addClass('alert-' + this.weight);
26969 setIcon : function(icon)
26972 this.el.select('.roo-alert-icon',true).first().removeClass(['fa', 'fa-' + this.faicon]);
26975 this.faicon = icon;
26977 this.el.select('.roo-alert-icon',true).first().addClass(['fa', 'fa-' + this.faicon]);
26998 * @class Roo.bootstrap.UploadCropbox
26999 * @extends Roo.bootstrap.Component
27000 * Bootstrap UploadCropbox class
27001 * @cfg {String} emptyText show when image has been loaded
27002 * @cfg {String} rotateNotify show when image too small to rotate
27003 * @cfg {Number} errorTimeout default 3000
27004 * @cfg {Number} minWidth default 300
27005 * @cfg {Number} minHeight default 300
27006 * @cfg {Array} buttons default ['rotateLeft', 'pictureBtn', 'rotateRight']
27007 * @cfg {Boolean} isDocument (true|false) default false
27008 * @cfg {String} url action url
27009 * @cfg {String} paramName default 'imageUpload'
27010 * @cfg {String} method default POST
27011 * @cfg {Boolean} loadMask (true|false) default true
27012 * @cfg {Boolean} loadingText default 'Loading...'
27015 * Create a new UploadCropbox
27016 * @param {Object} config The config object
27019 Roo.bootstrap.UploadCropbox = function(config){
27020 Roo.bootstrap.UploadCropbox.superclass.constructor.call(this, config);
27024 * @event beforeselectfile
27025 * Fire before select file
27026 * @param {Roo.bootstrap.UploadCropbox} this
27028 "beforeselectfile" : true,
27031 * Fire after initEvent
27032 * @param {Roo.bootstrap.UploadCropbox} this
27037 * Fire after initEvent
27038 * @param {Roo.bootstrap.UploadCropbox} this
27039 * @param {String} data
27044 * Fire when preparing the file data
27045 * @param {Roo.bootstrap.UploadCropbox} this
27046 * @param {Object} file
27051 * Fire when get exception
27052 * @param {Roo.bootstrap.UploadCropbox} this
27053 * @param {XMLHttpRequest} xhr
27055 "exception" : true,
27057 * @event beforeloadcanvas
27058 * Fire before load the canvas
27059 * @param {Roo.bootstrap.UploadCropbox} this
27060 * @param {String} src
27062 "beforeloadcanvas" : true,
27065 * Fire when trash image
27066 * @param {Roo.bootstrap.UploadCropbox} this
27071 * Fire when download the image
27072 * @param {Roo.bootstrap.UploadCropbox} this
27076 * @event footerbuttonclick
27077 * Fire when footerbuttonclick
27078 * @param {Roo.bootstrap.UploadCropbox} this
27079 * @param {String} type
27081 "footerbuttonclick" : true,
27085 * @param {Roo.bootstrap.UploadCropbox} this
27090 * Fire when rotate the image
27091 * @param {Roo.bootstrap.UploadCropbox} this
27092 * @param {String} pos
27097 * Fire when inspect the file
27098 * @param {Roo.bootstrap.UploadCropbox} this
27099 * @param {Object} file
27104 * Fire when xhr upload the file
27105 * @param {Roo.bootstrap.UploadCropbox} this
27106 * @param {Object} data
27111 * Fire when arrange the file data
27112 * @param {Roo.bootstrap.UploadCropbox} this
27113 * @param {Object} formData
27118 this.buttons = this.buttons || Roo.bootstrap.UploadCropbox.footer.STANDARD;
27121 Roo.extend(Roo.bootstrap.UploadCropbox, Roo.bootstrap.Component, {
27123 emptyText : 'Click to upload image',
27124 rotateNotify : 'Image is too small to rotate',
27125 errorTimeout : 3000,
27139 cropType : 'image/jpeg',
27141 canvasLoaded : false,
27142 isDocument : false,
27144 paramName : 'imageUpload',
27146 loadingText : 'Loading...',
27149 getAutoCreate : function()
27153 cls : 'roo-upload-cropbox',
27157 cls : 'roo-upload-cropbox-selector',
27162 cls : 'roo-upload-cropbox-body',
27163 style : 'cursor:pointer',
27167 cls : 'roo-upload-cropbox-preview'
27171 cls : 'roo-upload-cropbox-thumb'
27175 cls : 'roo-upload-cropbox-empty-notify',
27176 html : this.emptyText
27180 cls : 'roo-upload-cropbox-error-notify alert alert-danger',
27181 html : this.rotateNotify
27187 cls : 'roo-upload-cropbox-footer',
27190 cls : 'btn-group btn-group-justified roo-upload-cropbox-btn-group',
27200 onRender : function(ct, position)
27202 Roo.bootstrap.UploadCropbox.superclass.onRender.call(this, ct, position);
27204 if (this.buttons.length) {
27206 Roo.each(this.buttons, function(bb) {
27208 var btn = this.el.select('.roo-upload-cropbox-footer div.roo-upload-cropbox-btn-group').first().createChild(bb);
27210 btn.on('click', this.onFooterButtonClick.createDelegate(this, [bb.action], true));
27216 this.maskEl = this.el;
27220 initEvents : function()
27222 this.urlAPI = (window.createObjectURL && window) ||
27223 (window.URL && URL.revokeObjectURL && URL) ||
27224 (window.webkitURL && webkitURL);
27226 this.bodyEl = this.el.select('.roo-upload-cropbox-body', true).first();
27227 this.bodyEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
27229 this.selectorEl = this.el.select('.roo-upload-cropbox-selector', true).first();
27230 this.selectorEl.hide();
27232 this.previewEl = this.el.select('.roo-upload-cropbox-preview', true).first();
27233 this.previewEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
27235 this.thumbEl = this.el.select('.roo-upload-cropbox-thumb', true).first();
27236 this.thumbEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
27237 this.thumbEl.hide();
27239 this.notifyEl = this.el.select('.roo-upload-cropbox-empty-notify', true).first();
27240 this.notifyEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
27242 this.errorEl = this.el.select('.roo-upload-cropbox-error-notify', true).first();
27243 this.errorEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
27244 this.errorEl.hide();
27246 this.footerEl = this.el.select('.roo-upload-cropbox-footer', true).first();
27247 this.footerEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
27248 this.footerEl.hide();
27250 this.setThumbBoxSize();
27256 this.fireEvent('initial', this);
27263 window.addEventListener("resize", function() { _this.resize(); } );
27265 this.bodyEl.on('click', this.beforeSelectFile, this);
27268 this.bodyEl.on('touchstart', this.onTouchStart, this);
27269 this.bodyEl.on('touchmove', this.onTouchMove, this);
27270 this.bodyEl.on('touchend', this.onTouchEnd, this);
27274 this.bodyEl.on('mousedown', this.onMouseDown, this);
27275 this.bodyEl.on('mousemove', this.onMouseMove, this);
27276 var mousewheel = (/Firefox/i.test(navigator.userAgent))? 'DOMMouseScroll' : 'mousewheel';
27277 this.bodyEl.on(mousewheel, this.onMouseWheel, this);
27278 Roo.get(document).on('mouseup', this.onMouseUp, this);
27281 this.selectorEl.on('change', this.onFileSelected, this);
27287 this.baseScale = 1;
27289 this.baseRotate = 1;
27290 this.dragable = false;
27291 this.pinching = false;
27294 this.cropData = false;
27295 this.notifyEl.dom.innerHTML = this.emptyText;
27297 this.selectorEl.dom.value = '';
27301 resize : function()
27303 if(this.fireEvent('resize', this) != false){
27304 this.setThumbBoxPosition();
27305 this.setCanvasPosition();
27309 onFooterButtonClick : function(e, el, o, type)
27312 case 'rotate-left' :
27313 this.onRotateLeft(e);
27315 case 'rotate-right' :
27316 this.onRotateRight(e);
27319 this.beforeSelectFile(e);
27334 this.fireEvent('footerbuttonclick', this, type);
27337 beforeSelectFile : function(e)
27339 e.preventDefault();
27341 if(this.fireEvent('beforeselectfile', this) != false){
27342 this.selectorEl.dom.click();
27346 onFileSelected : function(e)
27348 e.preventDefault();
27350 if(typeof(this.selectorEl.dom.files) == 'undefined' || !this.selectorEl.dom.files.length){
27354 var file = this.selectorEl.dom.files[0];
27356 if(this.fireEvent('inspect', this, file) != false){
27357 this.prepare(file);
27362 trash : function(e)
27364 this.fireEvent('trash', this);
27367 download : function(e)
27369 this.fireEvent('download', this);
27372 loadCanvas : function(src)
27374 if(this.fireEvent('beforeloadcanvas', this, src) != false){
27378 this.imageEl = document.createElement('img');
27382 this.imageEl.addEventListener("load", function(){ _this.onLoadCanvas(); });
27384 this.imageEl.src = src;
27388 onLoadCanvas : function()
27390 this.imageEl.OriginWidth = this.imageEl.naturalWidth || this.imageEl.width;
27391 this.imageEl.OriginHeight = this.imageEl.naturalHeight || this.imageEl.height;
27393 this.bodyEl.un('click', this.beforeSelectFile, this);
27395 this.notifyEl.hide();
27396 this.thumbEl.show();
27397 this.footerEl.show();
27399 this.baseRotateLevel();
27401 if(this.isDocument){
27402 this.setThumbBoxSize();
27405 this.setThumbBoxPosition();
27407 this.baseScaleLevel();
27413 this.canvasLoaded = true;
27416 this.maskEl.unmask();
27421 setCanvasPosition : function()
27423 if(!this.canvasEl){
27427 var pw = Math.ceil((this.bodyEl.getWidth() - this.canvasEl.width) / 2);
27428 var ph = Math.ceil((this.bodyEl.getHeight() - this.canvasEl.height) / 2);
27430 this.previewEl.setLeft(pw);
27431 this.previewEl.setTop(ph);
27435 onMouseDown : function(e)
27439 this.dragable = true;
27440 this.pinching = false;
27442 if(this.isDocument && (this.canvasEl.width < this.thumbEl.getWidth() || this.canvasEl.height < this.thumbEl.getHeight())){
27443 this.dragable = false;
27447 this.mouseX = Roo.isTouch ? e.browserEvent.touches[0].pageX : e.getPageX();
27448 this.mouseY = Roo.isTouch ? e.browserEvent.touches[0].pageY : e.getPageY();
27452 onMouseMove : function(e)
27456 if(!this.canvasLoaded){
27460 if (!this.dragable){
27464 var minX = Math.ceil(this.thumbEl.getLeft(true));
27465 var minY = Math.ceil(this.thumbEl.getTop(true));
27467 var maxX = Math.ceil(minX + this.thumbEl.getWidth() - this.canvasEl.width);
27468 var maxY = Math.ceil(minY + this.thumbEl.getHeight() - this.canvasEl.height);
27470 var x = Roo.isTouch ? e.browserEvent.touches[0].pageX : e.getPageX();
27471 var y = Roo.isTouch ? e.browserEvent.touches[0].pageY : e.getPageY();
27473 x = x - this.mouseX;
27474 y = y - this.mouseY;
27476 var bgX = Math.ceil(x + this.previewEl.getLeft(true));
27477 var bgY = Math.ceil(y + this.previewEl.getTop(true));
27479 bgX = (minX < bgX) ? minX : ((maxX > bgX) ? maxX : bgX);
27480 bgY = (minY < bgY) ? minY : ((maxY > bgY) ? maxY : bgY);
27482 this.previewEl.setLeft(bgX);
27483 this.previewEl.setTop(bgY);
27485 this.mouseX = Roo.isTouch ? e.browserEvent.touches[0].pageX : e.getPageX();
27486 this.mouseY = Roo.isTouch ? e.browserEvent.touches[0].pageY : e.getPageY();
27489 onMouseUp : function(e)
27493 this.dragable = false;
27496 onMouseWheel : function(e)
27500 this.startScale = this.scale;
27502 this.scale = (e.getWheelDelta() == 1) ? (this.scale + 1) : (this.scale - 1);
27504 if(!this.zoomable()){
27505 this.scale = this.startScale;
27514 zoomable : function()
27516 var minScale = this.thumbEl.getWidth() / this.minWidth;
27518 if(this.minWidth < this.minHeight){
27519 minScale = this.thumbEl.getHeight() / this.minHeight;
27522 var width = Math.ceil(this.imageEl.OriginWidth * this.getScaleLevel() / minScale);
27523 var height = Math.ceil(this.imageEl.OriginHeight * this.getScaleLevel() / minScale);
27527 (this.rotate == 0 || this.rotate == 180) &&
27529 width > this.imageEl.OriginWidth ||
27530 height > this.imageEl.OriginHeight ||
27531 (width < this.minWidth && height < this.minHeight)
27539 (this.rotate == 90 || this.rotate == 270) &&
27541 width > this.imageEl.OriginWidth ||
27542 height > this.imageEl.OriginHeight ||
27543 (width < this.minHeight && height < this.minWidth)
27550 !this.isDocument &&
27551 (this.rotate == 0 || this.rotate == 180) &&
27553 width < this.minWidth ||
27554 width > this.imageEl.OriginWidth ||
27555 height < this.minHeight ||
27556 height > this.imageEl.OriginHeight
27563 !this.isDocument &&
27564 (this.rotate == 90 || this.rotate == 270) &&
27566 width < this.minHeight ||
27567 width > this.imageEl.OriginWidth ||
27568 height < this.minWidth ||
27569 height > this.imageEl.OriginHeight
27579 onRotateLeft : function(e)
27581 if(!this.isDocument && (this.canvasEl.height < this.thumbEl.getWidth() || this.canvasEl.width < this.thumbEl.getHeight())){
27583 var minScale = this.thumbEl.getWidth() / this.minWidth;
27585 var bw = Math.ceil(this.canvasEl.width / this.getScaleLevel());
27586 var bh = Math.ceil(this.canvasEl.height / this.getScaleLevel());
27588 this.startScale = this.scale;
27590 while (this.getScaleLevel() < minScale){
27592 this.scale = this.scale + 1;
27594 if(!this.zoomable()){
27599 Math.ceil(bw * this.getScaleLevel()) < this.thumbEl.getHeight() ||
27600 Math.ceil(bh * this.getScaleLevel()) < this.thumbEl.getWidth()
27605 this.rotate = (this.rotate < 90) ? 270 : this.rotate - 90;
27612 this.scale = this.startScale;
27614 this.onRotateFail();
27619 this.rotate = (this.rotate < 90) ? 270 : this.rotate - 90;
27621 if(this.isDocument){
27622 this.setThumbBoxSize();
27623 this.setThumbBoxPosition();
27624 this.setCanvasPosition();
27629 this.fireEvent('rotate', this, 'left');
27633 onRotateRight : function(e)
27635 if(!this.isDocument && (this.canvasEl.height < this.thumbEl.getWidth() || this.canvasEl.width < this.thumbEl.getHeight())){
27637 var minScale = this.thumbEl.getWidth() / this.minWidth;
27639 var bw = Math.ceil(this.canvasEl.width / this.getScaleLevel());
27640 var bh = Math.ceil(this.canvasEl.height / this.getScaleLevel());
27642 this.startScale = this.scale;
27644 while (this.getScaleLevel() < minScale){
27646 this.scale = this.scale + 1;
27648 if(!this.zoomable()){
27653 Math.ceil(bw * this.getScaleLevel()) < this.thumbEl.getHeight() ||
27654 Math.ceil(bh * this.getScaleLevel()) < this.thumbEl.getWidth()
27659 this.rotate = (this.rotate > 180) ? 0 : this.rotate + 90;
27666 this.scale = this.startScale;
27668 this.onRotateFail();
27673 this.rotate = (this.rotate > 180) ? 0 : this.rotate + 90;
27675 if(this.isDocument){
27676 this.setThumbBoxSize();
27677 this.setThumbBoxPosition();
27678 this.setCanvasPosition();
27683 this.fireEvent('rotate', this, 'right');
27686 onRotateFail : function()
27688 this.errorEl.show(true);
27692 (function() { _this.errorEl.hide(true); }).defer(this.errorTimeout);
27697 this.previewEl.dom.innerHTML = '';
27699 var canvasEl = document.createElement("canvas");
27701 var contextEl = canvasEl.getContext("2d");
27703 canvasEl.width = this.imageEl.OriginWidth * this.getScaleLevel();
27704 canvasEl.height = this.imageEl.OriginWidth * this.getScaleLevel();
27705 var center = this.imageEl.OriginWidth / 2;
27707 if(this.imageEl.OriginWidth < this.imageEl.OriginHeight){
27708 canvasEl.width = this.imageEl.OriginHeight * this.getScaleLevel();
27709 canvasEl.height = this.imageEl.OriginHeight * this.getScaleLevel();
27710 center = this.imageEl.OriginHeight / 2;
27713 contextEl.scale(this.getScaleLevel(), this.getScaleLevel());
27715 contextEl.translate(center, center);
27716 contextEl.rotate(this.rotate * Math.PI / 180);
27718 contextEl.drawImage(this.imageEl, 0, 0, this.imageEl.OriginWidth, this.imageEl.OriginHeight, center * -1, center * -1, this.imageEl.OriginWidth, this.imageEl.OriginHeight);
27720 this.canvasEl = document.createElement("canvas");
27722 this.contextEl = this.canvasEl.getContext("2d");
27724 switch (this.rotate) {
27727 this.canvasEl.width = this.imageEl.OriginWidth * this.getScaleLevel();
27728 this.canvasEl.height = this.imageEl.OriginHeight * this.getScaleLevel();
27730 this.contextEl.drawImage(canvasEl, 0, 0, this.canvasEl.width, this.canvasEl.height, 0, 0, this.canvasEl.width, this.canvasEl.height);
27735 this.canvasEl.width = this.imageEl.OriginHeight * this.getScaleLevel();
27736 this.canvasEl.height = this.imageEl.OriginWidth * this.getScaleLevel();
27738 if(this.imageEl.OriginWidth > this.imageEl.OriginHeight){
27739 this.contextEl.drawImage(canvasEl, Math.abs(this.canvasEl.width - this.canvasEl.height), 0, this.canvasEl.width, this.canvasEl.height, 0, 0, this.canvasEl.width, this.canvasEl.height);
27743 this.contextEl.drawImage(canvasEl, 0, 0, this.canvasEl.width, this.canvasEl.height, 0, 0, this.canvasEl.width, this.canvasEl.height);
27748 this.canvasEl.width = this.imageEl.OriginWidth * this.getScaleLevel();
27749 this.canvasEl.height = this.imageEl.OriginHeight * this.getScaleLevel();
27751 if(this.imageEl.OriginWidth > this.imageEl.OriginHeight){
27752 this.contextEl.drawImage(canvasEl, 0, Math.abs(this.canvasEl.width - this.canvasEl.height), this.canvasEl.width, this.canvasEl.height, 0, 0, this.canvasEl.width, this.canvasEl.height);
27756 this.contextEl.drawImage(canvasEl, Math.abs(this.canvasEl.width - this.canvasEl.height), 0, this.canvasEl.width, this.canvasEl.height, 0, 0, this.canvasEl.width, this.canvasEl.height);
27761 this.canvasEl.width = this.imageEl.OriginHeight * this.getScaleLevel();
27762 this.canvasEl.height = this.imageEl.OriginWidth * this.getScaleLevel();
27764 if(this.imageEl.OriginWidth > this.imageEl.OriginHeight){
27765 this.contextEl.drawImage(canvasEl, 0, 0, this.canvasEl.width, this.canvasEl.height, 0, 0, this.canvasEl.width, this.canvasEl.height);
27769 this.contextEl.drawImage(canvasEl, 0, Math.abs(this.canvasEl.width - this.canvasEl.height), this.canvasEl.width, this.canvasEl.height, 0, 0, this.canvasEl.width, this.canvasEl.height);
27776 this.previewEl.appendChild(this.canvasEl);
27778 this.setCanvasPosition();
27783 if(!this.canvasLoaded){
27787 var imageCanvas = document.createElement("canvas");
27789 var imageContext = imageCanvas.getContext("2d");
27791 imageCanvas.width = (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? this.imageEl.OriginWidth : this.imageEl.OriginHeight;
27792 imageCanvas.height = (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? this.imageEl.OriginWidth : this.imageEl.OriginHeight;
27794 var center = imageCanvas.width / 2;
27796 imageContext.translate(center, center);
27798 imageContext.rotate(this.rotate * Math.PI / 180);
27800 imageContext.drawImage(this.imageEl, 0, 0, this.imageEl.OriginWidth, this.imageEl.OriginHeight, center * -1, center * -1, this.imageEl.OriginWidth, this.imageEl.OriginHeight);
27802 var canvas = document.createElement("canvas");
27804 var context = canvas.getContext("2d");
27806 canvas.width = this.minWidth;
27807 canvas.height = this.minHeight;
27809 switch (this.rotate) {
27812 var width = (this.thumbEl.getWidth() / this.getScaleLevel() > this.imageEl.OriginWidth) ? this.imageEl.OriginWidth : (this.thumbEl.getWidth() / this.getScaleLevel());
27813 var height = (this.thumbEl.getHeight() / this.getScaleLevel() > this.imageEl.OriginHeight) ? this.imageEl.OriginHeight : (this.thumbEl.getHeight() / this.getScaleLevel());
27815 var x = (this.thumbEl.getLeft(true) > this.previewEl.getLeft(true)) ? 0 : ((this.previewEl.getLeft(true) - this.thumbEl.getLeft(true)) / this.getScaleLevel());
27816 var y = (this.thumbEl.getTop(true) > this.previewEl.getTop(true)) ? 0 : ((this.previewEl.getTop(true) - this.thumbEl.getTop(true)) / this.getScaleLevel());
27818 var targetWidth = this.minWidth - 2 * x;
27819 var targetHeight = this.minHeight - 2 * y;
27823 if((x == 0 && y == 0) || (x == 0 && y > 0)){
27824 scale = targetWidth / width;
27827 if(x > 0 && y == 0){
27828 scale = targetHeight / height;
27831 if(x > 0 && y > 0){
27832 scale = targetWidth / width;
27834 if(width < height){
27835 scale = targetHeight / height;
27839 context.scale(scale, scale);
27841 var sx = Math.min(this.canvasEl.width - this.thumbEl.getWidth(), this.thumbEl.getLeft(true) - this.previewEl.getLeft(true));
27842 var sy = Math.min(this.canvasEl.height - this.thumbEl.getHeight(), this.thumbEl.getTop(true) - this.previewEl.getTop(true));
27844 sx = sx < 0 ? 0 : (sx / this.getScaleLevel());
27845 sy = sy < 0 ? 0 : (sy / this.getScaleLevel());
27847 context.drawImage(imageCanvas, sx, sy, width, height, x, y, width, height);
27852 var width = (this.thumbEl.getWidth() / this.getScaleLevel() > this.imageEl.OriginHeight) ? this.imageEl.OriginHeight : (this.thumbEl.getWidth() / this.getScaleLevel());
27853 var height = (this.thumbEl.getHeight() / this.getScaleLevel() > this.imageEl.OriginWidth) ? this.imageEl.OriginWidth : (this.thumbEl.getHeight() / this.getScaleLevel());
27855 var x = (this.thumbEl.getLeft(true) > this.previewEl.getLeft(true)) ? 0 : ((this.previewEl.getLeft(true) - this.thumbEl.getLeft(true)) / this.getScaleLevel());
27856 var y = (this.thumbEl.getTop(true) > this.previewEl.getTop(true)) ? 0 : ((this.previewEl.getTop(true) - this.thumbEl.getTop(true)) / this.getScaleLevel());
27858 var targetWidth = this.minWidth - 2 * x;
27859 var targetHeight = this.minHeight - 2 * y;
27863 if((x == 0 && y == 0) || (x == 0 && y > 0)){
27864 scale = targetWidth / width;
27867 if(x > 0 && y == 0){
27868 scale = targetHeight / height;
27871 if(x > 0 && y > 0){
27872 scale = targetWidth / width;
27874 if(width < height){
27875 scale = targetHeight / height;
27879 context.scale(scale, scale);
27881 var sx = Math.min(this.canvasEl.width - this.thumbEl.getWidth(), this.thumbEl.getLeft(true) - this.previewEl.getLeft(true));
27882 var sy = Math.min(this.canvasEl.height - this.thumbEl.getHeight(), this.thumbEl.getTop(true) - this.previewEl.getTop(true));
27884 sx = sx < 0 ? 0 : (sx / this.getScaleLevel());
27885 sy = sy < 0 ? 0 : (sy / this.getScaleLevel());
27887 sx += (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? Math.abs(this.imageEl.OriginWidth - this.imageEl.OriginHeight) : 0;
27889 context.drawImage(imageCanvas, sx, sy, width, height, x, y, width, height);
27894 var width = (this.thumbEl.getWidth() / this.getScaleLevel() > this.imageEl.OriginWidth) ? this.imageEl.OriginWidth : (this.thumbEl.getWidth() / this.getScaleLevel());
27895 var height = (this.thumbEl.getHeight() / this.getScaleLevel() > this.imageEl.OriginHeight) ? this.imageEl.OriginHeight : (this.thumbEl.getHeight() / this.getScaleLevel());
27897 var x = (this.thumbEl.getLeft(true) > this.previewEl.getLeft(true)) ? 0 : ((this.previewEl.getLeft(true) - this.thumbEl.getLeft(true)) / this.getScaleLevel());
27898 var y = (this.thumbEl.getTop(true) > this.previewEl.getTop(true)) ? 0 : ((this.previewEl.getTop(true) - this.thumbEl.getTop(true)) / this.getScaleLevel());
27900 var targetWidth = this.minWidth - 2 * x;
27901 var targetHeight = this.minHeight - 2 * y;
27905 if((x == 0 && y == 0) || (x == 0 && y > 0)){
27906 scale = targetWidth / width;
27909 if(x > 0 && y == 0){
27910 scale = targetHeight / height;
27913 if(x > 0 && y > 0){
27914 scale = targetWidth / width;
27916 if(width < height){
27917 scale = targetHeight / height;
27921 context.scale(scale, scale);
27923 var sx = Math.min(this.canvasEl.width - this.thumbEl.getWidth(), this.thumbEl.getLeft(true) - this.previewEl.getLeft(true));
27924 var sy = Math.min(this.canvasEl.height - this.thumbEl.getHeight(), this.thumbEl.getTop(true) - this.previewEl.getTop(true));
27926 sx = sx < 0 ? 0 : (sx / this.getScaleLevel());
27927 sy = sy < 0 ? 0 : (sy / this.getScaleLevel());
27929 sx += (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? 0 : Math.abs(this.imageEl.OriginWidth - this.imageEl.OriginHeight);
27930 sy += (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? Math.abs(this.imageEl.OriginWidth - this.imageEl.OriginHeight) : 0;
27932 context.drawImage(imageCanvas, sx, sy, width, height, x, y, width, height);
27937 var width = (this.thumbEl.getWidth() / this.getScaleLevel() > this.imageEl.OriginHeight) ? this.imageEl.OriginHeight : (this.thumbEl.getWidth() / this.getScaleLevel());
27938 var height = (this.thumbEl.getHeight() / this.getScaleLevel() > this.imageEl.OriginWidth) ? this.imageEl.OriginWidth : (this.thumbEl.getHeight() / this.getScaleLevel());
27940 var x = (this.thumbEl.getLeft(true) > this.previewEl.getLeft(true)) ? 0 : ((this.previewEl.getLeft(true) - this.thumbEl.getLeft(true)) / this.getScaleLevel());
27941 var y = (this.thumbEl.getTop(true) > this.previewEl.getTop(true)) ? 0 : ((this.previewEl.getTop(true) - this.thumbEl.getTop(true)) / this.getScaleLevel());
27943 var targetWidth = this.minWidth - 2 * x;
27944 var targetHeight = this.minHeight - 2 * y;
27948 if((x == 0 && y == 0) || (x == 0 && y > 0)){
27949 scale = targetWidth / width;
27952 if(x > 0 && y == 0){
27953 scale = targetHeight / height;
27956 if(x > 0 && y > 0){
27957 scale = targetWidth / width;
27959 if(width < height){
27960 scale = targetHeight / height;
27964 context.scale(scale, scale);
27966 var sx = Math.min(this.canvasEl.width - this.thumbEl.getWidth(), this.thumbEl.getLeft(true) - this.previewEl.getLeft(true));
27967 var sy = Math.min(this.canvasEl.height - this.thumbEl.getHeight(), this.thumbEl.getTop(true) - this.previewEl.getTop(true));
27969 sx = sx < 0 ? 0 : (sx / this.getScaleLevel());
27970 sy = sy < 0 ? 0 : (sy / this.getScaleLevel());
27972 sy += (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? 0 : Math.abs(this.imageEl.OriginWidth - this.imageEl.OriginHeight);
27974 context.drawImage(imageCanvas, sx, sy, width, height, x, y, width, height);
27981 this.cropData = canvas.toDataURL(this.cropType);
27983 if(this.fireEvent('crop', this, this.cropData) !== false){
27984 this.process(this.file, this.cropData);
27991 setThumbBoxSize : function()
27995 if(this.isDocument && typeof(this.imageEl) != 'undefined'){
27996 width = (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? Math.max(this.minWidth, this.minHeight) : Math.min(this.minWidth, this.minHeight);
27997 height = (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? Math.min(this.minWidth, this.minHeight) : Math.max(this.minWidth, this.minHeight);
27999 this.minWidth = width;
28000 this.minHeight = height;
28002 if(this.rotate == 90 || this.rotate == 270){
28003 this.minWidth = height;
28004 this.minHeight = width;
28009 width = Math.ceil(this.minWidth * height / this.minHeight);
28011 if(this.minWidth > this.minHeight){
28013 height = Math.ceil(this.minHeight * width / this.minWidth);
28016 this.thumbEl.setStyle({
28017 width : width + 'px',
28018 height : height + 'px'
28025 setThumbBoxPosition : function()
28027 var x = Math.ceil((this.bodyEl.getWidth() - this.thumbEl.getWidth()) / 2 );
28028 var y = Math.ceil((this.bodyEl.getHeight() - this.thumbEl.getHeight()) / 2);
28030 this.thumbEl.setLeft(x);
28031 this.thumbEl.setTop(y);
28035 baseRotateLevel : function()
28037 this.baseRotate = 1;
28040 typeof(this.exif) != 'undefined' &&
28041 typeof(this.exif[Roo.bootstrap.UploadCropbox['tags']['Orientation']]) != 'undefined' &&
28042 [1, 3, 6, 8].indexOf(this.exif[Roo.bootstrap.UploadCropbox['tags']['Orientation']]) != -1
28044 this.baseRotate = this.exif[Roo.bootstrap.UploadCropbox['tags']['Orientation']];
28047 this.rotate = Roo.bootstrap.UploadCropbox['Orientation'][this.baseRotate];
28051 baseScaleLevel : function()
28055 if(this.isDocument){
28057 if(this.baseRotate == 6 || this.baseRotate == 8){
28059 height = this.thumbEl.getHeight();
28060 this.baseScale = height / this.imageEl.OriginWidth;
28062 if(this.imageEl.OriginHeight * this.baseScale > this.thumbEl.getWidth()){
28063 width = this.thumbEl.getWidth();
28064 this.baseScale = width / this.imageEl.OriginHeight;
28070 height = this.thumbEl.getHeight();
28071 this.baseScale = height / this.imageEl.OriginHeight;
28073 if(this.imageEl.OriginWidth * this.baseScale > this.thumbEl.getWidth()){
28074 width = this.thumbEl.getWidth();
28075 this.baseScale = width / this.imageEl.OriginWidth;
28081 if(this.baseRotate == 6 || this.baseRotate == 8){
28083 width = this.thumbEl.getHeight();
28084 this.baseScale = width / this.imageEl.OriginHeight;
28086 if(this.imageEl.OriginHeight * this.baseScale < this.thumbEl.getWidth()){
28087 height = this.thumbEl.getWidth();
28088 this.baseScale = height / this.imageEl.OriginHeight;
28091 if(this.imageEl.OriginWidth > this.imageEl.OriginHeight){
28092 height = this.thumbEl.getWidth();
28093 this.baseScale = height / this.imageEl.OriginHeight;
28095 if(this.imageEl.OriginWidth * this.baseScale < this.thumbEl.getHeight()){
28096 width = this.thumbEl.getHeight();
28097 this.baseScale = width / this.imageEl.OriginWidth;
28104 width = this.thumbEl.getWidth();
28105 this.baseScale = width / this.imageEl.OriginWidth;
28107 if(this.imageEl.OriginHeight * this.baseScale < this.thumbEl.getHeight()){
28108 height = this.thumbEl.getHeight();
28109 this.baseScale = height / this.imageEl.OriginHeight;
28112 if(this.imageEl.OriginWidth > this.imageEl.OriginHeight){
28114 height = this.thumbEl.getHeight();
28115 this.baseScale = height / this.imageEl.OriginHeight;
28117 if(this.imageEl.OriginWidth * this.baseScale < this.thumbEl.getWidth()){
28118 width = this.thumbEl.getWidth();
28119 this.baseScale = width / this.imageEl.OriginWidth;
28127 getScaleLevel : function()
28129 return this.baseScale * Math.pow(1.1, this.scale);
28132 onTouchStart : function(e)
28134 if(!this.canvasLoaded){
28135 this.beforeSelectFile(e);
28139 var touches = e.browserEvent.touches;
28145 if(touches.length == 1){
28146 this.onMouseDown(e);
28150 if(touches.length != 2){
28156 for(var i = 0, finger; finger = touches[i]; i++){
28157 coords.push(finger.pageX, finger.pageY);
28160 var x = Math.pow(coords[0] - coords[2], 2);
28161 var y = Math.pow(coords[1] - coords[3], 2);
28163 this.startDistance = Math.sqrt(x + y);
28165 this.startScale = this.scale;
28167 this.pinching = true;
28168 this.dragable = false;
28172 onTouchMove : function(e)
28174 if(!this.pinching && !this.dragable){
28178 var touches = e.browserEvent.touches;
28185 this.onMouseMove(e);
28191 for(var i = 0, finger; finger = touches[i]; i++){
28192 coords.push(finger.pageX, finger.pageY);
28195 var x = Math.pow(coords[0] - coords[2], 2);
28196 var y = Math.pow(coords[1] - coords[3], 2);
28198 this.endDistance = Math.sqrt(x + y);
28200 this.scale = this.startScale + Math.floor(Math.log(this.endDistance / this.startDistance) / Math.log(1.1));
28202 if(!this.zoomable()){
28203 this.scale = this.startScale;
28211 onTouchEnd : function(e)
28213 this.pinching = false;
28214 this.dragable = false;
28218 process : function(file, crop)
28221 this.maskEl.mask(this.loadingText);
28224 this.xhr = new XMLHttpRequest();
28226 file.xhr = this.xhr;
28228 this.xhr.open(this.method, this.url, true);
28231 "Accept": "application/json",
28232 "Cache-Control": "no-cache",
28233 "X-Requested-With": "XMLHttpRequest"
28236 for (var headerName in headers) {
28237 var headerValue = headers[headerName];
28239 this.xhr.setRequestHeader(headerName, headerValue);
28245 this.xhr.onload = function()
28247 _this.xhrOnLoad(_this.xhr);
28250 this.xhr.onerror = function()
28252 _this.xhrOnError(_this.xhr);
28255 var formData = new FormData();
28257 formData.append('returnHTML', 'NO');
28260 formData.append('crop', crop);
28263 if(typeof(file) != 'undefined' && (typeof(file.id) == 'undefined' || file.id * 1 < 1)){
28264 formData.append(this.paramName, file, file.name);
28267 if(typeof(file.filename) != 'undefined'){
28268 formData.append('filename', file.filename);
28271 if(typeof(file.mimetype) != 'undefined'){
28272 formData.append('mimetype', file.mimetype);
28275 if(this.fireEvent('arrange', this, formData) != false){
28276 this.xhr.send(formData);
28280 xhrOnLoad : function(xhr)
28283 this.maskEl.unmask();
28286 if (xhr.readyState !== 4) {
28287 this.fireEvent('exception', this, xhr);
28291 var response = Roo.decode(xhr.responseText);
28293 if(!response.success){
28294 this.fireEvent('exception', this, xhr);
28298 var response = Roo.decode(xhr.responseText);
28300 this.fireEvent('upload', this, response);
28304 xhrOnError : function()
28307 this.maskEl.unmask();
28310 Roo.log('xhr on error');
28312 var response = Roo.decode(xhr.responseText);
28318 prepare : function(file)
28321 this.maskEl.mask(this.loadingText);
28327 if(typeof(file) === 'string'){
28328 this.loadCanvas(file);
28332 if(!file || !this.urlAPI){
28337 this.cropType = file.type;
28341 if(this.fireEvent('prepare', this, this.file) != false){
28343 var reader = new FileReader();
28345 reader.onload = function (e) {
28346 if (e.target.error) {
28347 Roo.log(e.target.error);
28351 var buffer = e.target.result,
28352 dataView = new DataView(buffer),
28354 maxOffset = dataView.byteLength - 4,
28358 if (dataView.getUint16(0) === 0xffd8) {
28359 while (offset < maxOffset) {
28360 markerBytes = dataView.getUint16(offset);
28362 if ((markerBytes >= 0xffe0 && markerBytes <= 0xffef) || markerBytes === 0xfffe) {
28363 markerLength = dataView.getUint16(offset + 2) + 2;
28364 if (offset + markerLength > dataView.byteLength) {
28365 Roo.log('Invalid meta data: Invalid segment size.');
28369 if(markerBytes == 0xffe1){
28370 _this.parseExifData(
28377 offset += markerLength;
28387 var url = _this.urlAPI.createObjectURL(_this.file);
28389 _this.loadCanvas(url);
28394 reader.readAsArrayBuffer(this.file);
28400 parseExifData : function(dataView, offset, length)
28402 var tiffOffset = offset + 10,
28406 if (dataView.getUint32(offset + 4) !== 0x45786966) {
28407 // No Exif data, might be XMP data instead
28411 // Check for the ASCII code for "Exif" (0x45786966):
28412 if (dataView.getUint32(offset + 4) !== 0x45786966) {
28413 // No Exif data, might be XMP data instead
28416 if (tiffOffset + 8 > dataView.byteLength) {
28417 Roo.log('Invalid Exif data: Invalid segment size.');
28420 // Check for the two null bytes:
28421 if (dataView.getUint16(offset + 8) !== 0x0000) {
28422 Roo.log('Invalid Exif data: Missing byte alignment offset.');
28425 // Check the byte alignment:
28426 switch (dataView.getUint16(tiffOffset)) {
28428 littleEndian = true;
28431 littleEndian = false;
28434 Roo.log('Invalid Exif data: Invalid byte alignment marker.');
28437 // Check for the TIFF tag marker (0x002A):
28438 if (dataView.getUint16(tiffOffset + 2, littleEndian) !== 0x002A) {
28439 Roo.log('Invalid Exif data: Missing TIFF marker.');
28442 // Retrieve the directory offset bytes, usually 0x00000008 or 8 decimal:
28443 dirOffset = dataView.getUint32(tiffOffset + 4, littleEndian);
28445 this.parseExifTags(
28448 tiffOffset + dirOffset,
28453 parseExifTags : function(dataView, tiffOffset, dirOffset, littleEndian)
28458 if (dirOffset + 6 > dataView.byteLength) {
28459 Roo.log('Invalid Exif data: Invalid directory offset.');
28462 tagsNumber = dataView.getUint16(dirOffset, littleEndian);
28463 dirEndOffset = dirOffset + 2 + 12 * tagsNumber;
28464 if (dirEndOffset + 4 > dataView.byteLength) {
28465 Roo.log('Invalid Exif data: Invalid directory size.');
28468 for (i = 0; i < tagsNumber; i += 1) {
28472 dirOffset + 2 + 12 * i, // tag offset
28476 // Return the offset to the next directory:
28477 return dataView.getUint32(dirEndOffset, littleEndian);
28480 parseExifTag : function (dataView, tiffOffset, offset, littleEndian)
28482 var tag = dataView.getUint16(offset, littleEndian);
28484 this.exif[tag] = this.getExifValue(
28488 dataView.getUint16(offset + 2, littleEndian), // tag type
28489 dataView.getUint32(offset + 4, littleEndian), // tag length
28494 getExifValue : function (dataView, tiffOffset, offset, type, length, littleEndian)
28496 var tagType = Roo.bootstrap.UploadCropbox.exifTagTypes[type],
28505 Roo.log('Invalid Exif data: Invalid tag type.');
28509 tagSize = tagType.size * length;
28510 // Determine if the value is contained in the dataOffset bytes,
28511 // or if the value at the dataOffset is a pointer to the actual data:
28512 dataOffset = tagSize > 4 ?
28513 tiffOffset + dataView.getUint32(offset + 8, littleEndian) : (offset + 8);
28514 if (dataOffset + tagSize > dataView.byteLength) {
28515 Roo.log('Invalid Exif data: Invalid data offset.');
28518 if (length === 1) {
28519 return tagType.getValue(dataView, dataOffset, littleEndian);
28522 for (i = 0; i < length; i += 1) {
28523 values[i] = tagType.getValue(dataView, dataOffset + i * tagType.size, littleEndian);
28526 if (tagType.ascii) {
28528 // Concatenate the chars:
28529 for (i = 0; i < values.length; i += 1) {
28531 // Ignore the terminating NULL byte(s):
28532 if (c === '\u0000') {
28544 Roo.apply(Roo.bootstrap.UploadCropbox, {
28546 'Orientation': 0x0112
28550 1: 0, //'top-left',
28552 3: 180, //'bottom-right',
28553 // 4: 'bottom-left',
28555 6: 90, //'right-top',
28556 // 7: 'right-bottom',
28557 8: 270 //'left-bottom'
28561 // byte, 8-bit unsigned int:
28563 getValue: function (dataView, dataOffset) {
28564 return dataView.getUint8(dataOffset);
28568 // ascii, 8-bit byte:
28570 getValue: function (dataView, dataOffset) {
28571 return String.fromCharCode(dataView.getUint8(dataOffset));
28576 // short, 16 bit int:
28578 getValue: function (dataView, dataOffset, littleEndian) {
28579 return dataView.getUint16(dataOffset, littleEndian);
28583 // long, 32 bit int:
28585 getValue: function (dataView, dataOffset, littleEndian) {
28586 return dataView.getUint32(dataOffset, littleEndian);
28590 // rational = two long values, first is numerator, second is denominator:
28592 getValue: function (dataView, dataOffset, littleEndian) {
28593 return dataView.getUint32(dataOffset, littleEndian) /
28594 dataView.getUint32(dataOffset + 4, littleEndian);
28598 // slong, 32 bit signed int:
28600 getValue: function (dataView, dataOffset, littleEndian) {
28601 return dataView.getInt32(dataOffset, littleEndian);
28605 // srational, two slongs, first is numerator, second is denominator:
28607 getValue: function (dataView, dataOffset, littleEndian) {
28608 return dataView.getInt32(dataOffset, littleEndian) /
28609 dataView.getInt32(dataOffset + 4, littleEndian);
28619 cls : 'btn-group roo-upload-cropbox-rotate-left',
28620 action : 'rotate-left',
28624 cls : 'btn btn-default',
28625 html : '<i class="fa fa-undo"></i>'
28631 cls : 'btn-group roo-upload-cropbox-picture',
28632 action : 'picture',
28636 cls : 'btn btn-default',
28637 html : '<i class="fa fa-picture-o"></i>'
28643 cls : 'btn-group roo-upload-cropbox-rotate-right',
28644 action : 'rotate-right',
28648 cls : 'btn btn-default',
28649 html : '<i class="fa fa-repeat"></i>'
28657 cls : 'btn-group roo-upload-cropbox-rotate-left',
28658 action : 'rotate-left',
28662 cls : 'btn btn-default',
28663 html : '<i class="fa fa-undo"></i>'
28669 cls : 'btn-group roo-upload-cropbox-download',
28670 action : 'download',
28674 cls : 'btn btn-default',
28675 html : '<i class="fa fa-download"></i>'
28681 cls : 'btn-group roo-upload-cropbox-crop',
28686 cls : 'btn btn-default',
28687 html : '<i class="fa fa-crop"></i>'
28693 cls : 'btn-group roo-upload-cropbox-trash',
28698 cls : 'btn btn-default',
28699 html : '<i class="fa fa-trash"></i>'
28705 cls : 'btn-group roo-upload-cropbox-rotate-right',
28706 action : 'rotate-right',
28710 cls : 'btn btn-default',
28711 html : '<i class="fa fa-repeat"></i>'
28719 cls : 'btn-group roo-upload-cropbox-rotate-left',
28720 action : 'rotate-left',
28724 cls : 'btn btn-default',
28725 html : '<i class="fa fa-undo"></i>'
28731 cls : 'btn-group roo-upload-cropbox-rotate-right',
28732 action : 'rotate-right',
28736 cls : 'btn btn-default',
28737 html : '<i class="fa fa-repeat"></i>'
28750 * @class Roo.bootstrap.DocumentManager
28751 * @extends Roo.bootstrap.Component
28752 * Bootstrap DocumentManager class
28753 * @cfg {String} paramName default 'imageUpload'
28754 * @cfg {String} toolTipName default 'filename'
28755 * @cfg {String} method default POST
28756 * @cfg {String} url action url
28757 * @cfg {Number} boxes number of boxes, 0 is no limit.. default 0
28758 * @cfg {Boolean} multiple multiple upload default true
28759 * @cfg {Number} thumbSize default 300
28760 * @cfg {String} fieldLabel
28761 * @cfg {Number} labelWidth default 4
28762 * @cfg {String} labelAlign (left|top) default left
28763 * @cfg {Boolean} editable (true|false) allow edit when upload a image default true
28764 * @cfg {Number} labellg set the width of label (1-12)
28765 * @cfg {Number} labelmd set the width of label (1-12)
28766 * @cfg {Number} labelsm set the width of label (1-12)
28767 * @cfg {Number} labelxs set the width of label (1-12)
28770 * Create a new DocumentManager
28771 * @param {Object} config The config object
28774 Roo.bootstrap.DocumentManager = function(config){
28775 Roo.bootstrap.DocumentManager.superclass.constructor.call(this, config);
28778 this.delegates = [];
28783 * Fire when initial the DocumentManager
28784 * @param {Roo.bootstrap.DocumentManager} this
28789 * inspect selected file
28790 * @param {Roo.bootstrap.DocumentManager} this
28791 * @param {File} file
28796 * Fire when xhr load exception
28797 * @param {Roo.bootstrap.DocumentManager} this
28798 * @param {XMLHttpRequest} xhr
28800 "exception" : true,
28802 * @event afterupload
28803 * Fire when xhr load exception
28804 * @param {Roo.bootstrap.DocumentManager} this
28805 * @param {XMLHttpRequest} xhr
28807 "afterupload" : true,
28810 * prepare the form data
28811 * @param {Roo.bootstrap.DocumentManager} this
28812 * @param {Object} formData
28817 * Fire when remove the file
28818 * @param {Roo.bootstrap.DocumentManager} this
28819 * @param {Object} file
28824 * Fire after refresh the file
28825 * @param {Roo.bootstrap.DocumentManager} this
28830 * Fire after click the image
28831 * @param {Roo.bootstrap.DocumentManager} this
28832 * @param {Object} file
28837 * Fire when upload a image and editable set to true
28838 * @param {Roo.bootstrap.DocumentManager} this
28839 * @param {Object} file
28843 * @event beforeselectfile
28844 * Fire before select file
28845 * @param {Roo.bootstrap.DocumentManager} this
28847 "beforeselectfile" : true,
28850 * Fire before process file
28851 * @param {Roo.bootstrap.DocumentManager} this
28852 * @param {Object} file
28856 * @event previewrendered
28857 * Fire when preview rendered
28858 * @param {Roo.bootstrap.DocumentManager} this
28859 * @param {Object} file
28861 "previewrendered" : true,
28864 "previewResize" : true
28869 Roo.extend(Roo.bootstrap.DocumentManager, Roo.bootstrap.Component, {
28878 paramName : 'imageUpload',
28879 toolTipName : 'filename',
28882 labelAlign : 'left',
28892 getAutoCreate : function()
28894 var managerWidget = {
28896 cls : 'roo-document-manager',
28900 cls : 'roo-document-manager-selector',
28905 cls : 'roo-document-manager-uploader',
28909 cls : 'roo-document-manager-upload-btn',
28910 html : '<i class="fa fa-plus"></i>'
28921 cls : 'column col-md-12',
28926 if(this.fieldLabel.length){
28931 cls : 'column col-md-12',
28932 html : this.fieldLabel
28936 cls : 'column col-md-12',
28941 if(this.labelAlign == 'left'){
28946 html : this.fieldLabel
28955 if(this.labelWidth > 12){
28956 content[0].style = "width: " + this.labelWidth + 'px';
28959 if(this.labelWidth < 13 && this.labelmd == 0){
28960 this.labelmd = this.labelWidth;
28963 if(this.labellg > 0){
28964 content[0].cls += ' col-lg-' + this.labellg;
28965 content[1].cls += ' col-lg-' + (12 - this.labellg);
28968 if(this.labelmd > 0){
28969 content[0].cls += ' col-md-' + this.labelmd;
28970 content[1].cls += ' col-md-' + (12 - this.labelmd);
28973 if(this.labelsm > 0){
28974 content[0].cls += ' col-sm-' + this.labelsm;
28975 content[1].cls += ' col-sm-' + (12 - this.labelsm);
28978 if(this.labelxs > 0){
28979 content[0].cls += ' col-xs-' + this.labelxs;
28980 content[1].cls += ' col-xs-' + (12 - this.labelxs);
28988 cls : 'row clearfix',
28996 initEvents : function()
28998 this.managerEl = this.el.select('.roo-document-manager', true).first();
28999 this.managerEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
29001 this.selectorEl = this.el.select('.roo-document-manager-selector', true).first();
29002 this.selectorEl.hide();
29005 this.selectorEl.attr('multiple', 'multiple');
29008 this.selectorEl.on('change', this.onFileSelected, this);
29010 this.uploader = this.el.select('.roo-document-manager-uploader', true).first();
29011 this.uploader.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
29013 this.uploader.on('click', this.onUploaderClick, this);
29015 this.renderProgressDialog();
29019 window.addEventListener("resize", function() { _this.refresh(); } );
29021 this.fireEvent('initial', this);
29024 renderProgressDialog : function()
29028 this.progressDialog = new Roo.bootstrap.Modal({
29029 cls : 'roo-document-manager-progress-dialog',
29030 allow_close : false,
29040 btnclick : function() {
29041 _this.uploadCancel();
29047 this.progressDialog.render(Roo.get(document.body));
29049 this.progress = new Roo.bootstrap.Progress({
29050 cls : 'roo-document-manager-progress',
29055 this.progress.render(this.progressDialog.getChildContainer());
29057 this.progressBar = new Roo.bootstrap.ProgressBar({
29058 cls : 'roo-document-manager-progress-bar',
29061 aria_valuemax : 12,
29065 this.progressBar.render(this.progress.getChildContainer());
29068 onUploaderClick : function(e)
29070 e.preventDefault();
29072 if(this.fireEvent('beforeselectfile', this) != false){
29073 this.selectorEl.dom.click();
29078 onFileSelected : function(e)
29080 e.preventDefault();
29082 if(typeof(this.selectorEl.dom.files) == 'undefined' || !this.selectorEl.dom.files.length){
29086 Roo.each(this.selectorEl.dom.files, function(file){
29087 if(this.fireEvent('inspect', this, file) != false){
29088 this.files.push(file);
29098 this.selectorEl.dom.value = '';
29100 if(!this.files || !this.files.length){
29104 if(this.boxes > 0 && this.files.length > this.boxes){
29105 this.files = this.files.slice(0, this.boxes);
29108 this.uploader.show();
29110 if(this.boxes > 0 && this.files.length > this.boxes - 1){
29111 this.uploader.hide();
29120 Roo.each(this.files, function(file){
29122 if(typeof(file.id) != 'undefined' && file.id * 1 > 0){
29123 var f = this.renderPreview(file);
29128 if(file.type.indexOf('image') != -1){
29129 this.delegates.push(
29131 _this.process(file);
29132 }).createDelegate(this)
29140 _this.process(file);
29141 }).createDelegate(this)
29146 this.files = files;
29148 this.delegates = this.delegates.concat(docs);
29150 if(!this.delegates.length){
29155 this.progressBar.aria_valuemax = this.delegates.length;
29162 arrange : function()
29164 if(!this.delegates.length){
29165 this.progressDialog.hide();
29170 var delegate = this.delegates.shift();
29172 this.progressDialog.show();
29174 this.progressDialog.setTitle((this.progressBar.aria_valuemax - this.delegates.length) + ' / ' + this.progressBar.aria_valuemax);
29176 this.progressBar.update(this.progressBar.aria_valuemax - this.delegates.length);
29181 refresh : function()
29183 this.uploader.show();
29185 if(this.boxes > 0 && this.files.length > this.boxes - 1){
29186 this.uploader.hide();
29189 Roo.isTouch ? this.closable(false) : this.closable(true);
29191 this.fireEvent('refresh', this);
29194 onRemove : function(e, el, o)
29196 e.preventDefault();
29198 this.fireEvent('remove', this, o);
29202 remove : function(o)
29206 Roo.each(this.files, function(file){
29207 if(typeof(file.id) == 'undefined' || file.id * 1 < 1 || file.id != o.id){
29216 this.files = files;
29223 Roo.each(this.files, function(file){
29228 file.target.remove();
29237 onClick : function(e, el, o)
29239 e.preventDefault();
29241 this.fireEvent('click', this, o);
29245 closable : function(closable)
29247 Roo.each(this.managerEl.select('.roo-document-manager-preview > button.close', true).elements, function(el){
29249 el.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
29261 xhrOnLoad : function(xhr)
29263 Roo.each(this.managerEl.select('.roo-document-manager-loading', true).elements, function(el){
29267 if (xhr.readyState !== 4) {
29269 this.fireEvent('exception', this, xhr);
29273 var response = Roo.decode(xhr.responseText);
29275 if(!response.success){
29277 this.fireEvent('exception', this, xhr);
29281 var file = this.renderPreview(response.data);
29283 this.files.push(file);
29287 this.fireEvent('afterupload', this, xhr);
29291 xhrOnError : function(xhr)
29293 Roo.log('xhr on error');
29295 var response = Roo.decode(xhr.responseText);
29302 process : function(file)
29304 if(this.fireEvent('process', this, file) !== false){
29305 if(this.editable && file.type.indexOf('image') != -1){
29306 this.fireEvent('edit', this, file);
29310 this.uploadStart(file, false);
29317 uploadStart : function(file, crop)
29319 this.xhr = new XMLHttpRequest();
29321 if(typeof(file.id) != 'undefined' && file.id * 1 > 0){
29326 file.xhr = this.xhr;
29328 this.managerEl.createChild({
29330 cls : 'roo-document-manager-loading',
29334 tooltip : file.name,
29335 cls : 'roo-document-manager-thumb',
29336 html : '<i class="fa fa-circle-o-notch fa-spin"></i>'
29342 this.xhr.open(this.method, this.url, true);
29345 "Accept": "application/json",
29346 "Cache-Control": "no-cache",
29347 "X-Requested-With": "XMLHttpRequest"
29350 for (var headerName in headers) {
29351 var headerValue = headers[headerName];
29353 this.xhr.setRequestHeader(headerName, headerValue);
29359 this.xhr.onload = function()
29361 _this.xhrOnLoad(_this.xhr);
29364 this.xhr.onerror = function()
29366 _this.xhrOnError(_this.xhr);
29369 var formData = new FormData();
29371 formData.append('returnHTML', 'NO');
29374 formData.append('crop', crop);
29377 formData.append(this.paramName, file, file.name);
29384 if(this.fireEvent('prepare', this, formData, options) != false){
29386 if(options.manually){
29390 this.xhr.send(formData);
29394 this.uploadCancel();
29397 uploadCancel : function()
29403 this.delegates = [];
29405 Roo.each(this.managerEl.select('.roo-document-manager-loading', true).elements, function(el){
29412 renderPreview : function(file)
29414 if(typeof(file.target) != 'undefined' && file.target){
29418 var img_src = encodeURI(baseURL +'/Images/Thumb/' + this.thumbSize + '/' + file.id + '/' + file.filename);
29420 var previewEl = this.managerEl.createChild({
29422 cls : 'roo-document-manager-preview',
29426 tooltip : file[this.toolTipName],
29427 cls : 'roo-document-manager-thumb',
29428 html : '<img tooltip="' + file[this.toolTipName] + '" src="' + img_src + '">'
29433 html : '<i class="fa fa-times-circle"></i>'
29438 var close = previewEl.select('button.close', true).first();
29440 close.on('click', this.onRemove, this, file);
29442 file.target = previewEl;
29444 var image = previewEl.select('img', true).first();
29448 image.dom.addEventListener("load", function(){ _this.onPreviewLoad(file, image); });
29450 image.on('click', this.onClick, this, file);
29452 this.fireEvent('previewrendered', this, file);
29458 onPreviewLoad : function(file, image)
29460 if(typeof(file.target) == 'undefined' || !file.target){
29464 var width = image.dom.naturalWidth || image.dom.width;
29465 var height = image.dom.naturalHeight || image.dom.height;
29467 if(!this.previewResize) {
29471 if(width > height){
29472 file.target.addClass('wide');
29476 file.target.addClass('tall');
29481 uploadFromSource : function(file, crop)
29483 this.xhr = new XMLHttpRequest();
29485 this.managerEl.createChild({
29487 cls : 'roo-document-manager-loading',
29491 tooltip : file.name,
29492 cls : 'roo-document-manager-thumb',
29493 html : '<i class="fa fa-circle-o-notch fa-spin"></i>'
29499 this.xhr.open(this.method, this.url, true);
29502 "Accept": "application/json",
29503 "Cache-Control": "no-cache",
29504 "X-Requested-With": "XMLHttpRequest"
29507 for (var headerName in headers) {
29508 var headerValue = headers[headerName];
29510 this.xhr.setRequestHeader(headerName, headerValue);
29516 this.xhr.onload = function()
29518 _this.xhrOnLoad(_this.xhr);
29521 this.xhr.onerror = function()
29523 _this.xhrOnError(_this.xhr);
29526 var formData = new FormData();
29528 formData.append('returnHTML', 'NO');
29530 formData.append('crop', crop);
29532 if(typeof(file.filename) != 'undefined'){
29533 formData.append('filename', file.filename);
29536 if(typeof(file.mimetype) != 'undefined'){
29537 formData.append('mimetype', file.mimetype);
29542 if(this.fireEvent('prepare', this, formData) != false){
29543 this.xhr.send(formData);
29553 * @class Roo.bootstrap.DocumentViewer
29554 * @extends Roo.bootstrap.Component
29555 * Bootstrap DocumentViewer class
29556 * @cfg {Boolean} showDownload (true|false) show download button (default true)
29557 * @cfg {Boolean} showTrash (true|false) show trash button (default true)
29560 * Create a new DocumentViewer
29561 * @param {Object} config The config object
29564 Roo.bootstrap.DocumentViewer = function(config){
29565 Roo.bootstrap.DocumentViewer.superclass.constructor.call(this, config);
29570 * Fire after initEvent
29571 * @param {Roo.bootstrap.DocumentViewer} this
29577 * @param {Roo.bootstrap.DocumentViewer} this
29582 * Fire after download button
29583 * @param {Roo.bootstrap.DocumentViewer} this
29588 * Fire after trash button
29589 * @param {Roo.bootstrap.DocumentViewer} this
29596 Roo.extend(Roo.bootstrap.DocumentViewer, Roo.bootstrap.Component, {
29598 showDownload : true,
29602 getAutoCreate : function()
29606 cls : 'roo-document-viewer',
29610 cls : 'roo-document-viewer-body',
29614 cls : 'roo-document-viewer-thumb',
29618 cls : 'roo-document-viewer-image'
29626 cls : 'roo-document-viewer-footer',
29629 cls : 'btn-group btn-group-justified roo-document-viewer-btn-group',
29633 cls : 'btn-group roo-document-viewer-download',
29637 cls : 'btn btn-default',
29638 html : '<i class="fa fa-download"></i>'
29644 cls : 'btn-group roo-document-viewer-trash',
29648 cls : 'btn btn-default',
29649 html : '<i class="fa fa-trash"></i>'
29662 initEvents : function()
29664 this.bodyEl = this.el.select('.roo-document-viewer-body', true).first();
29665 this.bodyEl.setVisibilityMode(Roo.Element.DISPLAY);
29667 this.thumbEl = this.el.select('.roo-document-viewer-thumb', true).first();
29668 this.thumbEl.setVisibilityMode(Roo.Element.DISPLAY);
29670 this.imageEl = this.el.select('.roo-document-viewer-image', true).first();
29671 this.imageEl.setVisibilityMode(Roo.Element.DISPLAY);
29673 this.footerEl = this.el.select('.roo-document-viewer-footer', true).first();
29674 this.footerEl.setVisibilityMode(Roo.Element.DISPLAY);
29676 this.downloadBtn = this.el.select('.roo-document-viewer-download', true).first();
29677 this.downloadBtn.setVisibilityMode(Roo.Element.DISPLAY);
29679 this.trashBtn = this.el.select('.roo-document-viewer-trash', true).first();
29680 this.trashBtn.setVisibilityMode(Roo.Element.DISPLAY);
29682 this.bodyEl.on('click', this.onClick, this);
29683 this.downloadBtn.on('click', this.onDownload, this);
29684 this.trashBtn.on('click', this.onTrash, this);
29686 this.downloadBtn.hide();
29687 this.trashBtn.hide();
29689 if(this.showDownload){
29690 this.downloadBtn.show();
29693 if(this.showTrash){
29694 this.trashBtn.show();
29697 if(!this.showDownload && !this.showTrash) {
29698 this.footerEl.hide();
29703 initial : function()
29705 this.fireEvent('initial', this);
29709 onClick : function(e)
29711 e.preventDefault();
29713 this.fireEvent('click', this);
29716 onDownload : function(e)
29718 e.preventDefault();
29720 this.fireEvent('download', this);
29723 onTrash : function(e)
29725 e.preventDefault();
29727 this.fireEvent('trash', this);
29739 * @class Roo.bootstrap.NavProgressBar
29740 * @extends Roo.bootstrap.Component
29741 * Bootstrap NavProgressBar class
29744 * Create a new nav progress bar
29745 * @param {Object} config The config object
29748 Roo.bootstrap.NavProgressBar = function(config){
29749 Roo.bootstrap.NavProgressBar.superclass.constructor.call(this, config);
29751 this.bullets = this.bullets || [];
29753 // Roo.bootstrap.NavProgressBar.register(this);
29757 * Fires when the active item changes
29758 * @param {Roo.bootstrap.NavProgressBar} this
29759 * @param {Roo.bootstrap.NavProgressItem} selected The item selected
29760 * @param {Roo.bootstrap.NavProgressItem} prev The previously selected item
29767 Roo.extend(Roo.bootstrap.NavProgressBar, Roo.bootstrap.Component, {
29772 getAutoCreate : function()
29774 var cfg = Roo.apply({}, Roo.bootstrap.NavProgressBar.superclass.getAutoCreate.call(this));
29778 cls : 'roo-navigation-bar-group',
29782 cls : 'roo-navigation-top-bar'
29786 cls : 'roo-navigation-bullets-bar',
29790 cls : 'roo-navigation-bar'
29797 cls : 'roo-navigation-bottom-bar'
29807 initEvents: function()
29812 onRender : function(ct, position)
29814 Roo.bootstrap.NavProgressBar.superclass.onRender.call(this, ct, position);
29816 if(this.bullets.length){
29817 Roo.each(this.bullets, function(b){
29826 addItem : function(cfg)
29828 var item = new Roo.bootstrap.NavProgressItem(cfg);
29830 item.parentId = this.id;
29831 item.render(this.el.select('.roo-navigation-bar', true).first(), null);
29834 var top = new Roo.bootstrap.Element({
29836 cls : 'roo-navigation-bar-text'
29839 var bottom = new Roo.bootstrap.Element({
29841 cls : 'roo-navigation-bar-text'
29844 top.onRender(this.el.select('.roo-navigation-top-bar', true).first(), null);
29845 bottom.onRender(this.el.select('.roo-navigation-bottom-bar', true).first(), null);
29847 var topText = new Roo.bootstrap.Element({
29849 html : (typeof(cfg.position) != 'undefined' && cfg.position == 'top') ? cfg.html : ''
29852 var bottomText = new Roo.bootstrap.Element({
29854 html : (typeof(cfg.position) != 'undefined' && cfg.position == 'top') ? '' : cfg.html
29857 topText.onRender(top.el, null);
29858 bottomText.onRender(bottom.el, null);
29861 item.bottomEl = bottom;
29864 this.barItems.push(item);
29869 getActive : function()
29871 var active = false;
29873 Roo.each(this.barItems, function(v){
29875 if (!v.isActive()) {
29887 setActiveItem : function(item)
29891 Roo.each(this.barItems, function(v){
29892 if (v.rid == item.rid) {
29896 if (v.isActive()) {
29897 v.setActive(false);
29902 item.setActive(true);
29904 this.fireEvent('changed', this, item, prev);
29907 getBarItem: function(rid)
29911 Roo.each(this.barItems, function(e) {
29912 if (e.rid != rid) {
29923 indexOfItem : function(item)
29927 Roo.each(this.barItems, function(v, i){
29929 if (v.rid != item.rid) {
29940 setActiveNext : function()
29942 var i = this.indexOfItem(this.getActive());
29944 if (i > this.barItems.length) {
29948 this.setActiveItem(this.barItems[i+1]);
29951 setActivePrev : function()
29953 var i = this.indexOfItem(this.getActive());
29959 this.setActiveItem(this.barItems[i-1]);
29962 format : function()
29964 if(!this.barItems.length){
29968 var width = 100 / this.barItems.length;
29970 Roo.each(this.barItems, function(i){
29971 i.el.setStyle('width', width + '%');
29972 i.topEl.el.setStyle('width', width + '%');
29973 i.bottomEl.el.setStyle('width', width + '%');
29982 * Nav Progress Item
29987 * @class Roo.bootstrap.NavProgressItem
29988 * @extends Roo.bootstrap.Component
29989 * Bootstrap NavProgressItem class
29990 * @cfg {String} rid the reference id
29991 * @cfg {Boolean} active (true|false) Is item active default false
29992 * @cfg {Boolean} disabled (true|false) Is item active default false
29993 * @cfg {String} html
29994 * @cfg {String} position (top|bottom) text position default bottom
29995 * @cfg {String} icon show icon instead of number
29998 * Create a new NavProgressItem
29999 * @param {Object} config The config object
30001 Roo.bootstrap.NavProgressItem = function(config){
30002 Roo.bootstrap.NavProgressItem.superclass.constructor.call(this, config);
30007 * The raw click event for the entire grid.
30008 * @param {Roo.bootstrap.NavProgressItem} this
30009 * @param {Roo.EventObject} e
30016 Roo.extend(Roo.bootstrap.NavProgressItem, Roo.bootstrap.Component, {
30022 position : 'bottom',
30025 getAutoCreate : function()
30027 var iconCls = 'roo-navigation-bar-item-icon';
30029 iconCls += ((this.icon) ? (' ' + this.icon) : (' step-number')) ;
30033 cls: 'roo-navigation-bar-item',
30043 cfg.cls += ' active';
30046 cfg.cls += ' disabled';
30052 disable : function()
30054 this.setDisabled(true);
30057 enable : function()
30059 this.setDisabled(false);
30062 initEvents: function()
30064 this.iconEl = this.el.select('.roo-navigation-bar-item-icon', true).first();
30066 this.iconEl.on('click', this.onClick, this);
30069 onClick : function(e)
30071 e.preventDefault();
30077 if(this.fireEvent('click', this, e) === false){
30081 this.parent().setActiveItem(this);
30084 isActive: function ()
30086 return this.active;
30089 setActive : function(state)
30091 if(this.active == state){
30095 this.active = state;
30098 this.el.addClass('active');
30102 this.el.removeClass('active');
30107 setDisabled : function(state)
30109 if(this.disabled == state){
30113 this.disabled = state;
30116 this.el.addClass('disabled');
30120 this.el.removeClass('disabled');
30123 tooltipEl : function()
30125 return this.el.select('.roo-navigation-bar-item-icon', true).first();;
30138 * @class Roo.bootstrap.FieldLabel
30139 * @extends Roo.bootstrap.Component
30140 * Bootstrap FieldLabel class
30141 * @cfg {String} html contents of the element
30142 * @cfg {String} tag tag of the element default label
30143 * @cfg {String} cls class of the element
30144 * @cfg {String} target label target
30145 * @cfg {Boolean} allowBlank (true|false) target allowBlank default true
30146 * @cfg {String} invalidClass default "text-warning"
30147 * @cfg {String} validClass default "text-success"
30148 * @cfg {String} iconTooltip default "This field is required"
30149 * @cfg {String} indicatorpos (left|right) default left
30152 * Create a new FieldLabel
30153 * @param {Object} config The config object
30156 Roo.bootstrap.FieldLabel = function(config){
30157 Roo.bootstrap.Element.superclass.constructor.call(this, config);
30162 * Fires after the field has been marked as invalid.
30163 * @param {Roo.form.FieldLabel} this
30164 * @param {String} msg The validation message
30169 * Fires after the field has been validated with no errors.
30170 * @param {Roo.form.FieldLabel} this
30176 Roo.extend(Roo.bootstrap.FieldLabel, Roo.bootstrap.Component, {
30183 invalidClass : 'has-warning',
30184 validClass : 'has-success',
30185 iconTooltip : 'This field is required',
30186 indicatorpos : 'left',
30188 getAutoCreate : function(){
30191 if (!this.allowBlank) {
30197 cls : 'roo-bootstrap-field-label ' + this.cls,
30202 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star ' + cls,
30203 tooltip : this.iconTooltip
30212 if(this.indicatorpos == 'right'){
30215 cls : 'roo-bootstrap-field-label ' + this.cls,
30224 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star '+ cls,
30225 tooltip : this.iconTooltip
30234 initEvents: function()
30236 Roo.bootstrap.Element.superclass.initEvents.call(this);
30238 this.indicator = this.indicatorEl();
30240 if(this.indicator){
30241 this.indicator.removeClass('visible');
30242 this.indicator.addClass('invisible');
30245 Roo.bootstrap.FieldLabel.register(this);
30248 indicatorEl : function()
30250 var indicator = this.el.select('i.roo-required-indicator',true).first();
30261 * Mark this field as valid
30263 markValid : function()
30265 if(this.indicator){
30266 this.indicator.removeClass('visible');
30267 this.indicator.addClass('invisible');
30270 this.el.removeClass(this.invalidClass);
30272 this.el.addClass(this.validClass);
30274 this.fireEvent('valid', this);
30278 * Mark this field as invalid
30279 * @param {String} msg The validation message
30281 markInvalid : function(msg)
30283 if(this.indicator){
30284 this.indicator.removeClass('invisible');
30285 this.indicator.addClass('visible');
30288 this.el.removeClass(this.validClass);
30290 this.el.addClass(this.invalidClass);
30292 this.fireEvent('invalid', this, msg);
30298 Roo.apply(Roo.bootstrap.FieldLabel, {
30303 * register a FieldLabel Group
30304 * @param {Roo.bootstrap.FieldLabel} the FieldLabel to add
30306 register : function(label)
30308 if(this.groups.hasOwnProperty(label.target)){
30312 this.groups[label.target] = label;
30316 * fetch a FieldLabel Group based on the target
30317 * @param {string} target
30318 * @returns {Roo.bootstrap.FieldLabel} the CheckBox group
30320 get: function(target) {
30321 if (typeof(this.groups[target]) == 'undefined') {
30325 return this.groups[target] ;
30334 * page DateSplitField.
30340 * @class Roo.bootstrap.DateSplitField
30341 * @extends Roo.bootstrap.Component
30342 * Bootstrap DateSplitField class
30343 * @cfg {string} fieldLabel - the label associated
30344 * @cfg {Number} labelWidth set the width of label (0-12)
30345 * @cfg {String} labelAlign (top|left)
30346 * @cfg {Boolean} dayAllowBlank (true|false) default false
30347 * @cfg {Boolean} monthAllowBlank (true|false) default false
30348 * @cfg {Boolean} yearAllowBlank (true|false) default false
30349 * @cfg {string} dayPlaceholder
30350 * @cfg {string} monthPlaceholder
30351 * @cfg {string} yearPlaceholder
30352 * @cfg {string} dayFormat default 'd'
30353 * @cfg {string} monthFormat default 'm'
30354 * @cfg {string} yearFormat default 'Y'
30355 * @cfg {Number} labellg set the width of label (1-12)
30356 * @cfg {Number} labelmd set the width of label (1-12)
30357 * @cfg {Number} labelsm set the width of label (1-12)
30358 * @cfg {Number} labelxs set the width of label (1-12)
30362 * Create a new DateSplitField
30363 * @param {Object} config The config object
30366 Roo.bootstrap.DateSplitField = function(config){
30367 Roo.bootstrap.DateSplitField.superclass.constructor.call(this, config);
30373 * getting the data of years
30374 * @param {Roo.bootstrap.DateSplitField} this
30375 * @param {Object} years
30380 * getting the data of days
30381 * @param {Roo.bootstrap.DateSplitField} this
30382 * @param {Object} days
30387 * Fires after the field has been marked as invalid.
30388 * @param {Roo.form.Field} this
30389 * @param {String} msg The validation message
30394 * Fires after the field has been validated with no errors.
30395 * @param {Roo.form.Field} this
30401 Roo.extend(Roo.bootstrap.DateSplitField, Roo.bootstrap.Component, {
30404 labelAlign : 'top',
30406 dayAllowBlank : false,
30407 monthAllowBlank : false,
30408 yearAllowBlank : false,
30409 dayPlaceholder : '',
30410 monthPlaceholder : '',
30411 yearPlaceholder : '',
30415 isFormField : true,
30421 getAutoCreate : function()
30425 cls : 'row roo-date-split-field-group',
30430 cls : 'form-hidden-field roo-date-split-field-group-value',
30436 var labelCls = 'col-md-12';
30437 var contentCls = 'col-md-4';
30439 if(this.fieldLabel){
30443 cls : 'column roo-date-split-field-label col-md-' + ((this.labelAlign == 'top') ? '12' : this.labelWidth),
30447 html : this.fieldLabel
30452 if(this.labelAlign == 'left'){
30454 if(this.labelWidth > 12){
30455 label.style = "width: " + this.labelWidth + 'px';
30458 if(this.labelWidth < 13 && this.labelmd == 0){
30459 this.labelmd = this.labelWidth;
30462 if(this.labellg > 0){
30463 labelCls = ' col-lg-' + this.labellg;
30464 contentCls = ' col-lg-' + ((12 - this.labellg) / 3);
30467 if(this.labelmd > 0){
30468 labelCls = ' col-md-' + this.labelmd;
30469 contentCls = ' col-md-' + ((12 - this.labelmd) / 3);
30472 if(this.labelsm > 0){
30473 labelCls = ' col-sm-' + this.labelsm;
30474 contentCls = ' col-sm-' + ((12 - this.labelsm) / 3);
30477 if(this.labelxs > 0){
30478 labelCls = ' col-xs-' + this.labelxs;
30479 contentCls = ' col-xs-' + ((12 - this.labelxs) / 3);
30483 label.cls += ' ' + labelCls;
30485 cfg.cn.push(label);
30488 Roo.each(['day', 'month', 'year'], function(t){
30491 cls : 'column roo-date-split-field-' + t + ' ' + contentCls
30498 inputEl: function ()
30500 return this.el.select('.roo-date-split-field-group-value', true).first();
30503 onRender : function(ct, position)
30507 Roo.bootstrap.NavProgressBar.superclass.onRender.call(this, ct, position);
30509 this.inputEl = this.el.select('.roo-date-split-field-group-value', true).first();
30511 this.dayField = new Roo.bootstrap.ComboBox({
30512 allowBlank : this.dayAllowBlank,
30513 alwaysQuery : true,
30514 displayField : 'value',
30517 forceSelection : true,
30519 placeholder : this.dayPlaceholder,
30520 selectOnFocus : true,
30521 tpl : '<div class="roo-select2-result"><b>{value}</b></div>',
30522 triggerAction : 'all',
30524 valueField : 'value',
30525 store : new Roo.data.SimpleStore({
30526 data : (function() {
30528 _this.fireEvent('days', _this, days);
30531 fields : [ 'value' ]
30534 select : function (_self, record, index)
30536 _this.setValue(_this.getValue());
30541 this.dayField.render(this.el.select('.roo-date-split-field-day', true).first(), null);
30543 this.monthField = new Roo.bootstrap.MonthField({
30544 after : '<i class=\"fa fa-calendar\"></i>',
30545 allowBlank : this.monthAllowBlank,
30546 placeholder : this.monthPlaceholder,
30549 render : function (_self)
30551 this.el.select('span.input-group-addon', true).first().on('click', function(e){
30552 e.preventDefault();
30556 select : function (_self, oldvalue, newvalue)
30558 _this.setValue(_this.getValue());
30563 this.monthField.render(this.el.select('.roo-date-split-field-month', true).first(), null);
30565 this.yearField = new Roo.bootstrap.ComboBox({
30566 allowBlank : this.yearAllowBlank,
30567 alwaysQuery : true,
30568 displayField : 'value',
30571 forceSelection : true,
30573 placeholder : this.yearPlaceholder,
30574 selectOnFocus : true,
30575 tpl : '<div class="roo-select2-result"><b>{value}</b></div>',
30576 triggerAction : 'all',
30578 valueField : 'value',
30579 store : new Roo.data.SimpleStore({
30580 data : (function() {
30582 _this.fireEvent('years', _this, years);
30585 fields : [ 'value' ]
30588 select : function (_self, record, index)
30590 _this.setValue(_this.getValue());
30595 this.yearField.render(this.el.select('.roo-date-split-field-year', true).first(), null);
30598 setValue : function(v, format)
30600 this.inputEl.dom.value = v;
30602 var f = format || (this.yearFormat + '-' + this.monthFormat + '-' + this.dayFormat);
30604 var d = Date.parseDate(v, f);
30611 this.setDay(d.format(this.dayFormat));
30612 this.setMonth(d.format(this.monthFormat));
30613 this.setYear(d.format(this.yearFormat));
30620 setDay : function(v)
30622 this.dayField.setValue(v);
30623 this.inputEl.dom.value = this.getValue();
30628 setMonth : function(v)
30630 this.monthField.setValue(v, true);
30631 this.inputEl.dom.value = this.getValue();
30636 setYear : function(v)
30638 this.yearField.setValue(v);
30639 this.inputEl.dom.value = this.getValue();
30644 getDay : function()
30646 return this.dayField.getValue();
30649 getMonth : function()
30651 return this.monthField.getValue();
30654 getYear : function()
30656 return this.yearField.getValue();
30659 getValue : function()
30661 var f = this.yearFormat + '-' + this.monthFormat + '-' + this.dayFormat;
30663 var date = this.yearField.getValue() + '-' + this.monthField.getValue() + '-' + this.dayField.getValue();
30673 this.inputEl.dom.value = '';
30678 validate : function()
30680 var d = this.dayField.validate();
30681 var m = this.monthField.validate();
30682 var y = this.yearField.validate();
30687 (!this.dayAllowBlank && !d) ||
30688 (!this.monthAllowBlank && !m) ||
30689 (!this.yearAllowBlank && !y)
30694 if(this.dayAllowBlank && this.monthAllowBlank && this.yearAllowBlank){
30703 this.markInvalid();
30708 markValid : function()
30711 var label = this.el.select('label', true).first();
30712 var icon = this.el.select('i.fa-star', true).first();
30718 this.fireEvent('valid', this);
30722 * Mark this field as invalid
30723 * @param {String} msg The validation message
30725 markInvalid : function(msg)
30728 var label = this.el.select('label', true).first();
30729 var icon = this.el.select('i.fa-star', true).first();
30731 if(label && !icon){
30732 this.el.select('.roo-date-split-field-label', true).createChild({
30734 cls : 'text-danger fa fa-lg fa-star',
30735 tooltip : 'This field is required',
30736 style : 'margin-right:5px;'
30740 this.fireEvent('invalid', this, msg);
30743 clearInvalid : function()
30745 var label = this.el.select('label', true).first();
30746 var icon = this.el.select('i.fa-star', true).first();
30752 this.fireEvent('valid', this);
30755 getName: function()
30765 * http://masonry.desandro.com
30767 * The idea is to render all the bricks based on vertical width...
30769 * The original code extends 'outlayer' - we might need to use that....
30775 * @class Roo.bootstrap.LayoutMasonry
30776 * @extends Roo.bootstrap.Component
30777 * Bootstrap Layout Masonry class
30780 * Create a new Element
30781 * @param {Object} config The config object
30784 Roo.bootstrap.LayoutMasonry = function(config){
30786 Roo.bootstrap.LayoutMasonry.superclass.constructor.call(this, config);
30790 Roo.bootstrap.LayoutMasonry.register(this);
30796 * Fire after layout the items
30797 * @param {Roo.bootstrap.LayoutMasonry} this
30798 * @param {Roo.EventObject} e
30805 Roo.extend(Roo.bootstrap.LayoutMasonry, Roo.bootstrap.Component, {
30808 * @cfg {Boolean} isLayoutInstant = no animation?
30810 isLayoutInstant : false, // needed?
30813 * @cfg {Number} boxWidth width of the columns
30818 * @cfg {Number} boxHeight - 0 for square, or fix it at a certian height
30823 * @cfg {Number} padWidth padding below box..
30828 * @cfg {Number} gutter gutter width..
30833 * @cfg {Number} maxCols maximum number of columns
30839 * @cfg {Boolean} isAutoInitial defalut true
30841 isAutoInitial : true,
30846 * @cfg {Boolean} isHorizontal defalut false
30848 isHorizontal : false,
30850 currentSize : null,
30856 bricks: null, //CompositeElement
30860 _isLayoutInited : false,
30862 // isAlternative : false, // only use for vertical layout...
30865 * @cfg {Number} alternativePadWidth padding below box..
30867 alternativePadWidth : 50,
30869 selectedBrick : [],
30871 getAutoCreate : function(){
30873 var cfg = Roo.apply({}, Roo.bootstrap.LayoutMasonry.superclass.getAutoCreate.call(this));
30877 cls: 'blog-masonary-wrapper ' + this.cls,
30879 cls : 'mas-boxes masonary'
30886 getChildContainer: function( )
30888 if (this.boxesEl) {
30889 return this.boxesEl;
30892 this.boxesEl = this.el.select('.mas-boxes').first();
30894 return this.boxesEl;
30898 initEvents : function()
30902 if(this.isAutoInitial){
30903 Roo.log('hook children rendered');
30904 this.on('childrenrendered', function() {
30905 Roo.log('children rendered');
30911 initial : function()
30913 this.selectedBrick = [];
30915 this.currentSize = this.el.getBox(true);
30917 Roo.EventManager.onWindowResize(this.resize, this);
30919 if(!this.isAutoInitial){
30927 //this.layout.defer(500,this);
30931 resize : function()
30933 var cs = this.el.getBox(true);
30936 this.currentSize.width == cs.width &&
30937 this.currentSize.x == cs.x &&
30938 this.currentSize.height == cs.height &&
30939 this.currentSize.y == cs.y
30941 Roo.log("no change in with or X or Y");
30945 this.currentSize = cs;
30951 layout : function()
30953 this._resetLayout();
30955 var isInstant = this.isLayoutInstant !== undefined ? this.isLayoutInstant : !this._isLayoutInited;
30957 this.layoutItems( isInstant );
30959 this._isLayoutInited = true;
30961 this.fireEvent('layout', this);
30965 _resetLayout : function()
30967 if(this.isHorizontal){
30968 this.horizontalMeasureColumns();
30972 this.verticalMeasureColumns();
30976 verticalMeasureColumns : function()
30978 this.getContainerWidth();
30980 // if(Roo.lib.Dom.getViewWidth() < 768 && this.isAlternative){
30981 // this.colWidth = Math.floor(this.containerWidth * 0.8);
30985 var boxWidth = this.boxWidth + this.padWidth;
30987 if(this.containerWidth < this.boxWidth){
30988 boxWidth = this.containerWidth
30991 var containerWidth = this.containerWidth;
30993 var cols = Math.floor(containerWidth / boxWidth);
30995 this.cols = Math.max( cols, 1 );
30997 this.cols = this.maxCols > 0 ? Math.min( this.cols, this.maxCols ) : this.cols;
30999 var totalBoxWidth = this.cols * boxWidth - this.padWidth;
31001 var avail = Math.floor((containerWidth - totalBoxWidth) / this.cols);
31003 this.colWidth = boxWidth + avail - this.padWidth;
31005 this.unitWidth = Math.round((this.colWidth - (this.gutter * 2)) / 3);
31006 this.unitHeight = this.boxHeight > 0 ? this.boxHeight : this.unitWidth;
31009 horizontalMeasureColumns : function()
31011 this.getContainerWidth();
31013 var boxWidth = this.boxWidth;
31015 if(this.containerWidth < boxWidth){
31016 boxWidth = this.containerWidth;
31019 this.unitWidth = Math.floor((boxWidth - (this.gutter * 2)) / 3);
31021 this.el.setHeight(boxWidth);
31025 getContainerWidth : function()
31027 this.containerWidth = this.el.getBox(true).width; //maybe use getComputedWidth
31030 layoutItems : function( isInstant )
31032 Roo.log(this.bricks);
31034 var items = Roo.apply([], this.bricks);
31036 if(this.isHorizontal){
31037 this._horizontalLayoutItems( items , isInstant );
31041 // if(Roo.lib.Dom.getViewWidth() < 768 && this.isAlternative){
31042 // this._verticalAlternativeLayoutItems( items , isInstant );
31046 this._verticalLayoutItems( items , isInstant );
31050 _verticalLayoutItems : function ( items , isInstant)
31052 if ( !items || !items.length ) {
31057 ['xs', 'xs', 'xs', 'tall'],
31058 ['xs', 'xs', 'tall'],
31059 ['xs', 'xs', 'sm'],
31060 ['xs', 'xs', 'xs'],
31066 ['sm', 'xs', 'xs'],
31070 ['tall', 'xs', 'xs', 'xs'],
31071 ['tall', 'xs', 'xs'],
31083 Roo.each(items, function(item, k){
31085 switch (item.size) {
31086 // these layouts take up a full box,
31097 boxes.push([item]);
31120 var filterPattern = function(box, length)
31128 var pattern = box.slice(0, length);
31132 Roo.each(pattern, function(i){
31133 format.push(i.size);
31136 Roo.each(standard, function(s){
31138 if(String(s) != String(format)){
31147 if(!match && length == 1){
31152 filterPattern(box, length - 1);
31156 queue.push(pattern);
31158 box = box.slice(length, box.length);
31160 filterPattern(box, 4);
31166 Roo.each(boxes, function(box, k){
31172 if(box.length == 1){
31177 filterPattern(box, 4);
31181 this._processVerticalLayoutQueue( queue, isInstant );
31185 // _verticalAlternativeLayoutItems : function( items , isInstant )
31187 // if ( !items || !items.length ) {
31191 // this._processVerticalAlternativeLayoutQueue( items, isInstant );
31195 _horizontalLayoutItems : function ( items , isInstant)
31197 if ( !items || !items.length || items.length < 3) {
31203 var eItems = items.slice(0, 3);
31205 items = items.slice(3, items.length);
31208 ['xs', 'xs', 'xs', 'wide'],
31209 ['xs', 'xs', 'wide'],
31210 ['xs', 'xs', 'sm'],
31211 ['xs', 'xs', 'xs'],
31217 ['sm', 'xs', 'xs'],
31221 ['wide', 'xs', 'xs', 'xs'],
31222 ['wide', 'xs', 'xs'],
31235 Roo.each(items, function(item, k){
31237 switch (item.size) {
31248 boxes.push([item]);
31272 var filterPattern = function(box, length)
31280 var pattern = box.slice(0, length);
31284 Roo.each(pattern, function(i){
31285 format.push(i.size);
31288 Roo.each(standard, function(s){
31290 if(String(s) != String(format)){
31299 if(!match && length == 1){
31304 filterPattern(box, length - 1);
31308 queue.push(pattern);
31310 box = box.slice(length, box.length);
31312 filterPattern(box, 4);
31318 Roo.each(boxes, function(box, k){
31324 if(box.length == 1){
31329 filterPattern(box, 4);
31336 var pos = this.el.getBox(true);
31340 var maxX = pos.right - this.unitWidth * 3 - this.gutter * 2 - this.padWidth;
31342 var hit_end = false;
31344 Roo.each(queue, function(box){
31348 Roo.each(box, function(b){
31350 b.el.setVisibilityMode(Roo.Element.DISPLAY);
31360 Roo.each(box, function(b){
31362 b.el.setVisibilityMode(Roo.Element.DISPLAY);
31365 mx = Math.max(mx, b.x);
31369 maxX = maxX - this.unitWidth * mx - this.gutter * (mx - 1) - this.padWidth;
31373 Roo.each(box, function(b){
31375 b.el.setVisibilityMode(Roo.Element.DISPLAY);
31389 this._processHorizontalLayoutQueue( prune, eItems, isInstant );
31392 /** Sets position of item in DOM
31393 * @param {Element} item
31394 * @param {Number} x - horizontal position
31395 * @param {Number} y - vertical position
31396 * @param {Boolean} isInstant - disables transitions
31398 _processVerticalLayoutQueue : function( queue, isInstant )
31400 var pos = this.el.getBox(true);
31405 for (var i = 0; i < this.cols; i++){
31409 Roo.each(queue, function(box, k){
31411 var col = k % this.cols;
31413 Roo.each(box, function(b,kk){
31415 b.el.position('absolute');
31417 var width = Math.floor(this.unitWidth * b.x + (this.gutter * (b.x - 1)) + b.el.getPadding('lr'));
31418 var height = Math.floor(this.unitHeight * b.y + (this.gutter * (b.y - 1)) + b.el.getPadding('tb'));
31420 if(b.size == 'md-left' || b.size == 'md-right'){
31421 width = Math.floor(this.unitWidth * (b.x - 1) + (this.gutter * (b.x - 2)) + b.el.getPadding('lr'));
31422 height = Math.floor(this.unitHeight * (b.y - 1) + (this.gutter * (b.y - 2)) + b.el.getPadding('tb'));
31425 b.el.setWidth(width);
31426 b.el.setHeight(height);
31428 b.el.select('iframe',true).setSize(width,height);
31432 for (var i = 0; i < this.cols; i++){
31434 if(maxY[i] < maxY[col]){
31439 col = Math.min(col, i);
31443 x = pos.x + col * (this.colWidth + this.padWidth);
31447 var positions = [];
31449 switch (box.length){
31451 positions = this.getVerticalOneBoxColPositions(x, y, box);
31454 positions = this.getVerticalTwoBoxColPositions(x, y, box);
31457 positions = this.getVerticalThreeBoxColPositions(x, y, box);
31460 positions = this.getVerticalFourBoxColPositions(x, y, box);
31466 Roo.each(box, function(b,kk){
31468 b.el.setXY([positions[kk].x, positions[kk].y], isInstant ? false : true);
31470 var sz = b.el.getSize();
31472 maxY[col] = Math.max(maxY[col], positions[kk].y + sz.height + this.padWidth);
31480 for (var i = 0; i < this.cols; i++){
31481 mY = Math.max(mY, maxY[i]);
31484 this.el.setHeight(mY - pos.y);
31488 // _processVerticalAlternativeLayoutQueue : function( items, isInstant )
31490 // var pos = this.el.getBox(true);
31493 // var maxX = pos.right;
31495 // var maxHeight = 0;
31497 // Roo.each(items, function(item, k){
31501 // item.el.position('absolute');
31503 // var width = Math.floor(this.colWidth + item.el.getPadding('lr'));
31505 // item.el.setWidth(width);
31507 // var height = Math.floor(this.colWidth * item.y / item.x + item.el.getPadding('tb'));
31509 // item.el.setHeight(height);
31512 // item.el.setXY([x, y], isInstant ? false : true);
31514 // item.el.setXY([maxX - width, y], isInstant ? false : true);
31517 // y = y + height + this.alternativePadWidth;
31519 // maxHeight = maxHeight + height + this.alternativePadWidth;
31523 // this.el.setHeight(maxHeight);
31527 _processHorizontalLayoutQueue : function( queue, eItems, isInstant )
31529 var pos = this.el.getBox(true);
31534 var maxX = pos.right;
31536 this._processHorizontalEndItem(eItems, maxX, minX, minY, isInstant);
31538 var maxX = maxX - this.unitWidth * 3 - this.gutter * 2 - this.padWidth;
31540 Roo.each(queue, function(box, k){
31542 Roo.each(box, function(b, kk){
31544 b.el.position('absolute');
31546 var width = Math.floor(this.unitWidth * b.x + (this.gutter * (b.x - 1)) + b.el.getPadding('lr'));
31547 var height = Math.floor(this.unitWidth * b.y + (this.gutter * (b.y - 1)) + b.el.getPadding('tb'));
31549 if(b.size == 'md-left' || b.size == 'md-right'){
31550 width = Math.floor(this.unitWidth * (b.x - 1) + (this.gutter * (b.x - 2)) + b.el.getPadding('lr'));
31551 height = Math.floor(this.unitWidth * (b.y - 1) + (this.gutter * (b.y - 2)) + b.el.getPadding('tb'));
31554 b.el.setWidth(width);
31555 b.el.setHeight(height);
31563 var positions = [];
31565 switch (box.length){
31567 positions = this.getHorizontalOneBoxColPositions(maxX, minY, box);
31570 positions = this.getHorizontalTwoBoxColPositions(maxX, minY, box);
31573 positions = this.getHorizontalThreeBoxColPositions(maxX, minY, box);
31576 positions = this.getHorizontalFourBoxColPositions(maxX, minY, box);
31582 Roo.each(box, function(b,kk){
31584 b.el.setXY([positions[kk].x, positions[kk].y], isInstant ? false : true);
31586 maxX = Math.min(maxX, positions[kk].x - this.padWidth);
31594 _processHorizontalEndItem : function(eItems, maxX, minX, minY, isInstant)
31596 Roo.each(eItems, function(b,k){
31598 b.size = (k == 0) ? 'sm' : 'xs';
31599 b.x = (k == 0) ? 2 : 1;
31600 b.y = (k == 0) ? 2 : 1;
31602 b.el.position('absolute');
31604 var width = Math.floor(this.unitWidth * b.x + (this.gutter * (b.x - 1)) + b.el.getPadding('lr'));
31606 b.el.setWidth(width);
31608 var height = Math.floor(this.unitWidth * b.y + (this.gutter * (b.y - 1)) + b.el.getPadding('tb'));
31610 b.el.setHeight(height);
31614 var positions = [];
31617 x : maxX - this.unitWidth * 2 - this.gutter,
31622 x : maxX - this.unitWidth,
31623 y : minY + (this.unitWidth + this.gutter) * 2
31627 x : maxX - this.unitWidth * 3 - this.gutter * 2,
31631 Roo.each(eItems, function(b,k){
31633 b.el.setXY([positions[k].x, positions[k].y], isInstant ? false : true);
31639 getVerticalOneBoxColPositions : function(x, y, box)
31643 var rand = Math.floor(Math.random() * ((4 - box[0].x)));
31645 if(box[0].size == 'md-left'){
31649 if(box[0].size == 'md-right'){
31654 x : x + (this.unitWidth + this.gutter) * rand,
31661 getVerticalTwoBoxColPositions : function(x, y, box)
31665 if(box[0].size == 'xs'){
31669 y : y + ((this.unitHeight + this.gutter) * Math.floor(Math.random() * box[1].y))
31673 x : x + (this.unitWidth + this.gutter) * (3 - box[1].x),
31687 x : x + (this.unitWidth + this.gutter) * 2,
31688 y : y + ((this.unitHeight + this.gutter) * Math.floor(Math.random() * box[0].y))
31695 getVerticalThreeBoxColPositions : function(x, y, box)
31699 if(box[0].size == 'xs' && box[1].size == 'xs' && box[2].size == 'xs'){
31707 x : x + (this.unitWidth + this.gutter) * 1,
31712 x : x + (this.unitWidth + this.gutter) * 2,
31720 if(box[0].size == 'xs' && box[1].size == 'xs'){
31729 y : y + ((this.unitHeight + this.gutter) * (box[2].y - 1))
31733 x : x + (this.unitWidth + this.gutter) * 1,
31747 x : x + (this.unitWidth + this.gutter) * 2,
31752 x : x + (this.unitWidth + this.gutter) * 2,
31753 y : y + (this.unitHeight + this.gutter) * (box[0].y - 1)
31760 getVerticalFourBoxColPositions : function(x, y, box)
31764 if(box[0].size == 'xs'){
31773 y : y + (this.unitHeight + this.gutter) * 1
31778 y : y + (this.unitHeight + this.gutter) * 2
31782 x : x + (this.unitWidth + this.gutter) * 1,
31796 x : x + (this.unitWidth + this.gutter) * 2,
31801 x : x + (this.unitHeightunitWidth + this.gutter) * 2,
31802 y : y + (this.unitHeight + this.gutter) * 1
31806 x : x + (this.unitWidth + this.gutter) * 2,
31807 y : y + (this.unitWidth + this.gutter) * 2
31814 getHorizontalOneBoxColPositions : function(maxX, minY, box)
31818 if(box[0].size == 'md-left'){
31820 x : maxX - this.unitWidth * (box[0].x - 1) - this.gutter * (box[0].x - 2),
31827 if(box[0].size == 'md-right'){
31829 x : maxX - this.unitWidth * (box[0].x - 1) - this.gutter * (box[0].x - 2),
31830 y : minY + (this.unitWidth + this.gutter) * 1
31836 var rand = Math.floor(Math.random() * (4 - box[0].y));
31839 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
31840 y : minY + (this.unitWidth + this.gutter) * rand
31847 getHorizontalTwoBoxColPositions : function(maxX, minY, box)
31851 if(box[0].size == 'xs'){
31854 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
31859 x : maxX - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1),
31860 y : minY + (this.unitWidth + this.gutter) * (3 - box[1].y)
31868 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
31873 x : maxX - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1),
31874 y : minY + (this.unitWidth + this.gutter) * 2
31881 getHorizontalThreeBoxColPositions : function(maxX, minY, box)
31885 if(box[0].size == 'xs' && box[1].size == 'xs' && box[2].size == 'xs'){
31888 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
31893 x : maxX - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1),
31894 y : minY + (this.unitWidth + this.gutter) * 1
31898 x : maxX - this.unitWidth * box[2].x - this.gutter * (box[2].x - 1),
31899 y : minY + (this.unitWidth + this.gutter) * 2
31906 if(box[0].size == 'xs' && box[1].size == 'xs'){
31909 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
31914 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1) - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1),
31919 x : maxX - this.unitWidth * box[2].x - this.gutter * (box[2].x - 1),
31920 y : minY + (this.unitWidth + this.gutter) * 1
31928 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
31933 x : maxX - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1),
31934 y : minY + (this.unitWidth + this.gutter) * 2
31938 x : maxX - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1) - this.unitWidth * box[2].x - this.gutter * (box[2].x - 1),
31939 y : minY + (this.unitWidth + this.gutter) * 2
31946 getHorizontalFourBoxColPositions : function(maxX, minY, box)
31950 if(box[0].size == 'xs'){
31953 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
31958 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1) - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1),
31963 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1) - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1) - this.unitWidth * box[2].x - this.gutter * (box[2].x - 1),
31968 x : maxX - this.unitWidth * box[3].x - this.gutter * (box[3].x - 1),
31969 y : minY + (this.unitWidth + this.gutter) * 1
31977 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
31982 x : maxX - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1),
31983 y : minY + (this.unitWidth + this.gutter) * 2
31987 x : maxX - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1) - this.unitWidth * box[2].x - this.gutter * (box[2].x - 1),
31988 y : minY + (this.unitWidth + this.gutter) * 2
31992 x : maxX - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1) - this.unitWidth * box[2].x - this.gutter * (box[2].x - 1) - this.unitWidth * box[3].x - this.gutter * (box[3].x - 1),
31993 y : minY + (this.unitWidth + this.gutter) * 2
32001 * remove a Masonry Brick
32002 * @param {Roo.bootstrap.MasonryBrick} the masonry brick to remove
32004 removeBrick : function(brick_id)
32010 for (var i = 0; i<this.bricks.length; i++) {
32011 if (this.bricks[i].id == brick_id) {
32012 this.bricks.splice(i,1);
32013 this.el.dom.removeChild(Roo.get(brick_id).dom);
32020 * adds a Masonry Brick
32021 * @param {Roo.bootstrap.MasonryBrick} the masonry brick to add
32023 addBrick : function(cfg)
32025 var cn = new Roo.bootstrap.MasonryBrick(cfg);
32026 //this.register(cn);
32027 cn.parentId = this.id;
32028 cn.render(this.el);
32033 * register a Masonry Brick
32034 * @param {Roo.bootstrap.MasonryBrick} the masonry brick to add
32037 register : function(brick)
32039 this.bricks.push(brick);
32040 brick.masonryId = this.id;
32044 * clear all the Masonry Brick
32046 clearAll : function()
32049 //this.getChildContainer().dom.innerHTML = "";
32050 this.el.dom.innerHTML = '';
32053 getSelected : function()
32055 if (!this.selectedBrick) {
32059 return this.selectedBrick;
32063 Roo.apply(Roo.bootstrap.LayoutMasonry, {
32067 * register a Masonry Layout
32068 * @param {Roo.bootstrap.LayoutMasonry} the masonry layout to add
32071 register : function(layout)
32073 this.groups[layout.id] = layout;
32076 * fetch a Masonry Layout based on the masonry layout ID
32077 * @param {string} the masonry layout to add
32078 * @returns {Roo.bootstrap.LayoutMasonry} the masonry layout
32081 get: function(layout_id) {
32082 if (typeof(this.groups[layout_id]) == 'undefined') {
32085 return this.groups[layout_id] ;
32097 * http://masonry.desandro.com
32099 * The idea is to render all the bricks based on vertical width...
32101 * The original code extends 'outlayer' - we might need to use that....
32107 * @class Roo.bootstrap.LayoutMasonryAuto
32108 * @extends Roo.bootstrap.Component
32109 * Bootstrap Layout Masonry class
32112 * Create a new Element
32113 * @param {Object} config The config object
32116 Roo.bootstrap.LayoutMasonryAuto = function(config){
32117 Roo.bootstrap.LayoutMasonryAuto.superclass.constructor.call(this, config);
32120 Roo.extend(Roo.bootstrap.LayoutMasonryAuto, Roo.bootstrap.Component, {
32123 * @cfg {Boolean} isFitWidth - resize the width..
32125 isFitWidth : false, // options..
32127 * @cfg {Boolean} isOriginLeft = left align?
32129 isOriginLeft : true,
32131 * @cfg {Boolean} isOriginTop = top align?
32133 isOriginTop : false,
32135 * @cfg {Boolean} isLayoutInstant = no animation?
32137 isLayoutInstant : false, // needed?
32139 * @cfg {Boolean} isResizingContainer = not sure if this is used..
32141 isResizingContainer : true,
32143 * @cfg {Number} columnWidth width of the columns
32149 * @cfg {Number} maxCols maximum number of columns
32154 * @cfg {Number} padHeight padding below box..
32160 * @cfg {Boolean} isAutoInitial defalut true
32163 isAutoInitial : true,
32169 initialColumnWidth : 0,
32170 currentSize : null,
32172 colYs : null, // array.
32179 bricks: null, //CompositeElement
32180 cols : 0, // array?
32181 // element : null, // wrapped now this.el
32182 _isLayoutInited : null,
32185 getAutoCreate : function(){
32189 cls: 'blog-masonary-wrapper ' + this.cls,
32191 cls : 'mas-boxes masonary'
32198 getChildContainer: function( )
32200 if (this.boxesEl) {
32201 return this.boxesEl;
32204 this.boxesEl = this.el.select('.mas-boxes').first();
32206 return this.boxesEl;
32210 initEvents : function()
32214 if(this.isAutoInitial){
32215 Roo.log('hook children rendered');
32216 this.on('childrenrendered', function() {
32217 Roo.log('children rendered');
32224 initial : function()
32226 this.reloadItems();
32228 this.currentSize = this.el.getBox(true);
32230 /// was window resize... - let's see if this works..
32231 Roo.EventManager.onWindowResize(this.resize, this);
32233 if(!this.isAutoInitial){
32238 this.layout.defer(500,this);
32241 reloadItems: function()
32243 this.bricks = this.el.select('.masonry-brick', true);
32245 this.bricks.each(function(b) {
32246 //Roo.log(b.getSize());
32247 if (!b.attr('originalwidth')) {
32248 b.attr('originalwidth', b.getSize().width);
32253 Roo.log(this.bricks.elements.length);
32256 resize : function()
32259 var cs = this.el.getBox(true);
32261 if (this.currentSize.width == cs.width && this.currentSize.x == cs.x ) {
32262 Roo.log("no change in with or X");
32265 this.currentSize = cs;
32269 layout : function()
32272 this._resetLayout();
32273 //this._manageStamps();
32275 // don't animate first layout
32276 var isInstant = this.isLayoutInstant !== undefined ? this.isLayoutInstant : !this._isLayoutInited;
32277 this.layoutItems( isInstant );
32279 // flag for initalized
32280 this._isLayoutInited = true;
32283 layoutItems : function( isInstant )
32285 //var items = this._getItemsForLayout( this.items );
32286 // original code supports filtering layout items.. we just ignore it..
32288 this._layoutItems( this.bricks , isInstant );
32290 this._postLayout();
32292 _layoutItems : function ( items , isInstant)
32294 //this.fireEvent( 'layout', this, items );
32297 if ( !items || !items.elements.length ) {
32298 // no items, emit event with empty array
32303 items.each(function(item) {
32304 Roo.log("layout item");
32306 // get x/y object from method
32307 var position = this._getItemLayoutPosition( item );
32309 position.item = item;
32310 position.isInstant = isInstant; // || item.isLayoutInstant; << not set yet...
32311 queue.push( position );
32314 this._processLayoutQueue( queue );
32316 /** Sets position of item in DOM
32317 * @param {Element} item
32318 * @param {Number} x - horizontal position
32319 * @param {Number} y - vertical position
32320 * @param {Boolean} isInstant - disables transitions
32322 _processLayoutQueue : function( queue )
32324 for ( var i=0, len = queue.length; i < len; i++ ) {
32325 var obj = queue[i];
32326 obj.item.position('absolute');
32327 obj.item.setXY([obj.x,obj.y], obj.isInstant ? false : true);
32333 * Any logic you want to do after each layout,
32334 * i.e. size the container
32336 _postLayout : function()
32338 this.resizeContainer();
32341 resizeContainer : function()
32343 if ( !this.isResizingContainer ) {
32346 var size = this._getContainerSize();
32348 this.el.setSize(size.width,size.height);
32349 this.boxesEl.setSize(size.width,size.height);
32355 _resetLayout : function()
32357 //this.getSize(); // -- does not really do anything.. it probably applies left/right etc. to obuject but not used
32358 this.colWidth = this.el.getWidth();
32359 //this.gutter = this.el.getWidth();
32361 this.measureColumns();
32367 this.colYs.push( 0 );
32373 measureColumns : function()
32375 this.getContainerWidth();
32376 // if columnWidth is 0, default to outerWidth of first item
32377 if ( !this.columnWidth ) {
32378 var firstItem = this.bricks.first();
32379 Roo.log(firstItem);
32380 this.columnWidth = this.containerWidth;
32381 if (firstItem && firstItem.attr('originalwidth') ) {
32382 this.columnWidth = 1* (firstItem.attr('originalwidth') || firstItem.getWidth());
32384 // columnWidth fall back to item of first element
32385 Roo.log("set column width?");
32386 this.initialColumnWidth = this.columnWidth ;
32388 // if first elem has no width, default to size of container
32393 if (this.initialColumnWidth) {
32394 this.columnWidth = this.initialColumnWidth;
32399 // column width is fixed at the top - however if container width get's smaller we should
32402 // this bit calcs how man columns..
32404 var columnWidth = this.columnWidth += this.gutter;
32406 // calculate columns
32407 var containerWidth = this.containerWidth + this.gutter;
32409 var cols = (containerWidth - this.padWidth) / (columnWidth - this.padWidth);
32410 // fix rounding errors, typically with gutters
32411 var excess = columnWidth - containerWidth % columnWidth;
32414 // if overshoot is less than a pixel, round up, otherwise floor it
32415 var mathMethod = excess && excess < 1 ? 'round' : 'floor';
32416 cols = Math[ mathMethod ]( cols );
32417 this.cols = Math.max( cols, 1 );
32418 this.cols = this.maxCols > 0 ? Math.min( this.cols, this.maxCols ) : this.cols;
32420 // padding positioning..
32421 var totalColWidth = this.cols * this.columnWidth;
32422 var padavail = this.containerWidth - totalColWidth;
32423 // so for 2 columns - we need 3 'pads'
32425 var padNeeded = (1+this.cols) * this.padWidth;
32427 var padExtra = Math.floor((padavail - padNeeded) / this.cols);
32429 this.columnWidth += padExtra
32430 //this.padWidth = Math.floor(padavail / ( this.cols));
32432 // adjust colum width so that padding is fixed??
32434 // we have 3 columns ... total = width * 3
32435 // we have X left over... that should be used by
32437 //if (this.expandC) {
32445 getContainerWidth : function()
32447 /* // container is parent if fit width
32448 var container = this.isFitWidth ? this.element.parentNode : this.element;
32449 // check that this.size and size are there
32450 // IE8 triggers resize on body size change, so they might not be
32452 var size = getSize( container ); //FIXME
32453 this.containerWidth = size && size.innerWidth; //FIXME
32456 this.containerWidth = this.el.getBox(true).width; //maybe use getComputedWidth
32460 _getItemLayoutPosition : function( item ) // what is item?
32462 // we resize the item to our columnWidth..
32464 item.setWidth(this.columnWidth);
32465 item.autoBoxAdjust = false;
32467 var sz = item.getSize();
32469 // how many columns does this brick span
32470 var remainder = this.containerWidth % this.columnWidth;
32472 var mathMethod = remainder && remainder < 1 ? 'round' : 'ceil';
32473 // round if off by 1 pixel, otherwise use ceil
32474 var colSpan = Math[ mathMethod ]( sz.width / this.columnWidth );
32475 colSpan = Math.min( colSpan, this.cols );
32477 // normally this should be '1' as we dont' currently allow multi width columns..
32479 var colGroup = this._getColGroup( colSpan );
32480 // get the minimum Y value from the columns
32481 var minimumY = Math.min.apply( Math, colGroup );
32482 Roo.log([ 'setHeight', minimumY, sz.height, setHeight ]);
32484 var shortColIndex = colGroup.indexOf( minimumY ); // broken on ie8..?? probably...
32486 // position the brick
32488 x: this.currentSize.x + (this.padWidth /2) + ((this.columnWidth + this.padWidth )* shortColIndex),
32489 y: this.currentSize.y + minimumY + this.padHeight
32493 // apply setHeight to necessary columns
32494 var setHeight = minimumY + sz.height + this.padHeight;
32495 //Roo.log([ 'setHeight', minimumY, sz.height, setHeight ]);
32497 var setSpan = this.cols + 1 - colGroup.length;
32498 for ( var i = 0; i < setSpan; i++ ) {
32499 this.colYs[ shortColIndex + i ] = setHeight ;
32506 * @param {Number} colSpan - number of columns the element spans
32507 * @returns {Array} colGroup
32509 _getColGroup : function( colSpan )
32511 if ( colSpan < 2 ) {
32512 // if brick spans only one column, use all the column Ys
32517 // how many different places could this brick fit horizontally
32518 var groupCount = this.cols + 1 - colSpan;
32519 // for each group potential horizontal position
32520 for ( var i = 0; i < groupCount; i++ ) {
32521 // make an array of colY values for that one group
32522 var groupColYs = this.colYs.slice( i, i + colSpan );
32523 // and get the max value of the array
32524 colGroup[i] = Math.max.apply( Math, groupColYs );
32529 _manageStamp : function( stamp )
32531 var stampSize = stamp.getSize();
32532 var offset = stamp.getBox();
32533 // get the columns that this stamp affects
32534 var firstX = this.isOriginLeft ? offset.x : offset.right;
32535 var lastX = firstX + stampSize.width;
32536 var firstCol = Math.floor( firstX / this.columnWidth );
32537 firstCol = Math.max( 0, firstCol );
32539 var lastCol = Math.floor( lastX / this.columnWidth );
32540 // lastCol should not go over if multiple of columnWidth #425
32541 lastCol -= lastX % this.columnWidth ? 0 : 1;
32542 lastCol = Math.min( this.cols - 1, lastCol );
32544 // set colYs to bottom of the stamp
32545 var stampMaxY = ( this.isOriginTop ? offset.y : offset.bottom ) +
32548 for ( var i = firstCol; i <= lastCol; i++ ) {
32549 this.colYs[i] = Math.max( stampMaxY, this.colYs[i] );
32554 _getContainerSize : function()
32556 this.maxY = Math.max.apply( Math, this.colYs );
32561 if ( this.isFitWidth ) {
32562 size.width = this._getContainerFitWidth();
32568 _getContainerFitWidth : function()
32570 var unusedCols = 0;
32571 // count unused columns
32574 if ( this.colYs[i] !== 0 ) {
32579 // fit container to columns that have been used
32580 return ( this.cols - unusedCols ) * this.columnWidth - this.gutter;
32583 needsResizeLayout : function()
32585 var previousWidth = this.containerWidth;
32586 this.getContainerWidth();
32587 return previousWidth !== this.containerWidth;
32602 * @class Roo.bootstrap.MasonryBrick
32603 * @extends Roo.bootstrap.Component
32604 * Bootstrap MasonryBrick class
32607 * Create a new MasonryBrick
32608 * @param {Object} config The config object
32611 Roo.bootstrap.MasonryBrick = function(config){
32613 Roo.bootstrap.MasonryBrick.superclass.constructor.call(this, config);
32615 Roo.bootstrap.MasonryBrick.register(this);
32621 * When a MasonryBrick is clcik
32622 * @param {Roo.bootstrap.MasonryBrick} this
32623 * @param {Roo.EventObject} e
32629 Roo.extend(Roo.bootstrap.MasonryBrick, Roo.bootstrap.Component, {
32632 * @cfg {String} title
32636 * @cfg {String} html
32640 * @cfg {String} bgimage
32644 * @cfg {String} videourl
32648 * @cfg {String} cls
32652 * @cfg {String} href
32656 * @cfg {String} size (xs|sm|md|md-left|md-right|tall|wide)
32661 * @cfg {String} placetitle (center|bottom)
32666 * @cfg {Boolean} isFitContainer defalut true
32668 isFitContainer : true,
32671 * @cfg {Boolean} preventDefault defalut false
32673 preventDefault : false,
32676 * @cfg {Boolean} inverse defalut false
32678 maskInverse : false,
32680 getAutoCreate : function()
32682 if(!this.isFitContainer){
32683 return this.getSplitAutoCreate();
32686 var cls = 'masonry-brick masonry-brick-full';
32688 if(this.href.length){
32689 cls += ' masonry-brick-link';
32692 if(this.bgimage.length){
32693 cls += ' masonry-brick-image';
32696 if(this.maskInverse){
32697 cls += ' mask-inverse';
32700 if(!this.html.length && !this.maskInverse && !this.videourl.length){
32701 cls += ' enable-mask';
32705 cls += ' masonry-' + this.size + '-brick';
32708 if(this.placetitle.length){
32710 switch (this.placetitle) {
32712 cls += ' masonry-center-title';
32715 cls += ' masonry-bottom-title';
32722 if(!this.html.length && !this.bgimage.length){
32723 cls += ' masonry-center-title';
32726 if(!this.html.length && this.bgimage.length){
32727 cls += ' masonry-bottom-title';
32732 cls += ' ' + this.cls;
32736 tag: (this.href.length) ? 'a' : 'div',
32741 cls: 'masonry-brick-mask'
32745 cls: 'masonry-brick-paragraph',
32751 if(this.href.length){
32752 cfg.href = this.href;
32755 var cn = cfg.cn[1].cn;
32757 if(this.title.length){
32760 cls: 'masonry-brick-title',
32765 if(this.html.length){
32768 cls: 'masonry-brick-text',
32773 if (!this.title.length && !this.html.length) {
32774 cfg.cn[1].cls += ' hide';
32777 if(this.bgimage.length){
32780 cls: 'masonry-brick-image-view',
32785 if(this.videourl.length){
32786 var vurl = this.videourl.replace(/https:\/\/youtu\.be/, 'https://www.youtube.com/embed/');
32787 // youtube support only?
32790 cls: 'masonry-brick-image-view',
32793 allowfullscreen : true
32801 getSplitAutoCreate : function()
32803 var cls = 'masonry-brick masonry-brick-split';
32805 if(this.href.length){
32806 cls += ' masonry-brick-link';
32809 if(this.bgimage.length){
32810 cls += ' masonry-brick-image';
32814 cls += ' masonry-' + this.size + '-brick';
32817 switch (this.placetitle) {
32819 cls += ' masonry-center-title';
32822 cls += ' masonry-bottom-title';
32825 if(!this.bgimage.length){
32826 cls += ' masonry-center-title';
32829 if(this.bgimage.length){
32830 cls += ' masonry-bottom-title';
32836 cls += ' ' + this.cls;
32840 tag: (this.href.length) ? 'a' : 'div',
32845 cls: 'masonry-brick-split-head',
32849 cls: 'masonry-brick-paragraph',
32856 cls: 'masonry-brick-split-body',
32862 if(this.href.length){
32863 cfg.href = this.href;
32866 if(this.title.length){
32867 cfg.cn[0].cn[0].cn.push({
32869 cls: 'masonry-brick-title',
32874 if(this.html.length){
32875 cfg.cn[1].cn.push({
32877 cls: 'masonry-brick-text',
32882 if(this.bgimage.length){
32883 cfg.cn[0].cn.push({
32885 cls: 'masonry-brick-image-view',
32890 if(this.videourl.length){
32891 var vurl = this.videourl.replace(/https:\/\/youtu\.be/, 'https://www.youtube.com/embed/');
32892 // youtube support only?
32893 cfg.cn[0].cn.cn.push({
32895 cls: 'masonry-brick-image-view',
32898 allowfullscreen : true
32905 initEvents: function()
32907 switch (this.size) {
32940 this.el.on('touchstart', this.onTouchStart, this);
32941 this.el.on('touchmove', this.onTouchMove, this);
32942 this.el.on('touchend', this.onTouchEnd, this);
32943 this.el.on('contextmenu', this.onContextMenu, this);
32945 this.el.on('mouseenter' ,this.enter, this);
32946 this.el.on('mouseleave', this.leave, this);
32947 this.el.on('click', this.onClick, this);
32950 if (typeof(this.parent().bricks) == 'object' && this.parent().bricks != null) {
32951 this.parent().bricks.push(this);
32956 onClick: function(e, el)
32958 var time = this.endTimer - this.startTimer;
32959 // Roo.log(e.preventDefault());
32962 e.preventDefault();
32967 if(!this.preventDefault){
32971 e.preventDefault();
32973 if (this.activeClass != '') {
32974 this.selectBrick();
32977 this.fireEvent('click', this, e);
32980 enter: function(e, el)
32982 e.preventDefault();
32984 if(!this.isFitContainer || this.maskInverse || this.videourl.length){
32988 if(this.bgimage.length && this.html.length){
32989 this.el.select('.masonry-brick-paragraph', true).first().setOpacity(0.9, true);
32993 leave: function(e, el)
32995 e.preventDefault();
32997 if(!this.isFitContainer || this.maskInverse || this.videourl.length){
33001 if(this.bgimage.length && this.html.length){
33002 this.el.select('.masonry-brick-paragraph', true).first().setOpacity(0, true);
33006 onTouchStart: function(e, el)
33008 // e.preventDefault();
33010 this.touchmoved = false;
33012 if(!this.isFitContainer){
33016 if(!this.bgimage.length || !this.html.length){
33020 this.el.select('.masonry-brick-paragraph', true).first().setOpacity(0.9, true);
33022 this.timer = new Date().getTime();
33026 onTouchMove: function(e, el)
33028 this.touchmoved = true;
33031 onContextMenu : function(e,el)
33033 e.preventDefault();
33034 e.stopPropagation();
33038 onTouchEnd: function(e, el)
33040 // e.preventDefault();
33042 if((new Date().getTime() - this.timer > 1000) || !this.href.length || this.touchmoved){
33049 if(!this.bgimage.length || !this.html.length){
33051 if(this.href.length){
33052 window.location.href = this.href;
33058 if(!this.isFitContainer){
33062 this.el.select('.masonry-brick-paragraph', true).first().setOpacity(0, true);
33064 window.location.href = this.href;
33067 //selection on single brick only
33068 selectBrick : function() {
33070 if (!this.parentId) {
33074 var m = Roo.bootstrap.LayoutMasonry.get(this.parentId);
33075 var index = m.selectedBrick.indexOf(this.id);
33078 m.selectedBrick.splice(index,1);
33079 this.el.removeClass(this.activeClass);
33083 for(var i = 0; i < m.selectedBrick.length; i++) {
33084 var b = Roo.bootstrap.MasonryBrick.get(m.selectedBrick[i]);
33085 b.el.removeClass(b.activeClass);
33088 m.selectedBrick = [];
33090 m.selectedBrick.push(this.id);
33091 this.el.addClass(this.activeClass);
33095 isSelected : function(){
33096 return this.el.hasClass(this.activeClass);
33101 Roo.apply(Roo.bootstrap.MasonryBrick, {
33104 groups : new Roo.util.MixedCollection(false, function(o) { return o.el.id; }),
33106 * register a Masonry Brick
33107 * @param {Roo.bootstrap.MasonryBrick} the masonry brick to add
33110 register : function(brick)
33112 //this.groups[brick.id] = brick;
33113 this.groups.add(brick.id, brick);
33116 * fetch a masonry brick based on the masonry brick ID
33117 * @param {string} the masonry brick to add
33118 * @returns {Roo.bootstrap.MasonryBrick} the masonry brick
33121 get: function(brick_id)
33123 // if (typeof(this.groups[brick_id]) == 'undefined') {
33126 // return this.groups[brick_id] ;
33128 if(this.groups.key(brick_id)) {
33129 return this.groups.key(brick_id);
33147 * @class Roo.bootstrap.Brick
33148 * @extends Roo.bootstrap.Component
33149 * Bootstrap Brick class
33152 * Create a new Brick
33153 * @param {Object} config The config object
33156 Roo.bootstrap.Brick = function(config){
33157 Roo.bootstrap.Brick.superclass.constructor.call(this, config);
33163 * When a Brick is click
33164 * @param {Roo.bootstrap.Brick} this
33165 * @param {Roo.EventObject} e
33171 Roo.extend(Roo.bootstrap.Brick, Roo.bootstrap.Component, {
33174 * @cfg {String} title
33178 * @cfg {String} html
33182 * @cfg {String} bgimage
33186 * @cfg {String} cls
33190 * @cfg {String} href
33194 * @cfg {String} video
33198 * @cfg {Boolean} square
33202 getAutoCreate : function()
33204 var cls = 'roo-brick';
33206 if(this.href.length){
33207 cls += ' roo-brick-link';
33210 if(this.bgimage.length){
33211 cls += ' roo-brick-image';
33214 if(!this.html.length && !this.bgimage.length){
33215 cls += ' roo-brick-center-title';
33218 if(!this.html.length && this.bgimage.length){
33219 cls += ' roo-brick-bottom-title';
33223 cls += ' ' + this.cls;
33227 tag: (this.href.length) ? 'a' : 'div',
33232 cls: 'roo-brick-paragraph',
33238 if(this.href.length){
33239 cfg.href = this.href;
33242 var cn = cfg.cn[0].cn;
33244 if(this.title.length){
33247 cls: 'roo-brick-title',
33252 if(this.html.length){
33255 cls: 'roo-brick-text',
33262 if(this.bgimage.length){
33265 cls: 'roo-brick-image-view',
33273 initEvents: function()
33275 if(this.title.length || this.html.length){
33276 this.el.on('mouseenter' ,this.enter, this);
33277 this.el.on('mouseleave', this.leave, this);
33280 Roo.EventManager.onWindowResize(this.resize, this);
33282 if(this.bgimage.length){
33283 this.imageEl = this.el.select('.roo-brick-image-view', true).first();
33284 this.imageEl.on('load', this.onImageLoad, this);
33291 onImageLoad : function()
33296 resize : function()
33298 var paragraph = this.el.select('.roo-brick-paragraph', true).first();
33300 paragraph.setHeight(paragraph.getWidth() + paragraph.getPadding('tb'));
33302 if(this.bgimage.length){
33303 var image = this.el.select('.roo-brick-image-view', true).first();
33305 image.setWidth(paragraph.getWidth());
33308 image.setHeight(paragraph.getWidth());
33311 this.el.setHeight(image.getHeight());
33312 paragraph.setHeight(image.getHeight());
33318 enter: function(e, el)
33320 e.preventDefault();
33322 if(this.bgimage.length){
33323 this.el.select('.roo-brick-paragraph', true).first().setOpacity(0.9, true);
33324 this.el.select('.roo-brick-image-view', true).first().setOpacity(0.1, true);
33328 leave: function(e, el)
33330 e.preventDefault();
33332 if(this.bgimage.length){
33333 this.el.select('.roo-brick-paragraph', true).first().setOpacity(0, true);
33334 this.el.select('.roo-brick-image-view', true).first().setOpacity(1, true);
33349 * @class Roo.bootstrap.NumberField
33350 * @extends Roo.bootstrap.Input
33351 * Bootstrap NumberField class
33357 * Create a new NumberField
33358 * @param {Object} config The config object
33361 Roo.bootstrap.NumberField = function(config){
33362 Roo.bootstrap.NumberField.superclass.constructor.call(this, config);
33365 Roo.extend(Roo.bootstrap.NumberField, Roo.bootstrap.Input, {
33368 * @cfg {Boolean} allowDecimals False to disallow decimal values (defaults to true)
33370 allowDecimals : true,
33372 * @cfg {String} decimalSeparator Character(s) to allow as the decimal separator (defaults to '.')
33374 decimalSeparator : ".",
33376 * @cfg {Number} decimalPrecision The maximum precision to display after the decimal separator (defaults to 2)
33378 decimalPrecision : 2,
33380 * @cfg {Boolean} allowNegative False to prevent entering a negative sign (defaults to true)
33382 allowNegative : true,
33385 * @cfg {Boolean} allowZero False to blank out if the user enters '0' (defaults to true)
33389 * @cfg {Number} minValue The minimum allowed value (defaults to Number.NEGATIVE_INFINITY)
33391 minValue : Number.NEGATIVE_INFINITY,
33393 * @cfg {Number} maxValue The maximum allowed value (defaults to Number.MAX_VALUE)
33395 maxValue : Number.MAX_VALUE,
33397 * @cfg {String} minText Error text to display if the minimum value validation fails (defaults to "The minimum value for this field is {minValue}")
33399 minText : "The minimum value for this field is {0}",
33401 * @cfg {String} maxText Error text to display if the maximum value validation fails (defaults to "The maximum value for this field is {maxValue}")
33403 maxText : "The maximum value for this field is {0}",
33405 * @cfg {String} nanText Error text to display if the value is not a valid number. For example, this can happen
33406 * if a valid character like '.' or '-' is left in the field with no number (defaults to "{value} is not a valid number")
33408 nanText : "{0} is not a valid number",
33410 * @cfg {String} thousandsDelimiter Symbol of thousandsDelimiter
33412 thousandsDelimiter : false,
33414 * @cfg {String} valueAlign alignment of value
33416 valueAlign : "left",
33418 getAutoCreate : function()
33420 var hiddenInput = {
33424 cls: 'hidden-number-input'
33428 hiddenInput.name = this.name;
33433 var cfg = Roo.bootstrap.NumberField.superclass.getAutoCreate.call(this);
33435 this.name = hiddenInput.name;
33437 if(cfg.cn.length > 0) {
33438 cfg.cn.push(hiddenInput);
33445 initEvents : function()
33447 Roo.bootstrap.NumberField.superclass.initEvents.call(this);
33449 var allowed = "0123456789";
33451 if(this.allowDecimals){
33452 allowed += this.decimalSeparator;
33455 if(this.allowNegative){
33459 if(this.thousandsDelimiter) {
33463 this.stripCharsRe = new RegExp('[^'+allowed+']', 'gi');
33465 var keyPress = function(e){
33467 var k = e.getKey();
33469 var c = e.getCharCode();
33472 (String.fromCharCode(c) == '.' || String.fromCharCode(c) == '-') &&
33473 allowed.indexOf(String.fromCharCode(c)) === -1
33479 if(!Roo.isIE && (e.isSpecialKey() || k == e.BACKSPACE || k == e.DELETE)){
33483 if(allowed.indexOf(String.fromCharCode(c)) === -1){
33488 this.el.on("keypress", keyPress, this);
33491 validateValue : function(value)
33494 if(!Roo.bootstrap.NumberField.superclass.validateValue.call(this, value)){
33498 var num = this.parseValue(value);
33501 this.markInvalid(String.format(this.nanText, value));
33505 if(num < this.minValue){
33506 this.markInvalid(String.format(this.minText, this.minValue));
33510 if(num > this.maxValue){
33511 this.markInvalid(String.format(this.maxText, this.maxValue));
33518 getValue : function()
33520 var v = this.hiddenEl().getValue();
33522 return this.fixPrecision(this.parseValue(v));
33525 parseValue : function(value)
33527 if(this.thousandsDelimiter) {
33529 r = new RegExp(",", "g");
33530 value = value.replace(r, "");
33533 value = parseFloat(String(value).replace(this.decimalSeparator, "."));
33534 return isNaN(value) ? '' : value;
33537 fixPrecision : function(value)
33539 if(this.thousandsDelimiter) {
33541 r = new RegExp(",", "g");
33542 value = value.replace(r, "");
33545 var nan = isNaN(value);
33547 if(!this.allowDecimals || this.decimalPrecision == -1 || nan || !value){
33548 return nan ? '' : value;
33550 return parseFloat(value).toFixed(this.decimalPrecision);
33553 setValue : function(v)
33555 v = String(this.fixPrecision(v)).replace(".", this.decimalSeparator);
33561 this.hiddenEl().dom.value = (v === null || v === undefined ? '' : v);
33563 this.inputEl().dom.value = (v == '') ? '' :
33564 Roo.util.Format.number(v, this.decimalPrecision, this.thousandsDelimiter || '');
33566 if(!this.allowZero && v === '0') {
33567 this.hiddenEl().dom.value = '';
33568 this.inputEl().dom.value = '';
33575 decimalPrecisionFcn : function(v)
33577 return Math.floor(v);
33580 beforeBlur : function()
33582 var v = this.parseValue(this.getRawValue());
33584 if(v || v === 0 || v === ''){
33589 hiddenEl : function()
33591 return this.el.select('input.hidden-number-input',true).first();
33603 * @class Roo.bootstrap.DocumentSlider
33604 * @extends Roo.bootstrap.Component
33605 * Bootstrap DocumentSlider class
33608 * Create a new DocumentViewer
33609 * @param {Object} config The config object
33612 Roo.bootstrap.DocumentSlider = function(config){
33613 Roo.bootstrap.DocumentSlider.superclass.constructor.call(this, config);
33620 * Fire after initEvent
33621 * @param {Roo.bootstrap.DocumentSlider} this
33626 * Fire after update
33627 * @param {Roo.bootstrap.DocumentSlider} this
33633 * @param {Roo.bootstrap.DocumentSlider} this
33639 Roo.extend(Roo.bootstrap.DocumentSlider, Roo.bootstrap.Component, {
33645 getAutoCreate : function()
33649 cls : 'roo-document-slider',
33653 cls : 'roo-document-slider-header',
33657 cls : 'roo-document-slider-header-title'
33663 cls : 'roo-document-slider-body',
33667 cls : 'roo-document-slider-prev',
33671 cls : 'fa fa-chevron-left'
33677 cls : 'roo-document-slider-thumb',
33681 cls : 'roo-document-slider-image'
33687 cls : 'roo-document-slider-next',
33691 cls : 'fa fa-chevron-right'
33703 initEvents : function()
33705 this.headerEl = this.el.select('.roo-document-slider-header', true).first();
33706 this.headerEl.setVisibilityMode(Roo.Element.DISPLAY);
33708 this.titleEl = this.el.select('.roo-document-slider-header .roo-document-slider-header-title', true).first();
33709 this.titleEl.setVisibilityMode(Roo.Element.DISPLAY);
33711 this.bodyEl = this.el.select('.roo-document-slider-body', true).first();
33712 this.bodyEl.setVisibilityMode(Roo.Element.DISPLAY);
33714 this.thumbEl = this.el.select('.roo-document-slider-thumb', true).first();
33715 this.thumbEl.setVisibilityMode(Roo.Element.DISPLAY);
33717 this.imageEl = this.el.select('.roo-document-slider-image', true).first();
33718 this.imageEl.setVisibilityMode(Roo.Element.DISPLAY);
33720 this.prevIndicator = this.el.select('.roo-document-slider-prev i', true).first();
33721 this.prevIndicator.setVisibilityMode(Roo.Element.DISPLAY);
33723 this.nextIndicator = this.el.select('.roo-document-slider-next i', true).first();
33724 this.nextIndicator.setVisibilityMode(Roo.Element.DISPLAY);
33726 this.thumbEl.on('click', this.onClick, this);
33728 this.prevIndicator.on('click', this.prev, this);
33730 this.nextIndicator.on('click', this.next, this);
33734 initial : function()
33736 if(this.files.length){
33737 this.indicator = 1;
33741 this.fireEvent('initial', this);
33744 update : function()
33746 this.imageEl.attr('src', this.files[this.indicator - 1]);
33748 this.titleEl.dom.innerHTML = String.format('{0} / {1}', this.indicator, this.files.length);
33750 this.prevIndicator.show();
33752 if(this.indicator == 1){
33753 this.prevIndicator.hide();
33756 this.nextIndicator.show();
33758 if(this.indicator == this.files.length){
33759 this.nextIndicator.hide();
33762 this.thumbEl.scrollTo('top');
33764 this.fireEvent('update', this);
33767 onClick : function(e)
33769 e.preventDefault();
33771 this.fireEvent('click', this);
33776 e.preventDefault();
33778 this.indicator = Math.max(1, this.indicator - 1);
33785 e.preventDefault();
33787 this.indicator = Math.min(this.files.length, this.indicator + 1);
33801 * @class Roo.bootstrap.RadioSet
33802 * @extends Roo.bootstrap.Input
33803 * Bootstrap RadioSet class
33804 * @cfg {String} indicatorpos (left|right) default left
33805 * @cfg {Boolean} inline (true|false) inline the element (default true)
33806 * @cfg {String} weight (primary|warning|info|danger|success) The text that appears beside the radio
33808 * Create a new RadioSet
33809 * @param {Object} config The config object
33812 Roo.bootstrap.RadioSet = function(config){
33814 Roo.bootstrap.RadioSet.superclass.constructor.call(this, config);
33818 Roo.bootstrap.RadioSet.register(this);
33823 * Fires when the element is checked or unchecked.
33824 * @param {Roo.bootstrap.RadioSet} this This radio
33825 * @param {Roo.bootstrap.Radio} item The checked item
33830 * Fires when the element is click.
33831 * @param {Roo.bootstrap.RadioSet} this This radio set
33832 * @param {Roo.bootstrap.Radio} item The checked item
33833 * @param {Roo.EventObject} e The event object
33840 Roo.extend(Roo.bootstrap.RadioSet, Roo.bootstrap.Input, {
33848 indicatorpos : 'left',
33850 getAutoCreate : function()
33854 cls : 'roo-radio-set-label',
33858 html : this.fieldLabel
33863 if(this.indicatorpos == 'left'){
33866 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
33867 tooltip : 'This field is required'
33872 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
33873 tooltip : 'This field is required'
33879 cls : 'roo-radio-set-items'
33882 var align = (!this.labelAlign) ? this.parentLabelAlign() : this.labelAlign;
33884 if (align === 'left' && this.fieldLabel.length) {
33887 cls : "roo-radio-set-right",
33893 if(this.labelWidth > 12){
33894 label.style = "width: " + this.labelWidth + 'px';
33897 if(this.labelWidth < 13 && this.labelmd == 0){
33898 this.labelmd = this.labelWidth;
33901 if(this.labellg > 0){
33902 label.cls += ' col-lg-' + this.labellg;
33903 items.cls += ' col-lg-' + (12 - this.labellg);
33906 if(this.labelmd > 0){
33907 label.cls += ' col-md-' + this.labelmd;
33908 items.cls += ' col-md-' + (12 - this.labelmd);
33911 if(this.labelsm > 0){
33912 label.cls += ' col-sm-' + this.labelsm;
33913 items.cls += ' col-sm-' + (12 - this.labelsm);
33916 if(this.labelxs > 0){
33917 label.cls += ' col-xs-' + this.labelxs;
33918 items.cls += ' col-xs-' + (12 - this.labelxs);
33924 cls : 'roo-radio-set',
33928 cls : 'roo-radio-set-input',
33931 value : this.value ? this.value : ''
33938 if(this.weight.length){
33939 cfg.cls += ' roo-radio-' + this.weight;
33943 cfg.cls += ' roo-radio-set-inline';
33947 ['xs','sm','md','lg'].map(function(size){
33948 if (settings[size]) {
33949 cfg.cls += ' col-' + size + '-' + settings[size];
33957 initEvents : function()
33959 this.labelEl = this.el.select('.roo-radio-set-label', true).first();
33960 this.labelEl.setVisibilityMode(Roo.Element.DISPLAY);
33962 if(!this.fieldLabel.length){
33963 this.labelEl.hide();
33966 this.itemsEl = this.el.select('.roo-radio-set-items', true).first();
33967 this.itemsEl.setVisibilityMode(Roo.Element.DISPLAY);
33969 this.indicator = this.indicatorEl();
33971 if(this.indicator){
33972 this.indicator.addClass('invisible');
33975 this.originalValue = this.getValue();
33979 inputEl: function ()
33981 return this.el.select('.roo-radio-set-input', true).first();
33984 getChildContainer : function()
33986 return this.itemsEl;
33989 register : function(item)
33991 this.radioes.push(item);
33995 validate : function()
33997 if(this.getVisibilityEl().hasClass('hidden')){
34003 Roo.each(this.radioes, function(i){
34012 if(this.allowBlank) {
34016 if(this.disabled || valid){
34021 this.markInvalid();
34026 markValid : function()
34028 if(this.labelEl.isVisible(true)){
34029 this.indicatorEl().removeClass('visible');
34030 this.indicatorEl().addClass('invisible');
34033 this.el.removeClass([this.invalidClass, this.validClass]);
34034 this.el.addClass(this.validClass);
34036 this.fireEvent('valid', this);
34039 markInvalid : function(msg)
34041 if(this.allowBlank || this.disabled){
34045 if(this.labelEl.isVisible(true)){
34046 this.indicatorEl().removeClass('invisible');
34047 this.indicatorEl().addClass('visible');
34050 this.el.removeClass([this.invalidClass, this.validClass]);
34051 this.el.addClass(this.invalidClass);
34053 this.fireEvent('invalid', this, msg);
34057 setValue : function(v, suppressEvent)
34059 if(this.value === v){
34066 this.inputEl().dom.value = (v === null || v === undefined ? '' : v);
34069 Roo.each(this.radioes, function(i){
34071 i.el.removeClass('checked');
34074 Roo.each(this.radioes, function(i){
34076 if(i.value === v || i.value.toString() === v.toString()){
34078 i.el.addClass('checked');
34080 if(suppressEvent !== true){
34081 this.fireEvent('check', this, i);
34092 clearInvalid : function(){
34094 if(!this.el || this.preventMark){
34098 this.el.removeClass([this.invalidClass]);
34100 this.fireEvent('valid', this);
34105 Roo.apply(Roo.bootstrap.RadioSet, {
34109 register : function(set)
34111 this.groups[set.name] = set;
34114 get: function(name)
34116 if (typeof(this.groups[name]) == 'undefined') {
34120 return this.groups[name] ;
34126 * Ext JS Library 1.1.1
34127 * Copyright(c) 2006-2007, Ext JS, LLC.
34129 * Originally Released Under LGPL - original licence link has changed is not relivant.
34132 * <script type="text/javascript">
34137 * @class Roo.bootstrap.SplitBar
34138 * @extends Roo.util.Observable
34139 * Creates draggable splitter bar functionality from two elements (element to be dragged and element to be resized).
34143 var split = new Roo.bootstrap.SplitBar("elementToDrag", "elementToSize",
34144 Roo.bootstrap.SplitBar.HORIZONTAL, Roo.bootstrap.SplitBar.LEFT);
34145 split.setAdapter(new Roo.bootstrap.SplitBar.AbsoluteLayoutAdapter("container"));
34146 split.minSize = 100;
34147 split.maxSize = 600;
34148 split.animate = true;
34149 split.on('moved', splitterMoved);
34152 * Create a new SplitBar
34153 * @config {String/HTMLElement/Roo.Element} dragElement The element to be dragged and act as the SplitBar.
34154 * @config {String/HTMLElement/Roo.Element} resizingElement The element to be resized based on where the SplitBar element is dragged
34155 * @config {Number} orientation (optional) Either Roo.bootstrap.SplitBar.HORIZONTAL or Roo.bootstrap.SplitBar.VERTICAL. (Defaults to HORIZONTAL)
34156 * @config {Number} placement (optional) Either Roo.bootstrap.SplitBar.LEFT or Roo.bootstrap.SplitBar.RIGHT for horizontal or
34157 Roo.bootstrap.SplitBar.TOP or Roo.bootstrap.SplitBar.BOTTOM for vertical. (By default, this is determined automatically by the initial
34158 position of the SplitBar).
34160 Roo.bootstrap.SplitBar = function(cfg){
34165 // dragElement : elm
34166 // resizingElement: el,
34168 // orientation : Either Roo.bootstrap.SplitBar.HORIZONTAL
34169 // placement : Roo.bootstrap.SplitBar.LEFT ,
34170 // existingProxy ???
34173 this.el = Roo.get(cfg.dragElement, true);
34174 this.el.dom.unselectable = "on";
34176 this.resizingEl = Roo.get(cfg.resizingElement, true);
34180 * The orientation of the split. Either Roo.bootstrap.SplitBar.HORIZONTAL or Roo.bootstrap.SplitBar.VERTICAL. (Defaults to HORIZONTAL)
34181 * Note: If this is changed after creating the SplitBar, the placement property must be manually updated
34184 this.orientation = cfg.orientation || Roo.bootstrap.SplitBar.HORIZONTAL;
34187 * The minimum size of the resizing element. (Defaults to 0)
34193 * The maximum size of the resizing element. (Defaults to 2000)
34196 this.maxSize = 2000;
34199 * Whether to animate the transition to the new size
34202 this.animate = false;
34205 * Whether to create a transparent shim that overlays the page when dragging, enables dragging across iframes.
34208 this.useShim = false;
34213 if(!cfg.existingProxy){
34215 this.proxy = Roo.bootstrap.SplitBar.createProxy(this.orientation);
34217 this.proxy = Roo.get(cfg.existingProxy).dom;
34220 this.dd = new Roo.dd.DDProxy(this.el.dom.id, "XSplitBars", {dragElId : this.proxy.id});
34223 this.dd.b4StartDrag = this.onStartProxyDrag.createDelegate(this);
34226 this.dd.endDrag = this.onEndProxyDrag.createDelegate(this);
34229 this.dragSpecs = {};
34232 * @private The adapter to use to positon and resize elements
34234 this.adapter = new Roo.bootstrap.SplitBar.BasicLayoutAdapter();
34235 this.adapter.init(this);
34237 if(this.orientation == Roo.bootstrap.SplitBar.HORIZONTAL){
34239 this.placement = cfg.placement || (this.el.getX() > this.resizingEl.getX() ? Roo.bootstrap.SplitBar.LEFT : Roo.bootstrap.SplitBar.RIGHT);
34240 this.el.addClass("roo-splitbar-h");
34243 this.placement = cfg.placement || (this.el.getY() > this.resizingEl.getY() ? Roo.bootstrap.SplitBar.TOP : Roo.bootstrap.SplitBar.BOTTOM);
34244 this.el.addClass("roo-splitbar-v");
34250 * Fires when the splitter is moved (alias for {@link #event-moved})
34251 * @param {Roo.bootstrap.SplitBar} this
34252 * @param {Number} newSize the new width or height
34257 * Fires when the splitter is moved
34258 * @param {Roo.bootstrap.SplitBar} this
34259 * @param {Number} newSize the new width or height
34263 * @event beforeresize
34264 * Fires before the splitter is dragged
34265 * @param {Roo.bootstrap.SplitBar} this
34267 "beforeresize" : true,
34269 "beforeapply" : true
34272 Roo.util.Observable.call(this);
34275 Roo.extend(Roo.bootstrap.SplitBar, Roo.util.Observable, {
34276 onStartProxyDrag : function(x, y){
34277 this.fireEvent("beforeresize", this);
34279 var o = Roo.DomHelper.insertFirst(document.body, {cls: "roo-drag-overlay", html: " "}, true);
34281 o.enableDisplayMode("block");
34282 // all splitbars share the same overlay
34283 Roo.bootstrap.SplitBar.prototype.overlay = o;
34285 this.overlay.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
34286 this.overlay.show();
34287 Roo.get(this.proxy).setDisplayed("block");
34288 var size = this.adapter.getElementSize(this);
34289 this.activeMinSize = this.getMinimumSize();;
34290 this.activeMaxSize = this.getMaximumSize();;
34291 var c1 = size - this.activeMinSize;
34292 var c2 = Math.max(this.activeMaxSize - size, 0);
34293 if(this.orientation == Roo.bootstrap.SplitBar.HORIZONTAL){
34294 this.dd.resetConstraints();
34295 this.dd.setXConstraint(
34296 this.placement == Roo.bootstrap.SplitBar.LEFT ? c1 : c2,
34297 this.placement == Roo.bootstrap.SplitBar.LEFT ? c2 : c1
34299 this.dd.setYConstraint(0, 0);
34301 this.dd.resetConstraints();
34302 this.dd.setXConstraint(0, 0);
34303 this.dd.setYConstraint(
34304 this.placement == Roo.bootstrap.SplitBar.TOP ? c1 : c2,
34305 this.placement == Roo.bootstrap.SplitBar.TOP ? c2 : c1
34308 this.dragSpecs.startSize = size;
34309 this.dragSpecs.startPoint = [x, y];
34310 Roo.dd.DDProxy.prototype.b4StartDrag.call(this.dd, x, y);
34314 * @private Called after the drag operation by the DDProxy
34316 onEndProxyDrag : function(e){
34317 Roo.get(this.proxy).setDisplayed(false);
34318 var endPoint = Roo.lib.Event.getXY(e);
34320 this.overlay.hide();
34323 if(this.orientation == Roo.bootstrap.SplitBar.HORIZONTAL){
34324 newSize = this.dragSpecs.startSize +
34325 (this.placement == Roo.bootstrap.SplitBar.LEFT ?
34326 endPoint[0] - this.dragSpecs.startPoint[0] :
34327 this.dragSpecs.startPoint[0] - endPoint[0]
34330 newSize = this.dragSpecs.startSize +
34331 (this.placement == Roo.bootstrap.SplitBar.TOP ?
34332 endPoint[1] - this.dragSpecs.startPoint[1] :
34333 this.dragSpecs.startPoint[1] - endPoint[1]
34336 newSize = Math.min(Math.max(newSize, this.activeMinSize), this.activeMaxSize);
34337 if(newSize != this.dragSpecs.startSize){
34338 if(this.fireEvent('beforeapply', this, newSize) !== false){
34339 this.adapter.setElementSize(this, newSize);
34340 this.fireEvent("moved", this, newSize);
34341 this.fireEvent("resize", this, newSize);
34347 * Get the adapter this SplitBar uses
34348 * @return The adapter object
34350 getAdapter : function(){
34351 return this.adapter;
34355 * Set the adapter this SplitBar uses
34356 * @param {Object} adapter A SplitBar adapter object
34358 setAdapter : function(adapter){
34359 this.adapter = adapter;
34360 this.adapter.init(this);
34364 * Gets the minimum size for the resizing element
34365 * @return {Number} The minimum size
34367 getMinimumSize : function(){
34368 return this.minSize;
34372 * Sets the minimum size for the resizing element
34373 * @param {Number} minSize The minimum size
34375 setMinimumSize : function(minSize){
34376 this.minSize = minSize;
34380 * Gets the maximum size for the resizing element
34381 * @return {Number} The maximum size
34383 getMaximumSize : function(){
34384 return this.maxSize;
34388 * Sets the maximum size for the resizing element
34389 * @param {Number} maxSize The maximum size
34391 setMaximumSize : function(maxSize){
34392 this.maxSize = maxSize;
34396 * Sets the initialize size for the resizing element
34397 * @param {Number} size The initial size
34399 setCurrentSize : function(size){
34400 var oldAnimate = this.animate;
34401 this.animate = false;
34402 this.adapter.setElementSize(this, size);
34403 this.animate = oldAnimate;
34407 * Destroy this splitbar.
34408 * @param {Boolean} removeEl True to remove the element
34410 destroy : function(removeEl){
34412 this.shim.remove();
34415 this.proxy.parentNode.removeChild(this.proxy);
34423 * @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.
34425 Roo.bootstrap.SplitBar.createProxy = function(dir){
34426 var proxy = new Roo.Element(document.createElement("div"));
34427 proxy.unselectable();
34428 var cls = 'roo-splitbar-proxy';
34429 proxy.addClass(cls + ' ' + (dir == Roo.bootstrap.SplitBar.HORIZONTAL ? cls +'-h' : cls + '-v'));
34430 document.body.appendChild(proxy.dom);
34435 * @class Roo.bootstrap.SplitBar.BasicLayoutAdapter
34436 * Default Adapter. It assumes the splitter and resizing element are not positioned
34437 * elements and only gets/sets the width of the element. Generally used for table based layouts.
34439 Roo.bootstrap.SplitBar.BasicLayoutAdapter = function(){
34442 Roo.bootstrap.SplitBar.BasicLayoutAdapter.prototype = {
34443 // do nothing for now
34444 init : function(s){
34448 * Called before drag operations to get the current size of the resizing element.
34449 * @param {Roo.bootstrap.SplitBar} s The SplitBar using this adapter
34451 getElementSize : function(s){
34452 if(s.orientation == Roo.bootstrap.SplitBar.HORIZONTAL){
34453 return s.resizingEl.getWidth();
34455 return s.resizingEl.getHeight();
34460 * Called after drag operations to set the size of the resizing element.
34461 * @param {Roo.bootstrap.SplitBar} s The SplitBar using this adapter
34462 * @param {Number} newSize The new size to set
34463 * @param {Function} onComplete A function to be invoked when resizing is complete
34465 setElementSize : function(s, newSize, onComplete){
34466 if(s.orientation == Roo.bootstrap.SplitBar.HORIZONTAL){
34468 s.resizingEl.setWidth(newSize);
34470 onComplete(s, newSize);
34473 s.resizingEl.setWidth(newSize, true, .1, onComplete, 'easeOut');
34478 s.resizingEl.setHeight(newSize);
34480 onComplete(s, newSize);
34483 s.resizingEl.setHeight(newSize, true, .1, onComplete, 'easeOut');
34490 *@class Roo.bootstrap.SplitBar.AbsoluteLayoutAdapter
34491 * @extends Roo.bootstrap.SplitBar.BasicLayoutAdapter
34492 * Adapter that moves the splitter element to align with the resized sizing element.
34493 * Used with an absolute positioned SplitBar.
34494 * @param {String/HTMLElement/Roo.Element} container The container that wraps around the absolute positioned content. If it's
34495 * document.body, make sure you assign an id to the body element.
34497 Roo.bootstrap.SplitBar.AbsoluteLayoutAdapter = function(container){
34498 this.basic = new Roo.bootstrap.SplitBar.BasicLayoutAdapter();
34499 this.container = Roo.get(container);
34502 Roo.bootstrap.SplitBar.AbsoluteLayoutAdapter.prototype = {
34503 init : function(s){
34504 this.basic.init(s);
34507 getElementSize : function(s){
34508 return this.basic.getElementSize(s);
34511 setElementSize : function(s, newSize, onComplete){
34512 this.basic.setElementSize(s, newSize, this.moveSplitter.createDelegate(this, [s]));
34515 moveSplitter : function(s){
34516 var yes = Roo.bootstrap.SplitBar;
34517 switch(s.placement){
34519 s.el.setX(s.resizingEl.getRight());
34522 s.el.setStyle("right", (this.container.getWidth() - s.resizingEl.getLeft()) + "px");
34525 s.el.setY(s.resizingEl.getBottom());
34528 s.el.setY(s.resizingEl.getTop() - s.el.getHeight());
34535 * Orientation constant - Create a vertical SplitBar
34539 Roo.bootstrap.SplitBar.VERTICAL = 1;
34542 * Orientation constant - Create a horizontal SplitBar
34546 Roo.bootstrap.SplitBar.HORIZONTAL = 2;
34549 * Placement constant - The resizing element is to the left of the splitter element
34553 Roo.bootstrap.SplitBar.LEFT = 1;
34556 * Placement constant - The resizing element is to the right of the splitter element
34560 Roo.bootstrap.SplitBar.RIGHT = 2;
34563 * Placement constant - The resizing element is positioned above the splitter element
34567 Roo.bootstrap.SplitBar.TOP = 3;
34570 * Placement constant - The resizing element is positioned under splitter element
34574 Roo.bootstrap.SplitBar.BOTTOM = 4;
34575 Roo.namespace("Roo.bootstrap.layout");/*
34577 * Ext JS Library 1.1.1
34578 * Copyright(c) 2006-2007, Ext JS, LLC.
34580 * Originally Released Under LGPL - original licence link has changed is not relivant.
34583 * <script type="text/javascript">
34587 * @class Roo.bootstrap.layout.Manager
34588 * @extends Roo.bootstrap.Component
34589 * Base class for layout managers.
34591 Roo.bootstrap.layout.Manager = function(config)
34593 Roo.bootstrap.layout.Manager.superclass.constructor.call(this,config);
34599 /** false to disable window resize monitoring @type Boolean */
34600 this.monitorWindowResize = true;
34605 * Fires when a layout is performed.
34606 * @param {Roo.LayoutManager} this
34610 * @event regionresized
34611 * Fires when the user resizes a region.
34612 * @param {Roo.LayoutRegion} region The resized region
34613 * @param {Number} newSize The new size (width for east/west, height for north/south)
34615 "regionresized" : true,
34617 * @event regioncollapsed
34618 * Fires when a region is collapsed.
34619 * @param {Roo.LayoutRegion} region The collapsed region
34621 "regioncollapsed" : true,
34623 * @event regionexpanded
34624 * Fires when a region is expanded.
34625 * @param {Roo.LayoutRegion} region The expanded region
34627 "regionexpanded" : true
34629 this.updating = false;
34632 this.el = Roo.get(config.el);
34638 Roo.extend(Roo.bootstrap.layout.Manager, Roo.bootstrap.Component, {
34643 monitorWindowResize : true,
34649 onRender : function(ct, position)
34652 this.el = Roo.get(ct);
34655 //this.fireEvent('render',this);
34659 initEvents: function()
34663 // ie scrollbar fix
34664 if(this.el.dom == document.body && Roo.isIE && !config.allowScroll){
34665 document.body.scroll = "no";
34666 }else if(this.el.dom != document.body && this.el.getStyle('position') == 'static'){
34667 this.el.position('relative');
34669 this.id = this.el.id;
34670 this.el.addClass("roo-layout-container");
34671 Roo.EventManager.onWindowResize(this.onWindowResize, this, true);
34672 if(this.el.dom != document.body ) {
34673 this.el.on('resize', this.layout,this);
34674 this.el.on('show', this.layout,this);
34680 * Returns true if this layout is currently being updated
34681 * @return {Boolean}
34683 isUpdating : function(){
34684 return this.updating;
34688 * Suspend the LayoutManager from doing auto-layouts while
34689 * making multiple add or remove calls
34691 beginUpdate : function(){
34692 this.updating = true;
34696 * Restore auto-layouts and optionally disable the manager from performing a layout
34697 * @param {Boolean} noLayout true to disable a layout update
34699 endUpdate : function(noLayout){
34700 this.updating = false;
34706 layout: function(){
34710 onRegionResized : function(region, newSize){
34711 this.fireEvent("regionresized", region, newSize);
34715 onRegionCollapsed : function(region){
34716 this.fireEvent("regioncollapsed", region);
34719 onRegionExpanded : function(region){
34720 this.fireEvent("regionexpanded", region);
34724 * Returns the size of the current view. This method normalizes document.body and element embedded layouts and
34725 * performs box-model adjustments.
34726 * @return {Object} The size as an object {width: (the width), height: (the height)}
34728 getViewSize : function()
34731 if(this.el.dom != document.body){
34732 size = this.el.getSize();
34734 size = {width: Roo.lib.Dom.getViewWidth(), height: Roo.lib.Dom.getViewHeight()};
34736 size.width -= this.el.getBorderWidth("lr")-this.el.getPadding("lr");
34737 size.height -= this.el.getBorderWidth("tb")-this.el.getPadding("tb");
34742 * Returns the Element this layout is bound to.
34743 * @return {Roo.Element}
34745 getEl : function(){
34750 * Returns the specified region.
34751 * @param {String} target The region key ('center', 'north', 'south', 'east' or 'west')
34752 * @return {Roo.LayoutRegion}
34754 getRegion : function(target){
34755 return this.regions[target.toLowerCase()];
34758 onWindowResize : function(){
34759 if(this.monitorWindowResize){
34766 * Ext JS Library 1.1.1
34767 * Copyright(c) 2006-2007, Ext JS, LLC.
34769 * Originally Released Under LGPL - original licence link has changed is not relivant.
34772 * <script type="text/javascript">
34775 * @class Roo.bootstrap.layout.Border
34776 * @extends Roo.bootstrap.layout.Manager
34777 * This class represents a common layout manager used in desktop applications. For screenshots and more details,
34778 * please see: examples/bootstrap/nested.html<br><br>
34780 <b>The container the layout is rendered into can be either the body element or any other element.
34781 If it is not the body element, the container needs to either be an absolute positioned element,
34782 or you will need to add "position:relative" to the css of the container. You will also need to specify
34783 the container size if it is not the body element.</b>
34786 * Create a new Border
34787 * @param {Object} config Configuration options
34789 Roo.bootstrap.layout.Border = function(config){
34790 config = config || {};
34791 Roo.bootstrap.layout.Border.superclass.constructor.call(this, config);
34795 Roo.each(Roo.bootstrap.layout.Border.regions, function(region) {
34796 if(config[region]){
34797 config[region].region = region;
34798 this.addRegion(config[region]);
34804 Roo.bootstrap.layout.Border.regions = ["north","south","east","west","center"];
34806 Roo.extend(Roo.bootstrap.layout.Border, Roo.bootstrap.layout.Manager, {
34808 * Creates and adds a new region if it doesn't already exist.
34809 * @param {String} target The target region key (north, south, east, west or center).
34810 * @param {Object} config The regions config object
34811 * @return {BorderLayoutRegion} The new region
34813 addRegion : function(config)
34815 if(!this.regions[config.region]){
34816 var r = this.factory(config);
34817 this.bindRegion(r);
34819 return this.regions[config.region];
34823 bindRegion : function(r){
34824 this.regions[r.config.region] = r;
34826 r.on("visibilitychange", this.layout, this);
34827 r.on("paneladded", this.layout, this);
34828 r.on("panelremoved", this.layout, this);
34829 r.on("invalidated", this.layout, this);
34830 r.on("resized", this.onRegionResized, this);
34831 r.on("collapsed", this.onRegionCollapsed, this);
34832 r.on("expanded", this.onRegionExpanded, this);
34836 * Performs a layout update.
34838 layout : function()
34840 if(this.updating) {
34844 // render all the rebions if they have not been done alreayd?
34845 Roo.each(Roo.bootstrap.layout.Border.regions, function(region) {
34846 if(this.regions[region] && !this.regions[region].bodyEl){
34847 this.regions[region].onRender(this.el)
34851 var size = this.getViewSize();
34852 var w = size.width;
34853 var h = size.height;
34858 //var x = 0, y = 0;
34860 var rs = this.regions;
34861 var north = rs["north"];
34862 var south = rs["south"];
34863 var west = rs["west"];
34864 var east = rs["east"];
34865 var center = rs["center"];
34866 //if(this.hideOnLayout){ // not supported anymore
34867 //c.el.setStyle("display", "none");
34869 if(north && north.isVisible()){
34870 var b = north.getBox();
34871 var m = north.getMargins();
34872 b.width = w - (m.left+m.right);
34875 centerY = b.height + b.y + m.bottom;
34876 centerH -= centerY;
34877 north.updateBox(this.safeBox(b));
34879 if(south && south.isVisible()){
34880 var b = south.getBox();
34881 var m = south.getMargins();
34882 b.width = w - (m.left+m.right);
34884 var totalHeight = (b.height + m.top + m.bottom);
34885 b.y = h - totalHeight + m.top;
34886 centerH -= totalHeight;
34887 south.updateBox(this.safeBox(b));
34889 if(west && west.isVisible()){
34890 var b = west.getBox();
34891 var m = west.getMargins();
34892 b.height = centerH - (m.top+m.bottom);
34894 b.y = centerY + m.top;
34895 var totalWidth = (b.width + m.left + m.right);
34896 centerX += totalWidth;
34897 centerW -= totalWidth;
34898 west.updateBox(this.safeBox(b));
34900 if(east && east.isVisible()){
34901 var b = east.getBox();
34902 var m = east.getMargins();
34903 b.height = centerH - (m.top+m.bottom);
34904 var totalWidth = (b.width + m.left + m.right);
34905 b.x = w - totalWidth + m.left;
34906 b.y = centerY + m.top;
34907 centerW -= totalWidth;
34908 east.updateBox(this.safeBox(b));
34911 var m = center.getMargins();
34913 x: centerX + m.left,
34914 y: centerY + m.top,
34915 width: centerW - (m.left+m.right),
34916 height: centerH - (m.top+m.bottom)
34918 //if(this.hideOnLayout){
34919 //center.el.setStyle("display", "block");
34921 center.updateBox(this.safeBox(centerBox));
34924 this.fireEvent("layout", this);
34928 safeBox : function(box){
34929 box.width = Math.max(0, box.width);
34930 box.height = Math.max(0, box.height);
34935 * Adds a ContentPanel (or subclass) to this layout.
34936 * @param {String} target The target region key (north, south, east, west or center).
34937 * @param {Roo.ContentPanel} panel The panel to add
34938 * @return {Roo.ContentPanel} The added panel
34940 add : function(target, panel){
34942 target = target.toLowerCase();
34943 return this.regions[target].add(panel);
34947 * Remove a ContentPanel (or subclass) to this layout.
34948 * @param {String} target The target region key (north, south, east, west or center).
34949 * @param {Number/String/Roo.ContentPanel} panel The index, id or panel to remove
34950 * @return {Roo.ContentPanel} The removed panel
34952 remove : function(target, panel){
34953 target = target.toLowerCase();
34954 return this.regions[target].remove(panel);
34958 * Searches all regions for a panel with the specified id
34959 * @param {String} panelId
34960 * @return {Roo.ContentPanel} The panel or null if it wasn't found
34962 findPanel : function(panelId){
34963 var rs = this.regions;
34964 for(var target in rs){
34965 if(typeof rs[target] != "function"){
34966 var p = rs[target].getPanel(panelId);
34976 * Searches all regions for a panel with the specified id and activates (shows) it.
34977 * @param {String/ContentPanel} panelId The panels id or the panel itself
34978 * @return {Roo.ContentPanel} The shown panel or null
34980 showPanel : function(panelId) {
34981 var rs = this.regions;
34982 for(var target in rs){
34983 var r = rs[target];
34984 if(typeof r != "function"){
34985 if(r.hasPanel(panelId)){
34986 return r.showPanel(panelId);
34994 * Restores this layout's state using Roo.state.Manager or the state provided by the passed provider.
34995 * @param {Roo.state.Provider} provider (optional) An alternate state provider
34998 restoreState : function(provider){
35000 provider = Roo.state.Manager;
35002 var sm = new Roo.LayoutStateManager();
35003 sm.init(this, provider);
35009 * Adds a xtype elements to the layout.
35013 xtype : 'ContentPanel',
35020 xtype : 'NestedLayoutPanel',
35026 items : [ ... list of content panels or nested layout panels.. ]
35030 * @param {Object} cfg Xtype definition of item to add.
35032 addxtype : function(cfg)
35034 // basically accepts a pannel...
35035 // can accept a layout region..!?!?
35036 //Roo.log('Roo.BorderLayout add ' + cfg.xtype)
35039 // theory? children can only be panels??
35041 //if (!cfg.xtype.match(/Panel$/)) {
35046 if (typeof(cfg.region) == 'undefined') {
35047 Roo.log("Failed to add Panel, region was not set");
35051 var region = cfg.region;
35057 xitems = cfg.items;
35064 case 'Content': // ContentPanel (el, cfg)
35065 case 'Scroll': // ContentPanel (el, cfg)
35067 cfg.autoCreate = true;
35068 ret = new cfg.xns[cfg.xtype](cfg); // new panel!!!!!
35070 // var el = this.el.createChild();
35071 // ret = new Roo[cfg.xtype](el, cfg); // new panel!!!!!
35074 this.add(region, ret);
35078 case 'TreePanel': // our new panel!
35079 cfg.el = this.el.createChild();
35080 ret = new Roo[cfg.xtype](cfg); // new panel!!!!!
35081 this.add(region, ret);
35086 // create a new Layout (which is a Border Layout...
35088 var clayout = cfg.layout;
35089 clayout.el = this.el.createChild();
35090 clayout.items = clayout.items || [];
35094 // replace this exitems with the clayout ones..
35095 xitems = clayout.items;
35097 // force background off if it's in center...
35098 if (region == 'center' && this.active && this.getRegion('center').panels.length < 1) {
35099 cfg.background = false;
35101 cfg.layout = new Roo.bootstrap.layout.Border(clayout);
35104 ret = new cfg.xns[cfg.xtype](cfg); // new panel!!!!!
35105 //console.log('adding nested layout panel ' + cfg.toSource());
35106 this.add(region, ret);
35107 nb = {}; /// find first...
35112 // needs grid and region
35114 //var el = this.getRegion(region).el.createChild();
35116 *var el = this.el.createChild();
35117 // create the grid first...
35118 cfg.grid.container = el;
35119 cfg.grid = new cfg.grid.xns[cfg.grid.xtype](cfg.grid);
35122 if (region == 'center' && this.active ) {
35123 cfg.background = false;
35126 ret = new cfg.xns[cfg.xtype](cfg); // new panel!!!!!
35128 this.add(region, ret);
35130 if (cfg.background) {
35131 // render grid on panel activation (if panel background)
35132 ret.on('activate', function(gp) {
35133 if (!gp.grid.rendered) {
35134 // gp.grid.render(el);
35138 // cfg.grid.render(el);
35144 case 'Border': // it can get called on it'self... - might need to check if this is fixed?
35145 // it was the old xcomponent building that caused this before.
35146 // espeically if border is the top element in the tree.
35156 if (typeof(Roo[cfg.xtype]) != 'undefined') {
35158 ret = new Roo[cfg.xtype](cfg); // new panel!!!!!
35159 this.add(region, ret);
35163 throw "Can not add '" + cfg.xtype + "' to Border";
35169 this.beginUpdate();
35173 Roo.each(xitems, function(i) {
35174 region = nb && i.region ? i.region : false;
35176 var add = ret.addxtype(i);
35179 nb[region] = nb[region] == undefined ? 0 : nb[region]+1;
35180 if (!i.background) {
35181 abn[region] = nb[region] ;
35188 // make the last non-background panel active..
35189 //if (nb) { Roo.log(abn); }
35192 for(var r in abn) {
35193 region = this.getRegion(r);
35195 // tried using nb[r], but it does not work..
35197 region.showPanel(abn[r]);
35208 factory : function(cfg)
35211 var validRegions = Roo.bootstrap.layout.Border.regions;
35213 var target = cfg.region;
35216 var r = Roo.bootstrap.layout;
35220 return new r.North(cfg);
35222 return new r.South(cfg);
35224 return new r.East(cfg);
35226 return new r.West(cfg);
35228 return new r.Center(cfg);
35230 throw 'Layout region "'+target+'" not supported.';
35237 * Ext JS Library 1.1.1
35238 * Copyright(c) 2006-2007, Ext JS, LLC.
35240 * Originally Released Under LGPL - original licence link has changed is not relivant.
35243 * <script type="text/javascript">
35247 * @class Roo.bootstrap.layout.Basic
35248 * @extends Roo.util.Observable
35249 * This class represents a lightweight region in a layout manager. This region does not move dom nodes
35250 * and does not have a titlebar, tabs or any other features. All it does is size and position
35251 * panels. To create a BasicLayoutRegion, add lightweight:true or basic:true to your regions config.
35252 * @cfg {Roo.bootstrap.layout.Manager} mgr The manager
35253 * @cfg {string} region the region that it inhabits..
35254 * @cfg {bool} skipConfig skip config?
35258 Roo.bootstrap.layout.Basic = function(config){
35260 this.mgr = config.mgr;
35262 this.position = config.region;
35264 var skipConfig = config.skipConfig;
35268 * @scope Roo.BasicLayoutRegion
35272 * @event beforeremove
35273 * Fires before a panel is removed (or closed). To cancel the removal set "e.cancel = true" on the event argument.
35274 * @param {Roo.LayoutRegion} this
35275 * @param {Roo.ContentPanel} panel The panel
35276 * @param {Object} e The cancel event object
35278 "beforeremove" : true,
35280 * @event invalidated
35281 * Fires when the layout for this region is changed.
35282 * @param {Roo.LayoutRegion} this
35284 "invalidated" : true,
35286 * @event visibilitychange
35287 * Fires when this region is shown or hidden
35288 * @param {Roo.LayoutRegion} this
35289 * @param {Boolean} visibility true or false
35291 "visibilitychange" : true,
35293 * @event paneladded
35294 * Fires when a panel is added.
35295 * @param {Roo.LayoutRegion} this
35296 * @param {Roo.ContentPanel} panel The panel
35298 "paneladded" : true,
35300 * @event panelremoved
35301 * Fires when a panel is removed.
35302 * @param {Roo.LayoutRegion} this
35303 * @param {Roo.ContentPanel} panel The panel
35305 "panelremoved" : true,
35307 * @event beforecollapse
35308 * Fires when this region before collapse.
35309 * @param {Roo.LayoutRegion} this
35311 "beforecollapse" : true,
35314 * Fires when this region is collapsed.
35315 * @param {Roo.LayoutRegion} this
35317 "collapsed" : true,
35320 * Fires when this region is expanded.
35321 * @param {Roo.LayoutRegion} this
35326 * Fires when this region is slid into view.
35327 * @param {Roo.LayoutRegion} this
35329 "slideshow" : true,
35332 * Fires when this region slides out of view.
35333 * @param {Roo.LayoutRegion} this
35335 "slidehide" : true,
35337 * @event panelactivated
35338 * Fires when a panel is activated.
35339 * @param {Roo.LayoutRegion} this
35340 * @param {Roo.ContentPanel} panel The activated panel
35342 "panelactivated" : true,
35345 * Fires when the user resizes this region.
35346 * @param {Roo.LayoutRegion} this
35347 * @param {Number} newSize The new size (width for east/west, height for north/south)
35351 /** A collection of panels in this region. @type Roo.util.MixedCollection */
35352 this.panels = new Roo.util.MixedCollection();
35353 this.panels.getKey = this.getPanelId.createDelegate(this);
35355 this.activePanel = null;
35356 // ensure listeners are added...
35358 if (config.listeners || config.events) {
35359 Roo.bootstrap.layout.Basic.superclass.constructor.call(this, {
35360 listeners : config.listeners || {},
35361 events : config.events || {}
35365 if(skipConfig !== true){
35366 this.applyConfig(config);
35370 Roo.extend(Roo.bootstrap.layout.Basic, Roo.util.Observable,
35372 getPanelId : function(p){
35376 applyConfig : function(config){
35377 this.margins = config.margins || this.margins || {top: 0, left: 0, right:0, bottom: 0};
35378 this.config = config;
35383 * Resizes the region to the specified size. For vertical regions (west, east) this adjusts
35384 * the width, for horizontal (north, south) the height.
35385 * @param {Number} newSize The new width or height
35387 resizeTo : function(newSize){
35388 var el = this.el ? this.el :
35389 (this.activePanel ? this.activePanel.getEl() : null);
35391 switch(this.position){
35394 el.setWidth(newSize);
35395 this.fireEvent("resized", this, newSize);
35399 el.setHeight(newSize);
35400 this.fireEvent("resized", this, newSize);
35406 getBox : function(){
35407 return this.activePanel ? this.activePanel.getEl().getBox(false, true) : null;
35410 getMargins : function(){
35411 return this.margins;
35414 updateBox : function(box){
35416 var el = this.activePanel.getEl();
35417 el.dom.style.left = box.x + "px";
35418 el.dom.style.top = box.y + "px";
35419 this.activePanel.setSize(box.width, box.height);
35423 * Returns the container element for this region.
35424 * @return {Roo.Element}
35426 getEl : function(){
35427 return this.activePanel;
35431 * Returns true if this region is currently visible.
35432 * @return {Boolean}
35434 isVisible : function(){
35435 return this.activePanel ? true : false;
35438 setActivePanel : function(panel){
35439 panel = this.getPanel(panel);
35440 if(this.activePanel && this.activePanel != panel){
35441 this.activePanel.setActiveState(false);
35442 this.activePanel.getEl().setLeftTop(-10000,-10000);
35444 this.activePanel = panel;
35445 panel.setActiveState(true);
35447 panel.setSize(this.box.width, this.box.height);
35449 this.fireEvent("panelactivated", this, panel);
35450 this.fireEvent("invalidated");
35454 * Show the specified panel.
35455 * @param {Number/String/ContentPanel} panelId The panels index, id or the panel itself
35456 * @return {Roo.ContentPanel} The shown panel or null
35458 showPanel : function(panel){
35459 panel = this.getPanel(panel);
35461 this.setActivePanel(panel);
35467 * Get the active panel for this region.
35468 * @return {Roo.ContentPanel} The active panel or null
35470 getActivePanel : function(){
35471 return this.activePanel;
35475 * Add the passed ContentPanel(s)
35476 * @param {ContentPanel...} panel The ContentPanel(s) to add (you can pass more than one)
35477 * @return {Roo.ContentPanel} The panel added (if only one was added)
35479 add : function(panel){
35480 if(arguments.length > 1){
35481 for(var i = 0, len = arguments.length; i < len; i++) {
35482 this.add(arguments[i]);
35486 if(this.hasPanel(panel)){
35487 this.showPanel(panel);
35490 var el = panel.getEl();
35491 if(el.dom.parentNode != this.mgr.el.dom){
35492 this.mgr.el.dom.appendChild(el.dom);
35494 if(panel.setRegion){
35495 panel.setRegion(this);
35497 this.panels.add(panel);
35498 el.setStyle("position", "absolute");
35499 if(!panel.background){
35500 this.setActivePanel(panel);
35501 if(this.config.initialSize && this.panels.getCount()==1){
35502 this.resizeTo(this.config.initialSize);
35505 this.fireEvent("paneladded", this, panel);
35510 * Returns true if the panel is in this region.
35511 * @param {Number/String/ContentPanel} panel The panels index, id or the panel itself
35512 * @return {Boolean}
35514 hasPanel : function(panel){
35515 if(typeof panel == "object"){ // must be panel obj
35516 panel = panel.getId();
35518 return this.getPanel(panel) ? true : false;
35522 * Removes the specified panel. If preservePanel is not true (either here or in the config), the panel is destroyed.
35523 * @param {Number/String/ContentPanel} panel The panels index, id or the panel itself
35524 * @param {Boolean} preservePanel Overrides the config preservePanel option
35525 * @return {Roo.ContentPanel} The panel that was removed
35527 remove : function(panel, preservePanel){
35528 panel = this.getPanel(panel);
35533 this.fireEvent("beforeremove", this, panel, e);
35534 if(e.cancel === true){
35537 var panelId = panel.getId();
35538 this.panels.removeKey(panelId);
35543 * Returns the panel specified or null if it's not in this region.
35544 * @param {Number/String/ContentPanel} panel The panels index, id or the panel itself
35545 * @return {Roo.ContentPanel}
35547 getPanel : function(id){
35548 if(typeof id == "object"){ // must be panel obj
35551 return this.panels.get(id);
35555 * Returns this regions position (north/south/east/west/center).
35558 getPosition: function(){
35559 return this.position;
35563 * Ext JS Library 1.1.1
35564 * Copyright(c) 2006-2007, Ext JS, LLC.
35566 * Originally Released Under LGPL - original licence link has changed is not relivant.
35569 * <script type="text/javascript">
35573 * @class Roo.bootstrap.layout.Region
35574 * @extends Roo.bootstrap.layout.Basic
35575 * This class represents a region in a layout manager.
35577 * @cfg {Object} margins Margins for the element (defaults to {top: 0, left: 0, right:0, bottom: 0})
35578 * @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})
35579 * @cfg {String} tabPosition (top|bottom) "top" or "bottom" (defaults to "bottom")
35580 * @cfg {Boolean} alwaysShowTabs True to always display tabs even when there is only 1 panel (defaults to false)
35581 * @cfg {Boolean} autoScroll True to enable overflow scrolling (defaults to false)
35582 * @cfg {Boolean} titlebar True to display a title bar (defaults to true)
35583 * @cfg {String} title The title for the region (overrides panel titles)
35584 * @cfg {Boolean} animate True to animate expand/collapse (defaults to false)
35585 * @cfg {Boolean} autoHide False to disable auto hiding when the mouse leaves the "floated" region (defaults to true)
35586 * @cfg {Boolean} preservePanels True to preserve removed panels so they can be readded later (defaults to false)
35587 * @cfg {Boolean} closeOnTab True to place the close icon on the tabs instead of the region titlebar (defaults to false)
35588 * @cfg {Boolean} hideTabs True to hide the tab strip (defaults to false)
35589 * @cfg {Boolean} resizeTabs True to enable automatic tab resizing. This will resize the tabs so they are all the same size and fit within
35590 * the space available, similar to FireFox 1.5 tabs (defaults to false)
35591 * @cfg {Number} minTabWidth The minimum tab width (defaults to 40)
35592 * @cfg {Number} preferredTabWidth The preferred tab width (defaults to 150)
35593 * @cfg {String} overflow (hidden|visible) if you have menus in the region, then you need to set this to visible.
35595 * @cfg {Boolean} hidden True to start the region hidden (defaults to false)
35596 * @cfg {Boolean} hideWhenEmpty True to hide the region when it has no panels
35597 * @cfg {Boolean} disableTabTips True to disable tab tooltips
35598 * @cfg {Number} width For East/West panels
35599 * @cfg {Number} height For North/South panels
35600 * @cfg {Boolean} split To show the splitter
35601 * @cfg {Boolean} toolbar xtype configuration for a toolbar - shows on right of tabbar
35603 * @cfg {string} cls Extra CSS classes to add to region
35605 * @cfg {Roo.bootstrap.layout.Manager} mgr The manager
35606 * @cfg {string} region the region that it inhabits..
35609 * @xxxcfg {Boolean} collapsible DISABLED False to disable collapsing (defaults to true)
35610 * @xxxcfg {Boolean} collapsed DISABLED True to set the initial display to collapsed (defaults to false)
35612 * @xxxcfg {String} collapsedTitle DISABLED Optional string message to display in the collapsed block of a north or south region
35613 * @xxxxcfg {Boolean} floatable DISABLED False to disable floating (defaults to true)
35614 * @xxxxcfg {Boolean} showPin True to show a pin button NOT SUPPORTED YET
35616 Roo.bootstrap.layout.Region = function(config)
35618 this.applyConfig(config);
35620 var mgr = config.mgr;
35621 var pos = config.region;
35622 config.skipConfig = true;
35623 Roo.bootstrap.layout.Region.superclass.constructor.call(this, config);
35626 this.onRender(mgr.el);
35629 this.visible = true;
35630 this.collapsed = false;
35631 this.unrendered_panels = [];
35634 Roo.extend(Roo.bootstrap.layout.Region, Roo.bootstrap.layout.Basic, {
35636 position: '', // set by wrapper (eg. north/south etc..)
35637 unrendered_panels : null, // unrendered panels.
35638 createBody : function(){
35639 /** This region's body element
35640 * @type Roo.Element */
35641 this.bodyEl = this.el.createChild({
35643 cls: "roo-layout-panel-body tab-content" // bootstrap added...
35647 onRender: function(ctr, pos)
35649 var dh = Roo.DomHelper;
35650 /** This region's container element
35651 * @type Roo.Element */
35652 this.el = dh.append(ctr.dom, {
35654 cls: (this.config.cls || '') + " roo-layout-region roo-layout-panel roo-layout-panel-" + this.position
35656 /** This region's title element
35657 * @type Roo.Element */
35659 this.titleEl = dh.append(this.el.dom,
35662 unselectable: "on",
35663 cls: "roo-unselectable roo-layout-panel-hd breadcrumb roo-layout-title-" + this.position,
35665 {tag: "span", cls: "roo-unselectable roo-layout-panel-hd-text", unselectable: "on", html: " "},
35666 {tag: "div", cls: "roo-unselectable roo-layout-panel-hd-tools", unselectable: "on"}
35669 this.titleEl.enableDisplayMode();
35670 /** This region's title text element
35671 * @type HTMLElement */
35672 this.titleTextEl = this.titleEl.dom.firstChild;
35673 this.tools = Roo.get(this.titleEl.dom.childNodes[1], true);
35675 this.closeBtn = this.createTool(this.tools.dom, "roo-layout-close");
35676 this.closeBtn.enableDisplayMode();
35677 this.closeBtn.on("click", this.closeClicked, this);
35678 this.closeBtn.hide();
35680 this.createBody(this.config);
35681 if(this.config.hideWhenEmpty){
35683 this.on("paneladded", this.validateVisibility, this);
35684 this.on("panelremoved", this.validateVisibility, this);
35686 if(this.autoScroll){
35687 this.bodyEl.setStyle("overflow", "auto");
35689 this.bodyEl.setStyle("overflow", this.config.overflow || 'hidden');
35691 //if(c.titlebar !== false){
35692 if((!this.config.titlebar && !this.config.title) || this.config.titlebar === false){
35693 this.titleEl.hide();
35695 this.titleEl.show();
35696 if(this.config.title){
35697 this.titleTextEl.innerHTML = this.config.title;
35701 if(this.config.collapsed){
35702 this.collapse(true);
35704 if(this.config.hidden){
35708 if (this.unrendered_panels && this.unrendered_panels.length) {
35709 for (var i =0;i< this.unrendered_panels.length; i++) {
35710 this.add(this.unrendered_panels[i]);
35712 this.unrendered_panels = null;
35718 applyConfig : function(c)
35721 *if(c.collapsible && this.position != "center" && !this.collapsedEl){
35722 var dh = Roo.DomHelper;
35723 if(c.titlebar !== false){
35724 this.collapseBtn = this.createTool(this.tools.dom, "roo-layout-collapse-"+this.position);
35725 this.collapseBtn.on("click", this.collapse, this);
35726 this.collapseBtn.enableDisplayMode();
35728 if(c.showPin === true || this.showPin){
35729 this.stickBtn = this.createTool(this.tools.dom, "roo-layout-stick");
35730 this.stickBtn.enableDisplayMode();
35731 this.stickBtn.on("click", this.expand, this);
35732 this.stickBtn.hide();
35737 /** This region's collapsed element
35738 * @type Roo.Element */
35741 this.collapsedEl = dh.append(this.mgr.el.dom, {cls: "x-layout-collapsed x-layout-collapsed-"+this.position, children:[
35742 {cls: "x-layout-collapsed-tools", children:[{cls: "x-layout-ctools-inner"}]}
35745 if(c.floatable !== false){
35746 this.collapsedEl.addClassOnOver("x-layout-collapsed-over");
35747 this.collapsedEl.on("click", this.collapseClick, this);
35750 if(c.collapsedTitle && (this.position == "north" || this.position== "south")) {
35751 this.collapsedTitleTextEl = dh.append(this.collapsedEl.dom, {tag: "div", cls: "x-unselectable x-layout-panel-hd-text",
35752 id: "message", unselectable: "on", style:{"float":"left"}});
35753 this.collapsedTitleTextEl.innerHTML = c.collapsedTitle;
35755 this.expandBtn = this.createTool(this.collapsedEl.dom.firstChild.firstChild, "x-layout-expand-"+this.position);
35756 this.expandBtn.on("click", this.expand, this);
35760 if(this.collapseBtn){
35761 this.collapseBtn.setVisible(c.collapsible == true);
35764 this.cmargins = c.cmargins || this.cmargins ||
35765 (this.position == "west" || this.position == "east" ?
35766 {top: 0, left: 2, right:2, bottom: 0} :
35767 {top: 2, left: 0, right:0, bottom: 2});
35769 this.margins = c.margins || this.margins || {top: 0, left: 0, right:0, bottom: 0};
35772 this.bottomTabs = c.tabPosition != "top";
35774 this.autoScroll = c.autoScroll || false;
35779 this.duration = c.duration || .30;
35780 this.slideDuration = c.slideDuration || .45;
35785 * Returns true if this region is currently visible.
35786 * @return {Boolean}
35788 isVisible : function(){
35789 return this.visible;
35793 * Updates the title for collapsed north/south regions (used with {@link #collapsedTitle} config option)
35794 * @param {String} title (optional) The title text (accepts HTML markup, defaults to the numeric character reference for a non-breaking space, "&#160;")
35796 //setCollapsedTitle : function(title){
35797 // title = title || " ";
35798 // if(this.collapsedTitleTextEl){
35799 // this.collapsedTitleTextEl.innerHTML = title;
35803 getBox : function(){
35805 // if(!this.collapsed){
35806 b = this.el.getBox(false, true);
35808 // b = this.collapsedEl.getBox(false, true);
35813 getMargins : function(){
35814 return this.margins;
35815 //return this.collapsed ? this.cmargins : this.margins;
35818 highlight : function(){
35819 this.el.addClass("x-layout-panel-dragover");
35822 unhighlight : function(){
35823 this.el.removeClass("x-layout-panel-dragover");
35826 updateBox : function(box)
35828 if (!this.bodyEl) {
35829 return; // not rendered yet..
35833 if(!this.collapsed){
35834 this.el.dom.style.left = box.x + "px";
35835 this.el.dom.style.top = box.y + "px";
35836 this.updateBody(box.width, box.height);
35838 this.collapsedEl.dom.style.left = box.x + "px";
35839 this.collapsedEl.dom.style.top = box.y + "px";
35840 this.collapsedEl.setSize(box.width, box.height);
35843 this.tabs.autoSizeTabs();
35847 updateBody : function(w, h)
35850 this.el.setWidth(w);
35851 w -= this.el.getBorderWidth("rl");
35852 if(this.config.adjustments){
35853 w += this.config.adjustments[0];
35856 if(h !== null && h > 0){
35857 this.el.setHeight(h);
35858 h = this.titleEl && this.titleEl.isDisplayed() ? h - (this.titleEl.getHeight()||0) : h;
35859 h -= this.el.getBorderWidth("tb");
35860 if(this.config.adjustments){
35861 h += this.config.adjustments[1];
35863 this.bodyEl.setHeight(h);
35865 h = this.tabs.syncHeight(h);
35868 if(this.panelSize){
35869 w = w !== null ? w : this.panelSize.width;
35870 h = h !== null ? h : this.panelSize.height;
35872 if(this.activePanel){
35873 var el = this.activePanel.getEl();
35874 w = w !== null ? w : el.getWidth();
35875 h = h !== null ? h : el.getHeight();
35876 this.panelSize = {width: w, height: h};
35877 this.activePanel.setSize(w, h);
35879 if(Roo.isIE && this.tabs){
35880 this.tabs.el.repaint();
35885 * Returns the container element for this region.
35886 * @return {Roo.Element}
35888 getEl : function(){
35893 * Hides this region.
35896 //if(!this.collapsed){
35897 this.el.dom.style.left = "-2000px";
35900 // this.collapsedEl.dom.style.left = "-2000px";
35901 // this.collapsedEl.hide();
35903 this.visible = false;
35904 this.fireEvent("visibilitychange", this, false);
35908 * Shows this region if it was previously hidden.
35911 //if(!this.collapsed){
35914 // this.collapsedEl.show();
35916 this.visible = true;
35917 this.fireEvent("visibilitychange", this, true);
35920 closeClicked : function(){
35921 if(this.activePanel){
35922 this.remove(this.activePanel);
35926 collapseClick : function(e){
35928 e.stopPropagation();
35931 e.stopPropagation();
35937 * Collapses this region.
35938 * @param {Boolean} skipAnim (optional) true to collapse the element without animation (if animate is true)
35941 collapse : function(skipAnim, skipCheck = false){
35942 if(this.collapsed) {
35946 if(skipCheck || this.fireEvent("beforecollapse", this) != false){
35948 this.collapsed = true;
35950 this.split.el.hide();
35952 if(this.config.animate && skipAnim !== true){
35953 this.fireEvent("invalidated", this);
35954 this.animateCollapse();
35956 this.el.setLocation(-20000,-20000);
35958 this.collapsedEl.show();
35959 this.fireEvent("collapsed", this);
35960 this.fireEvent("invalidated", this);
35966 animateCollapse : function(){
35971 * Expands this region if it was previously collapsed.
35972 * @param {Roo.EventObject} e The event that triggered the expand (or null if calling manually)
35973 * @param {Boolean} skipAnim (optional) true to expand the element without animation (if animate is true)
35976 expand : function(e, skipAnim){
35978 e.stopPropagation();
35980 if(!this.collapsed || this.el.hasActiveFx()) {
35984 this.afterSlideIn();
35987 this.collapsed = false;
35988 if(this.config.animate && skipAnim !== true){
35989 this.animateExpand();
35993 this.split.el.show();
35995 this.collapsedEl.setLocation(-2000,-2000);
35996 this.collapsedEl.hide();
35997 this.fireEvent("invalidated", this);
35998 this.fireEvent("expanded", this);
36002 animateExpand : function(){
36006 initTabs : function()
36008 //this.bodyEl.setStyle("overflow", "hidden"); -- this is set in render?
36010 var ts = new Roo.bootstrap.panel.Tabs({
36011 el: this.bodyEl.dom,
36012 tabPosition: this.bottomTabs ? 'bottom' : 'top',
36013 disableTooltips: this.config.disableTabTips,
36014 toolbar : this.config.toolbar
36017 if(this.config.hideTabs){
36018 ts.stripWrap.setDisplayed(false);
36021 ts.resizeTabs = this.config.resizeTabs === true;
36022 ts.minTabWidth = this.config.minTabWidth || 40;
36023 ts.maxTabWidth = this.config.maxTabWidth || 250;
36024 ts.preferredTabWidth = this.config.preferredTabWidth || 150;
36025 ts.monitorResize = false;
36026 //ts.bodyEl.setStyle("overflow", this.config.autoScroll ? "auto" : "hidden"); // this is set in render?
36027 ts.bodyEl.addClass('roo-layout-tabs-body');
36028 this.panels.each(this.initPanelAsTab, this);
36031 initPanelAsTab : function(panel){
36032 var ti = this.tabs.addTab(
36036 this.config.closeOnTab && panel.isClosable(),
36039 if(panel.tabTip !== undefined){
36040 ti.setTooltip(panel.tabTip);
36042 ti.on("activate", function(){
36043 this.setActivePanel(panel);
36046 if(this.config.closeOnTab){
36047 ti.on("beforeclose", function(t, e){
36049 this.remove(panel);
36053 panel.tabItem = ti;
36058 updatePanelTitle : function(panel, title)
36060 if(this.activePanel == panel){
36061 this.updateTitle(title);
36064 var ti = this.tabs.getTab(panel.getEl().id);
36066 if(panel.tabTip !== undefined){
36067 ti.setTooltip(panel.tabTip);
36072 updateTitle : function(title){
36073 if(this.titleTextEl && !this.config.title){
36074 this.titleTextEl.innerHTML = (typeof title != "undefined" && title.length > 0 ? title : " ");
36078 setActivePanel : function(panel)
36080 panel = this.getPanel(panel);
36081 if(this.activePanel && this.activePanel != panel){
36082 if(this.activePanel.setActiveState(false) === false){
36086 this.activePanel = panel;
36087 panel.setActiveState(true);
36088 if(this.panelSize){
36089 panel.setSize(this.panelSize.width, this.panelSize.height);
36092 this.closeBtn.setVisible(!this.config.closeOnTab && !this.isSlid && panel.isClosable());
36094 this.updateTitle(panel.getTitle());
36096 this.fireEvent("invalidated", this);
36098 this.fireEvent("panelactivated", this, panel);
36102 * Shows the specified panel.
36103 * @param {Number/String/ContentPanel} panelId The panel's index, id or the panel itself
36104 * @return {Roo.ContentPanel} The shown panel, or null if a panel could not be found from panelId
36106 showPanel : function(panel)
36108 panel = this.getPanel(panel);
36111 var tab = this.tabs.getTab(panel.getEl().id);
36112 if(tab.isHidden()){
36113 this.tabs.unhideTab(tab.id);
36117 this.setActivePanel(panel);
36124 * Get the active panel for this region.
36125 * @return {Roo.ContentPanel} The active panel or null
36127 getActivePanel : function(){
36128 return this.activePanel;
36131 validateVisibility : function(){
36132 if(this.panels.getCount() < 1){
36133 this.updateTitle(" ");
36134 this.closeBtn.hide();
36137 if(!this.isVisible()){
36144 * Adds the passed ContentPanel(s) to this region.
36145 * @param {ContentPanel...} panel The ContentPanel(s) to add (you can pass more than one)
36146 * @return {Roo.ContentPanel} The panel added (if only one was added; null otherwise)
36148 add : function(panel)
36150 if(arguments.length > 1){
36151 for(var i = 0, len = arguments.length; i < len; i++) {
36152 this.add(arguments[i]);
36157 // if we have not been rendered yet, then we can not really do much of this..
36158 if (!this.bodyEl) {
36159 this.unrendered_panels.push(panel);
36166 if(this.hasPanel(panel)){
36167 this.showPanel(panel);
36170 panel.setRegion(this);
36171 this.panels.add(panel);
36172 /* if(this.panels.getCount() == 1 && !this.config.alwaysShowTabs){
36173 // sinle panel - no tab...?? would it not be better to render it with the tabs,
36174 // and hide them... ???
36175 this.bodyEl.dom.appendChild(panel.getEl().dom);
36176 if(panel.background !== true){
36177 this.setActivePanel(panel);
36179 this.fireEvent("paneladded", this, panel);
36186 this.initPanelAsTab(panel);
36190 if(panel.background !== true){
36191 this.tabs.activate(panel.getEl().id);
36193 this.fireEvent("paneladded", this, panel);
36198 * Hides the tab for the specified panel.
36199 * @param {Number/String/ContentPanel} panel The panel's index, id or the panel itself
36201 hidePanel : function(panel){
36202 if(this.tabs && (panel = this.getPanel(panel))){
36203 this.tabs.hideTab(panel.getEl().id);
36208 * Unhides the tab for a previously hidden panel.
36209 * @param {Number/String/ContentPanel} panel The panel's index, id or the panel itself
36211 unhidePanel : function(panel){
36212 if(this.tabs && (panel = this.getPanel(panel))){
36213 this.tabs.unhideTab(panel.getEl().id);
36217 clearPanels : function(){
36218 while(this.panels.getCount() > 0){
36219 this.remove(this.panels.first());
36224 * Removes the specified panel. If preservePanel is not true (either here or in the config), the panel is destroyed.
36225 * @param {Number/String/ContentPanel} panel The panel's index, id or the panel itself
36226 * @param {Boolean} preservePanel Overrides the config preservePanel option
36227 * @return {Roo.ContentPanel} The panel that was removed
36229 remove : function(panel, preservePanel)
36231 panel = this.getPanel(panel);
36236 this.fireEvent("beforeremove", this, panel, e);
36237 if(e.cancel === true){
36240 preservePanel = (typeof preservePanel != "undefined" ? preservePanel : (this.config.preservePanels === true || panel.preserve === true));
36241 var panelId = panel.getId();
36242 this.panels.removeKey(panelId);
36244 document.body.appendChild(panel.getEl().dom);
36247 this.tabs.removeTab(panel.getEl().id);
36248 }else if (!preservePanel){
36249 this.bodyEl.dom.removeChild(panel.getEl().dom);
36251 if(this.panels.getCount() == 1 && this.tabs && !this.config.alwaysShowTabs){
36252 var p = this.panels.first();
36253 var tempEl = document.createElement("div"); // temp holder to keep IE from deleting the node
36254 tempEl.appendChild(p.getEl().dom);
36255 this.bodyEl.update("");
36256 this.bodyEl.dom.appendChild(p.getEl().dom);
36258 this.updateTitle(p.getTitle());
36260 this.bodyEl.setStyle("overflow", this.config.autoScroll ? "auto" : "hidden");
36261 this.setActivePanel(p);
36263 panel.setRegion(null);
36264 if(this.activePanel == panel){
36265 this.activePanel = null;
36267 if(this.config.autoDestroy !== false && preservePanel !== true){
36268 try{panel.destroy();}catch(e){}
36270 this.fireEvent("panelremoved", this, panel);
36275 * Returns the TabPanel component used by this region
36276 * @return {Roo.TabPanel}
36278 getTabs : function(){
36282 createTool : function(parentEl, className){
36283 var btn = Roo.DomHelper.append(parentEl, {
36285 cls: "x-layout-tools-button",
36288 cls: "roo-layout-tools-button-inner " + className,
36292 btn.addClassOnOver("roo-layout-tools-button-over");
36297 * Ext JS Library 1.1.1
36298 * Copyright(c) 2006-2007, Ext JS, LLC.
36300 * Originally Released Under LGPL - original licence link has changed is not relivant.
36303 * <script type="text/javascript">
36309 * @class Roo.SplitLayoutRegion
36310 * @extends Roo.LayoutRegion
36311 * Adds a splitbar and other (private) useful functionality to a {@link Roo.LayoutRegion}.
36313 Roo.bootstrap.layout.Split = function(config){
36314 this.cursor = config.cursor;
36315 Roo.bootstrap.layout.Split.superclass.constructor.call(this, config);
36318 Roo.extend(Roo.bootstrap.layout.Split, Roo.bootstrap.layout.Region,
36320 splitTip : "Drag to resize.",
36321 collapsibleSplitTip : "Drag to resize. Double click to hide.",
36322 useSplitTips : false,
36324 applyConfig : function(config){
36325 Roo.bootstrap.layout.Split.superclass.applyConfig.call(this, config);
36328 onRender : function(ctr,pos) {
36330 Roo.bootstrap.layout.Split.superclass.onRender.call(this, ctr,pos);
36331 if(!this.config.split){
36336 var splitEl = Roo.DomHelper.append(ctr.dom, {
36338 id: this.el.id + "-split",
36339 cls: "roo-layout-split roo-layout-split-"+this.position,
36342 /** The SplitBar for this region
36343 * @type Roo.SplitBar */
36344 // does not exist yet...
36345 Roo.log([this.position, this.orientation]);
36347 this.split = new Roo.bootstrap.SplitBar({
36348 dragElement : splitEl,
36349 resizingElement: this.el,
36350 orientation : this.orientation
36353 this.split.on("moved", this.onSplitMove, this);
36354 this.split.useShim = this.config.useShim === true;
36355 this.split.getMaximumSize = this[this.position == 'north' || this.position == 'south' ? 'getVMaxSize' : 'getHMaxSize'].createDelegate(this);
36356 if(this.useSplitTips){
36357 this.split.el.dom.title = this.config.collapsible ? this.collapsibleSplitTip : this.splitTip;
36359 //if(config.collapsible){
36360 // this.split.el.on("dblclick", this.collapse, this);
36363 if(typeof this.config.minSize != "undefined"){
36364 this.split.minSize = this.config.minSize;
36366 if(typeof this.config.maxSize != "undefined"){
36367 this.split.maxSize = this.config.maxSize;
36369 if(this.config.hideWhenEmpty || this.config.hidden || this.config.collapsed){
36370 this.hideSplitter();
36375 getHMaxSize : function(){
36376 var cmax = this.config.maxSize || 10000;
36377 var center = this.mgr.getRegion("center");
36378 return Math.min(cmax, (this.el.getWidth()+center.getEl().getWidth())-center.getMinWidth());
36381 getVMaxSize : function(){
36382 var cmax = this.config.maxSize || 10000;
36383 var center = this.mgr.getRegion("center");
36384 return Math.min(cmax, (this.el.getHeight()+center.getEl().getHeight())-center.getMinHeight());
36387 onSplitMove : function(split, newSize){
36388 this.fireEvent("resized", this, newSize);
36392 * Returns the {@link Roo.SplitBar} for this region.
36393 * @return {Roo.SplitBar}
36395 getSplitBar : function(){
36400 this.hideSplitter();
36401 Roo.bootstrap.layout.Split.superclass.hide.call(this);
36404 hideSplitter : function(){
36406 this.split.el.setLocation(-2000,-2000);
36407 this.split.el.hide();
36413 this.split.el.show();
36415 Roo.bootstrap.layout.Split.superclass.show.call(this);
36418 beforeSlide: function(){
36419 if(Roo.isGecko){// firefox overflow auto bug workaround
36420 this.bodyEl.clip();
36422 this.tabs.bodyEl.clip();
36424 if(this.activePanel){
36425 this.activePanel.getEl().clip();
36427 if(this.activePanel.beforeSlide){
36428 this.activePanel.beforeSlide();
36434 afterSlide : function(){
36435 if(Roo.isGecko){// firefox overflow auto bug workaround
36436 this.bodyEl.unclip();
36438 this.tabs.bodyEl.unclip();
36440 if(this.activePanel){
36441 this.activePanel.getEl().unclip();
36442 if(this.activePanel.afterSlide){
36443 this.activePanel.afterSlide();
36449 initAutoHide : function(){
36450 if(this.autoHide !== false){
36451 if(!this.autoHideHd){
36452 var st = new Roo.util.DelayedTask(this.slideIn, this);
36453 this.autoHideHd = {
36454 "mouseout": function(e){
36455 if(!e.within(this.el, true)){
36459 "mouseover" : function(e){
36465 this.el.on(this.autoHideHd);
36469 clearAutoHide : function(){
36470 if(this.autoHide !== false){
36471 this.el.un("mouseout", this.autoHideHd.mouseout);
36472 this.el.un("mouseover", this.autoHideHd.mouseover);
36476 clearMonitor : function(){
36477 Roo.get(document).un("click", this.slideInIf, this);
36480 // these names are backwards but not changed for compat
36481 slideOut : function(){
36482 if(this.isSlid || this.el.hasActiveFx()){
36485 this.isSlid = true;
36486 if(this.collapseBtn){
36487 this.collapseBtn.hide();
36489 this.closeBtnState = this.closeBtn.getStyle('display');
36490 this.closeBtn.hide();
36492 this.stickBtn.show();
36495 this.el.alignTo(this.collapsedEl, this.getCollapseAnchor());
36496 this.beforeSlide();
36497 this.el.setStyle("z-index", 10001);
36498 this.el.slideIn(this.getSlideAnchor(), {
36499 callback: function(){
36501 this.initAutoHide();
36502 Roo.get(document).on("click", this.slideInIf, this);
36503 this.fireEvent("slideshow", this);
36510 afterSlideIn : function(){
36511 this.clearAutoHide();
36512 this.isSlid = false;
36513 this.clearMonitor();
36514 this.el.setStyle("z-index", "");
36515 if(this.collapseBtn){
36516 this.collapseBtn.show();
36518 this.closeBtn.setStyle('display', this.closeBtnState);
36520 this.stickBtn.hide();
36522 this.fireEvent("slidehide", this);
36525 slideIn : function(cb){
36526 if(!this.isSlid || this.el.hasActiveFx()){
36530 this.isSlid = false;
36531 this.beforeSlide();
36532 this.el.slideOut(this.getSlideAnchor(), {
36533 callback: function(){
36534 this.el.setLeftTop(-10000, -10000);
36536 this.afterSlideIn();
36544 slideInIf : function(e){
36545 if(!e.within(this.el)){
36550 animateCollapse : function(){
36551 this.beforeSlide();
36552 this.el.setStyle("z-index", 20000);
36553 var anchor = this.getSlideAnchor();
36554 this.el.slideOut(anchor, {
36555 callback : function(){
36556 this.el.setStyle("z-index", "");
36557 this.collapsedEl.slideIn(anchor, {duration:.3});
36559 this.el.setLocation(-10000,-10000);
36561 this.fireEvent("collapsed", this);
36568 animateExpand : function(){
36569 this.beforeSlide();
36570 this.el.alignTo(this.collapsedEl, this.getCollapseAnchor(), this.getExpandAdj());
36571 this.el.setStyle("z-index", 20000);
36572 this.collapsedEl.hide({
36575 this.el.slideIn(this.getSlideAnchor(), {
36576 callback : function(){
36577 this.el.setStyle("z-index", "");
36580 this.split.el.show();
36582 this.fireEvent("invalidated", this);
36583 this.fireEvent("expanded", this);
36611 getAnchor : function(){
36612 return this.anchors[this.position];
36615 getCollapseAnchor : function(){
36616 return this.canchors[this.position];
36619 getSlideAnchor : function(){
36620 return this.sanchors[this.position];
36623 getAlignAdj : function(){
36624 var cm = this.cmargins;
36625 switch(this.position){
36641 getExpandAdj : function(){
36642 var c = this.collapsedEl, cm = this.cmargins;
36643 switch(this.position){
36645 return [-(cm.right+c.getWidth()+cm.left), 0];
36648 return [cm.right+c.getWidth()+cm.left, 0];
36651 return [0, -(cm.top+cm.bottom+c.getHeight())];
36654 return [0, cm.top+cm.bottom+c.getHeight()];
36660 * Ext JS Library 1.1.1
36661 * Copyright(c) 2006-2007, Ext JS, LLC.
36663 * Originally Released Under LGPL - original licence link has changed is not relivant.
36666 * <script type="text/javascript">
36669 * These classes are private internal classes
36671 Roo.bootstrap.layout.Center = function(config){
36672 config.region = "center";
36673 Roo.bootstrap.layout.Region.call(this, config);
36674 this.visible = true;
36675 this.minWidth = config.minWidth || 20;
36676 this.minHeight = config.minHeight || 20;
36679 Roo.extend(Roo.bootstrap.layout.Center, Roo.bootstrap.layout.Region, {
36681 // center panel can't be hidden
36685 // center panel can't be hidden
36688 getMinWidth: function(){
36689 return this.minWidth;
36692 getMinHeight: function(){
36693 return this.minHeight;
36706 Roo.bootstrap.layout.North = function(config)
36708 config.region = 'north';
36709 config.cursor = 'n-resize';
36711 Roo.bootstrap.layout.Split.call(this, config);
36715 this.split.placement = Roo.bootstrap.SplitBar.TOP;
36716 this.split.orientation = Roo.bootstrap.SplitBar.VERTICAL;
36717 this.split.el.addClass("roo-layout-split-v");
36719 var size = config.initialSize || config.height;
36720 if(typeof size != "undefined"){
36721 this.el.setHeight(size);
36724 Roo.extend(Roo.bootstrap.layout.North, Roo.bootstrap.layout.Split,
36726 orientation: Roo.bootstrap.SplitBar.VERTICAL,
36730 getBox : function(){
36731 if(this.collapsed){
36732 return this.collapsedEl.getBox();
36734 var box = this.el.getBox();
36736 box.height += this.split.el.getHeight();
36741 updateBox : function(box){
36742 if(this.split && !this.collapsed){
36743 box.height -= this.split.el.getHeight();
36744 this.split.el.setLeft(box.x);
36745 this.split.el.setTop(box.y+box.height);
36746 this.split.el.setWidth(box.width);
36748 if(this.collapsed){
36749 this.updateBody(box.width, null);
36751 Roo.bootstrap.layout.Region.prototype.updateBox.call(this, box);
36759 Roo.bootstrap.layout.South = function(config){
36760 config.region = 'south';
36761 config.cursor = 's-resize';
36762 Roo.bootstrap.layout.Split.call(this, config);
36764 this.split.placement = Roo.bootstrap.SplitBar.BOTTOM;
36765 this.split.orientation = Roo.bootstrap.SplitBar.VERTICAL;
36766 this.split.el.addClass("roo-layout-split-v");
36768 var size = config.initialSize || config.height;
36769 if(typeof size != "undefined"){
36770 this.el.setHeight(size);
36774 Roo.extend(Roo.bootstrap.layout.South, Roo.bootstrap.layout.Split, {
36775 orientation: Roo.bootstrap.SplitBar.VERTICAL,
36776 getBox : function(){
36777 if(this.collapsed){
36778 return this.collapsedEl.getBox();
36780 var box = this.el.getBox();
36782 var sh = this.split.el.getHeight();
36789 updateBox : function(box){
36790 if(this.split && !this.collapsed){
36791 var sh = this.split.el.getHeight();
36794 this.split.el.setLeft(box.x);
36795 this.split.el.setTop(box.y-sh);
36796 this.split.el.setWidth(box.width);
36798 if(this.collapsed){
36799 this.updateBody(box.width, null);
36801 Roo.bootstrap.layout.Region.prototype.updateBox.call(this, box);
36805 Roo.bootstrap.layout.East = function(config){
36806 config.region = "east";
36807 config.cursor = "e-resize";
36808 Roo.bootstrap.layout.Split.call(this, config);
36810 this.split.placement = Roo.bootstrap.SplitBar.RIGHT;
36811 this.split.orientation = Roo.bootstrap.SplitBar.HORIZONTAL;
36812 this.split.el.addClass("roo-layout-split-h");
36814 var size = config.initialSize || config.width;
36815 if(typeof size != "undefined"){
36816 this.el.setWidth(size);
36819 Roo.extend(Roo.bootstrap.layout.East, Roo.bootstrap.layout.Split, {
36820 orientation: Roo.bootstrap.SplitBar.HORIZONTAL,
36821 getBox : function(){
36822 if(this.collapsed){
36823 return this.collapsedEl.getBox();
36825 var box = this.el.getBox();
36827 var sw = this.split.el.getWidth();
36834 updateBox : function(box){
36835 if(this.split && !this.collapsed){
36836 var sw = this.split.el.getWidth();
36838 this.split.el.setLeft(box.x);
36839 this.split.el.setTop(box.y);
36840 this.split.el.setHeight(box.height);
36843 if(this.collapsed){
36844 this.updateBody(null, box.height);
36846 Roo.bootstrap.layout.Region.prototype.updateBox.call(this, box);
36850 Roo.bootstrap.layout.West = function(config){
36851 config.region = "west";
36852 config.cursor = "w-resize";
36854 Roo.bootstrap.layout.Split.call(this, config);
36856 this.split.placement = Roo.bootstrap.SplitBar.LEFT;
36857 this.split.orientation = Roo.bootstrap.SplitBar.HORIZONTAL;
36858 this.split.el.addClass("roo-layout-split-h");
36862 Roo.extend(Roo.bootstrap.layout.West, Roo.bootstrap.layout.Split, {
36863 orientation: Roo.bootstrap.SplitBar.HORIZONTAL,
36865 onRender: function(ctr, pos)
36867 Roo.bootstrap.layout.West.superclass.onRender.call(this, ctr,pos);
36868 var size = this.config.initialSize || this.config.width;
36869 if(typeof size != "undefined"){
36870 this.el.setWidth(size);
36874 getBox : function(){
36875 if(this.collapsed){
36876 return this.collapsedEl.getBox();
36878 var box = this.el.getBox();
36880 box.width += this.split.el.getWidth();
36885 updateBox : function(box){
36886 if(this.split && !this.collapsed){
36887 var sw = this.split.el.getWidth();
36889 this.split.el.setLeft(box.x+box.width);
36890 this.split.el.setTop(box.y);
36891 this.split.el.setHeight(box.height);
36893 if(this.collapsed){
36894 this.updateBody(null, box.height);
36896 Roo.bootstrap.layout.Region.prototype.updateBox.call(this, box);
36899 Roo.namespace("Roo.bootstrap.panel");/*
36901 * Ext JS Library 1.1.1
36902 * Copyright(c) 2006-2007, Ext JS, LLC.
36904 * Originally Released Under LGPL - original licence link has changed is not relivant.
36907 * <script type="text/javascript">
36910 * @class Roo.ContentPanel
36911 * @extends Roo.util.Observable
36912 * A basic ContentPanel element.
36913 * @cfg {Boolean} fitToFrame True for this panel to adjust its size to fit when the region resizes (defaults to false)
36914 * @cfg {Boolean} fitContainer When using {@link #fitToFrame} and {@link #resizeEl}, you can also fit the parent container (defaults to false)
36915 * @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
36916 * @cfg {Boolean} closable True if the panel can be closed/removed
36917 * @cfg {Boolean} background True if the panel should not be activated when it is added (defaults to false)
36918 * @cfg {String/HTMLElement/Element} resizeEl An element to resize if {@link #fitToFrame} is true (instead of this panel's element)
36919 * @cfg {Toolbar} toolbar A toolbar for this panel
36920 * @cfg {Boolean} autoScroll True to scroll overflow in this panel (use with {@link #fitToFrame})
36921 * @cfg {String} title The title for this panel
36922 * @cfg {Array} adjustments Values to <b>add</b> to the width/height when doing a {@link #fitToFrame} (default is [0, 0])
36923 * @cfg {String} url Calls {@link #setUrl} with this value
36924 * @cfg {String} region (center|north|south|east|west) which region to put this panel on (when used with xtype constructors)
36925 * @cfg {String/Object} params When used with {@link #url}, calls {@link #setUrl} with this value
36926 * @cfg {Boolean} loadOnce When used with {@link #url}, calls {@link #setUrl} with this value
36927 * @cfg {String} content Raw content to fill content panel with (uses setContent on construction.)
36928 * @cfg {Boolean} badges render the badges
36931 * Create a new ContentPanel.
36932 * @param {String/HTMLElement/Roo.Element} el The container element for this panel
36933 * @param {String/Object} config A string to set only the title or a config object
36934 * @param {String} content (optional) Set the HTML content for this panel
36935 * @param {String} region (optional) Used by xtype constructors to add to regions. (values center,east,west,south,north)
36937 Roo.bootstrap.panel.Content = function( config){
36939 this.tpl = config.tpl || false;
36941 var el = config.el;
36942 var content = config.content;
36944 if(config.autoCreate){ // xtype is available if this is called from factory
36947 this.el = Roo.get(el);
36948 if(!this.el && config && config.autoCreate){
36949 if(typeof config.autoCreate == "object"){
36950 if(!config.autoCreate.id){
36951 config.autoCreate.id = config.id||el;
36953 this.el = Roo.DomHelper.append(document.body,
36954 config.autoCreate, true);
36956 var elcfg = { tag: "div",
36957 cls: "roo-layout-inactive-content",
36961 elcfg.html = config.html;
36965 this.el = Roo.DomHelper.append(document.body, elcfg , true);
36968 this.closable = false;
36969 this.loaded = false;
36970 this.active = false;
36973 if (config.toolbar && !config.toolbar.el && config.toolbar.xtype) {
36975 this.toolbar = new config.toolbar.xns[config.toolbar.xtype](config.toolbar);
36977 this.wrapEl = this.el; //this.el.wrap();
36979 if (config.toolbar.items) {
36980 ti = config.toolbar.items ;
36981 delete config.toolbar.items ;
36985 this.toolbar.render(this.wrapEl, 'before');
36986 for(var i =0;i < ti.length;i++) {
36987 // Roo.log(['add child', items[i]]);
36988 nitems.push(this.toolbar.addxtype(Roo.apply({}, ti[i])));
36990 this.toolbar.items = nitems;
36991 this.toolbar.el.insertBefore(this.wrapEl.dom.firstChild);
36992 delete config.toolbar;
36996 // xtype created footer. - not sure if will work as we normally have to render first..
36997 if (this.footer && !this.footer.el && this.footer.xtype) {
36998 if (!this.wrapEl) {
36999 this.wrapEl = this.el.wrap();
37002 this.footer.container = this.wrapEl.createChild();
37004 this.footer = Roo.factory(this.footer, Roo);
37009 if(typeof config == "string"){
37010 this.title = config;
37012 Roo.apply(this, config);
37016 this.resizeEl = Roo.get(this.resizeEl, true);
37018 this.resizeEl = this.el;
37020 // handle view.xtype
37028 * Fires when this panel is activated.
37029 * @param {Roo.ContentPanel} this
37033 * @event deactivate
37034 * Fires when this panel is activated.
37035 * @param {Roo.ContentPanel} this
37037 "deactivate" : true,
37041 * Fires when this panel is resized if fitToFrame is true.
37042 * @param {Roo.ContentPanel} this
37043 * @param {Number} width The width after any component adjustments
37044 * @param {Number} height The height after any component adjustments
37050 * Fires when this tab is created
37051 * @param {Roo.ContentPanel} this
37062 if(this.autoScroll){
37063 this.resizeEl.setStyle("overflow", "auto");
37065 // fix randome scrolling
37066 //this.el.on('scroll', function() {
37067 // Roo.log('fix random scolling');
37068 // this.scrollTo('top',0);
37071 content = content || this.content;
37073 this.setContent(content);
37075 if(config && config.url){
37076 this.setUrl(this.url, this.params, this.loadOnce);
37081 Roo.bootstrap.panel.Content.superclass.constructor.call(this);
37083 if (this.view && typeof(this.view.xtype) != 'undefined') {
37084 this.view.el = this.el.appendChild(document.createElement("div"));
37085 this.view = Roo.factory(this.view);
37086 this.view.render && this.view.render(false, '');
37090 this.fireEvent('render', this);
37093 Roo.extend(Roo.bootstrap.panel.Content, Roo.bootstrap.Component, {
37097 setRegion : function(region){
37098 this.region = region;
37099 this.setActiveClass(region && !this.background);
37103 setActiveClass: function(state)
37106 this.el.replaceClass("roo-layout-inactive-content", "roo-layout-active-content");
37107 this.el.setStyle('position','relative');
37109 this.el.replaceClass("roo-layout-active-content", "roo-layout-inactive-content");
37110 this.el.setStyle('position', 'absolute');
37115 * Returns the toolbar for this Panel if one was configured.
37116 * @return {Roo.Toolbar}
37118 getToolbar : function(){
37119 return this.toolbar;
37122 setActiveState : function(active)
37124 this.active = active;
37125 this.setActiveClass(active);
37127 if(this.fireEvent("deactivate", this) === false){
37132 this.fireEvent("activate", this);
37136 * Updates this panel's element
37137 * @param {String} content The new content
37138 * @param {Boolean} loadScripts (optional) true to look for and process scripts
37140 setContent : function(content, loadScripts){
37141 this.el.update(content, loadScripts);
37144 ignoreResize : function(w, h){
37145 if(this.lastSize && this.lastSize.width == w && this.lastSize.height == h){
37148 this.lastSize = {width: w, height: h};
37153 * Get the {@link Roo.UpdateManager} for this panel. Enables you to perform Ajax updates.
37154 * @return {Roo.UpdateManager} The UpdateManager
37156 getUpdateManager : function(){
37157 return this.el.getUpdateManager();
37160 * Loads this content panel immediately with content from XHR. Note: to delay loading until the panel is activated, use {@link #setUrl}.
37161 * @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:
37164 url: "your-url.php",
37165 params: {param1: "foo", param2: "bar"}, // or a URL encoded string
37166 callback: yourFunction,
37167 scope: yourObject, //(optional scope)
37170 text: "Loading...",
37175 * The only required property is <i>url</i>. The optional properties <i>nocache</i>, <i>text</i> and <i>scripts</i>
37176 * 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.
37177 * @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}
37178 * @param {Function} callback (optional) Callback when transaction is complete -- called with signature (oElement, bSuccess, oResponse)
37179 * @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.
37180 * @return {Roo.ContentPanel} this
37183 var um = this.el.getUpdateManager();
37184 um.update.apply(um, arguments);
37190 * 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.
37191 * @param {String/Function} url The URL to load the content from or a function to call to get the URL
37192 * @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)
37193 * @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)
37194 * @return {Roo.UpdateManager} The UpdateManager
37196 setUrl : function(url, params, loadOnce){
37197 if(this.refreshDelegate){
37198 this.removeListener("activate", this.refreshDelegate);
37200 this.refreshDelegate = this._handleRefresh.createDelegate(this, [url, params, loadOnce]);
37201 this.on("activate", this.refreshDelegate);
37202 return this.el.getUpdateManager();
37205 _handleRefresh : function(url, params, loadOnce){
37206 if(!loadOnce || !this.loaded){
37207 var updater = this.el.getUpdateManager();
37208 updater.update(url, params, this._setLoaded.createDelegate(this));
37212 _setLoaded : function(){
37213 this.loaded = true;
37217 * Returns this panel's id
37220 getId : function(){
37225 * Returns this panel's element - used by regiosn to add.
37226 * @return {Roo.Element}
37228 getEl : function(){
37229 return this.wrapEl || this.el;
37234 adjustForComponents : function(width, height)
37236 //Roo.log('adjustForComponents ');
37237 if(this.resizeEl != this.el){
37238 width -= this.el.getFrameWidth('lr');
37239 height -= this.el.getFrameWidth('tb');
37242 var te = this.toolbar.getEl();
37243 te.setWidth(width);
37244 height -= te.getHeight();
37247 var te = this.footer.getEl();
37248 te.setWidth(width);
37249 height -= te.getHeight();
37253 if(this.adjustments){
37254 width += this.adjustments[0];
37255 height += this.adjustments[1];
37257 return {"width": width, "height": height};
37260 setSize : function(width, height){
37261 if(this.fitToFrame && !this.ignoreResize(width, height)){
37262 if(this.fitContainer && this.resizeEl != this.el){
37263 this.el.setSize(width, height);
37265 var size = this.adjustForComponents(width, height);
37266 this.resizeEl.setSize(this.autoWidth ? "auto" : size.width, this.autoHeight ? "auto" : size.height);
37267 this.fireEvent('resize', this, size.width, size.height);
37272 * Returns this panel's title
37275 getTitle : function(){
37277 if (typeof(this.title) != 'object') {
37282 for (var k in this.title) {
37283 if (!this.title.hasOwnProperty(k)) {
37287 if (k.indexOf('-') >= 0) {
37288 var s = k.split('-');
37289 for (var i = 0; i<s.length; i++) {
37290 t += "<span class='visible-"+s[i]+"'>"+this.title[k]+"</span>";
37293 t += "<span class='visible-"+k+"'>"+this.title[k]+"</span>";
37300 * Set this panel's title
37301 * @param {String} title
37303 setTitle : function(title){
37304 this.title = title;
37306 this.region.updatePanelTitle(this, title);
37311 * Returns true is this panel was configured to be closable
37312 * @return {Boolean}
37314 isClosable : function(){
37315 return this.closable;
37318 beforeSlide : function(){
37320 this.resizeEl.clip();
37323 afterSlide : function(){
37325 this.resizeEl.unclip();
37329 * Force a content refresh from the URL specified in the {@link #setUrl} method.
37330 * Will fail silently if the {@link #setUrl} method has not been called.
37331 * This does not activate the panel, just updates its content.
37333 refresh : function(){
37334 if(this.refreshDelegate){
37335 this.loaded = false;
37336 this.refreshDelegate();
37341 * Destroys this panel
37343 destroy : function(){
37344 this.el.removeAllListeners();
37345 var tempEl = document.createElement("span");
37346 tempEl.appendChild(this.el.dom);
37347 tempEl.innerHTML = "";
37353 * form - if the content panel contains a form - this is a reference to it.
37354 * @type {Roo.form.Form}
37358 * view - if the content panel contains a view (Roo.DatePicker / Roo.View / Roo.JsonView)
37359 * This contains a reference to it.
37365 * Adds a xtype elements to the panel - currently only supports Forms, View, JsonView.
37375 * @param {Object} cfg Xtype definition of item to add.
37379 getChildContainer: function () {
37380 return this.getEl();
37385 var ret = new Roo.factory(cfg);
37390 if (cfg.xtype.match(/^Form$/)) {
37393 //if (this.footer) {
37394 // el = this.footer.container.insertSibling(false, 'before');
37396 el = this.el.createChild();
37399 this.form = new Roo.form.Form(cfg);
37402 if ( this.form.allItems.length) {
37403 this.form.render(el.dom);
37407 // should only have one of theses..
37408 if ([ 'View', 'JsonView', 'DatePicker'].indexOf(cfg.xtype) > -1) {
37409 // views.. should not be just added - used named prop 'view''
37411 cfg.el = this.el.appendChild(document.createElement("div"));
37414 var ret = new Roo.factory(cfg);
37416 ret.render && ret.render(false, ''); // render blank..
37426 * @class Roo.bootstrap.panel.Grid
37427 * @extends Roo.bootstrap.panel.Content
37429 * Create a new GridPanel.
37430 * @cfg {Roo.bootstrap.Table} grid The grid for this panel
37431 * @param {Object} config A the config object
37437 Roo.bootstrap.panel.Grid = function(config)
37441 this.wrapper = Roo.DomHelper.append(document.body, // wrapper for IE7 strict & safari scroll issue
37442 {tag: "div", cls: "roo-layout-grid-wrapper roo-layout-inactive-content"}, true);
37444 config.el = this.wrapper;
37445 //this.el = this.wrapper;
37447 if (config.container) {
37448 // ctor'ed from a Border/panel.grid
37451 this.wrapper.setStyle("overflow", "hidden");
37452 this.wrapper.addClass('roo-grid-container');
37457 if(config.toolbar){
37458 var tool_el = this.wrapper.createChild();
37459 this.toolbar = Roo.factory(config.toolbar);
37461 if (config.toolbar.items) {
37462 ti = config.toolbar.items ;
37463 delete config.toolbar.items ;
37467 this.toolbar.render(tool_el);
37468 for(var i =0;i < ti.length;i++) {
37469 // Roo.log(['add child', items[i]]);
37470 nitems.push(this.toolbar.addxtype(Roo.apply({}, ti[i])));
37472 this.toolbar.items = nitems;
37474 delete config.toolbar;
37477 Roo.bootstrap.panel.Grid.superclass.constructor.call(this, config);
37478 config.grid.scrollBody = true;;
37479 config.grid.monitorWindowResize = false; // turn off autosizing
37480 config.grid.autoHeight = false;
37481 config.grid.autoWidth = false;
37483 this.grid = new config.grid.xns[config.grid.xtype](config.grid);
37485 if (config.background) {
37486 // render grid on panel activation (if panel background)
37487 this.on('activate', function(gp) {
37488 if (!gp.grid.rendered) {
37489 gp.grid.render(this.wrapper);
37490 gp.grid.getGridEl().replaceClass("roo-layout-inactive-content", "roo-layout-component-panel");
37495 this.grid.render(this.wrapper);
37496 this.grid.getGridEl().replaceClass("roo-layout-inactive-content", "roo-layout-component-panel");
37499 //this.wrapper.dom.appendChild(config.grid.getGridEl().dom);
37500 // ??? needed ??? config.el = this.wrapper;
37505 // xtype created footer. - not sure if will work as we normally have to render first..
37506 if (this.footer && !this.footer.el && this.footer.xtype) {
37508 var ctr = this.grid.getView().getFooterPanel(true);
37509 this.footer.dataSource = this.grid.dataSource;
37510 this.footer = Roo.factory(this.footer, Roo);
37511 this.footer.render(ctr);
37521 Roo.extend(Roo.bootstrap.panel.Grid, Roo.bootstrap.panel.Content, {
37522 getId : function(){
37523 return this.grid.id;
37527 * Returns the grid for this panel
37528 * @return {Roo.bootstrap.Table}
37530 getGrid : function(){
37534 setSize : function(width, height){
37535 if(!this.ignoreResize(width, height)){
37536 var grid = this.grid;
37537 var size = this.adjustForComponents(width, height);
37538 var gridel = grid.getGridEl();
37539 gridel.setSize(size.width, size.height);
37541 var thd = grid.getGridEl().select('thead',true).first();
37542 var tbd = grid.getGridEl().select('tbody', true).first();
37544 tbd.setSize(width, height - thd.getHeight());
37553 beforeSlide : function(){
37554 this.grid.getView().scroller.clip();
37557 afterSlide : function(){
37558 this.grid.getView().scroller.unclip();
37561 destroy : function(){
37562 this.grid.destroy();
37564 Roo.bootstrap.panel.Grid.superclass.destroy.call(this);
37569 * @class Roo.bootstrap.panel.Nest
37570 * @extends Roo.bootstrap.panel.Content
37572 * Create a new Panel, that can contain a layout.Border.
37575 * @param {Roo.BorderLayout} layout The layout for this panel
37576 * @param {String/Object} config A string to set only the title or a config object
37578 Roo.bootstrap.panel.Nest = function(config)
37580 // construct with only one argument..
37581 /* FIXME - implement nicer consturctors
37582 if (layout.layout) {
37584 layout = config.layout;
37585 delete config.layout;
37587 if (layout.xtype && !layout.getEl) {
37588 // then layout needs constructing..
37589 layout = Roo.factory(layout, Roo);
37593 config.el = config.layout.getEl();
37595 Roo.bootstrap.panel.Nest.superclass.constructor.call(this, config);
37597 config.layout.monitorWindowResize = false; // turn off autosizing
37598 this.layout = config.layout;
37599 this.layout.getEl().addClass("roo-layout-nested-layout");
37606 Roo.extend(Roo.bootstrap.panel.Nest, Roo.bootstrap.panel.Content, {
37608 setSize : function(width, height){
37609 if(!this.ignoreResize(width, height)){
37610 var size = this.adjustForComponents(width, height);
37611 var el = this.layout.getEl();
37612 if (size.height < 1) {
37613 el.setWidth(size.width);
37615 el.setSize(size.width, size.height);
37617 var touch = el.dom.offsetWidth;
37618 this.layout.layout();
37619 // ie requires a double layout on the first pass
37620 if(Roo.isIE && !this.initialized){
37621 this.initialized = true;
37622 this.layout.layout();
37627 // activate all subpanels if not currently active..
37629 setActiveState : function(active){
37630 this.active = active;
37631 this.setActiveClass(active);
37634 this.fireEvent("deactivate", this);
37638 this.fireEvent("activate", this);
37639 // not sure if this should happen before or after..
37640 if (!this.layout) {
37641 return; // should not happen..
37644 for (var r in this.layout.regions) {
37645 reg = this.layout.getRegion(r);
37646 if (reg.getActivePanel()) {
37647 //reg.showPanel(reg.getActivePanel()); // force it to activate..
37648 reg.setActivePanel(reg.getActivePanel());
37651 if (!reg.panels.length) {
37654 reg.showPanel(reg.getPanel(0));
37663 * Returns the nested BorderLayout for this panel
37664 * @return {Roo.BorderLayout}
37666 getLayout : function(){
37667 return this.layout;
37671 * Adds a xtype elements to the layout of the nested panel
37675 xtype : 'ContentPanel',
37682 xtype : 'NestedLayoutPanel',
37688 items : [ ... list of content panels or nested layout panels.. ]
37692 * @param {Object} cfg Xtype definition of item to add.
37694 addxtype : function(cfg) {
37695 return this.layout.addxtype(cfg);
37700 * Ext JS Library 1.1.1
37701 * Copyright(c) 2006-2007, Ext JS, LLC.
37703 * Originally Released Under LGPL - original licence link has changed is not relivant.
37706 * <script type="text/javascript">
37709 * @class Roo.TabPanel
37710 * @extends Roo.util.Observable
37711 * A lightweight tab container.
37715 // basic tabs 1, built from existing content
37716 var tabs = new Roo.TabPanel("tabs1");
37717 tabs.addTab("script", "View Script");
37718 tabs.addTab("markup", "View Markup");
37719 tabs.activate("script");
37721 // more advanced tabs, built from javascript
37722 var jtabs = new Roo.TabPanel("jtabs");
37723 jtabs.addTab("jtabs-1", "Normal Tab", "My content was added during construction.");
37725 // set up the UpdateManager
37726 var tab2 = jtabs.addTab("jtabs-2", "Ajax Tab 1");
37727 var updater = tab2.getUpdateManager();
37728 updater.setDefaultUrl("ajax1.htm");
37729 tab2.on('activate', updater.refresh, updater, true);
37731 // Use setUrl for Ajax loading
37732 var tab3 = jtabs.addTab("jtabs-3", "Ajax Tab 2");
37733 tab3.setUrl("ajax2.htm", null, true);
37736 var tab4 = jtabs.addTab("tabs1-5", "Disabled Tab", "Can't see me cause I'm disabled");
37739 jtabs.activate("jtabs-1");
37742 * Create a new TabPanel.
37743 * @param {String/HTMLElement/Roo.Element} container The id, DOM element or Roo.Element container where this TabPanel is to be rendered.
37744 * @param {Object/Boolean} config Config object to set any properties for this TabPanel, or true to render the tabs on the bottom.
37746 Roo.bootstrap.panel.Tabs = function(config){
37748 * The container element for this TabPanel.
37749 * @type Roo.Element
37751 this.el = Roo.get(config.el);
37754 if(typeof config == "boolean"){
37755 this.tabPosition = config ? "bottom" : "top";
37757 Roo.apply(this, config);
37761 if(this.tabPosition == "bottom"){
37762 this.bodyEl = Roo.get(this.createBody(this.el.dom));
37763 this.el.addClass("roo-tabs-bottom");
37765 this.stripWrap = Roo.get(this.createStrip(this.el.dom), true);
37766 this.stripEl = Roo.get(this.createStripList(this.stripWrap.dom), true);
37767 this.stripBody = Roo.get(this.stripWrap.dom.firstChild.firstChild, true);
37769 Roo.fly(this.stripWrap.dom.firstChild).setStyle("overflow-x", "hidden");
37771 if(this.tabPosition != "bottom"){
37772 /** The body element that contains {@link Roo.TabPanelItem} bodies. +
37773 * @type Roo.Element
37775 this.bodyEl = Roo.get(this.createBody(this.el.dom));
37776 this.el.addClass("roo-tabs-top");
37780 this.bodyEl.setStyle("position", "relative");
37782 this.active = null;
37783 this.activateDelegate = this.activate.createDelegate(this);
37788 * Fires when the active tab changes
37789 * @param {Roo.TabPanel} this
37790 * @param {Roo.TabPanelItem} activePanel The new active tab
37794 * @event beforetabchange
37795 * Fires before the active tab changes, set cancel to true on the "e" parameter to cancel the change
37796 * @param {Roo.TabPanel} this
37797 * @param {Object} e Set cancel to true on this object to cancel the tab change
37798 * @param {Roo.TabPanelItem} tab The tab being changed to
37800 "beforetabchange" : true
37803 Roo.EventManager.onWindowResize(this.onResize, this);
37804 this.cpad = this.el.getPadding("lr");
37805 this.hiddenCount = 0;
37808 // toolbar on the tabbar support...
37809 if (this.toolbar) {
37810 alert("no toolbar support yet");
37811 this.toolbar = false;
37813 var tcfg = this.toolbar;
37814 tcfg.container = this.stripEl.child('td.x-tab-strip-toolbar');
37815 this.toolbar = new Roo.Toolbar(tcfg);
37816 if (Roo.isSafari) {
37817 var tbl = tcfg.container.child('table', true);
37818 tbl.setAttribute('width', '100%');
37826 Roo.bootstrap.panel.Tabs.superclass.constructor.call(this);
37829 Roo.extend(Roo.bootstrap.panel.Tabs, Roo.util.Observable, {
37831 *@cfg {String} tabPosition "top" or "bottom" (defaults to "top")
37833 tabPosition : "top",
37835 *@cfg {Number} currentTabWidth The width of the current tab (defaults to 0)
37837 currentTabWidth : 0,
37839 *@cfg {Number} minTabWidth The minimum width of a tab (defaults to 40) (ignored if {@link #resizeTabs} is not true)
37843 *@cfg {Number} maxTabWidth The maximum width of a tab (defaults to 250) (ignored if {@link #resizeTabs} is not true)
37847 *@cfg {Number} preferredTabWidth The preferred (default) width of a tab (defaults to 175) (ignored if {@link #resizeTabs} is not true)
37849 preferredTabWidth : 175,
37851 *@cfg {Boolean} resizeTabs True to enable dynamic tab resizing (defaults to false)
37853 resizeTabs : false,
37855 *@cfg {Boolean} monitorResize Set this to true to turn on window resize monitoring (ignored if {@link #resizeTabs} is not true) (defaults to true)
37857 monitorResize : true,
37859 *@cfg {Object} toolbar xtype description of toolbar to show at the right of the tab bar.
37864 * Creates a new {@link Roo.TabPanelItem} by looking for an existing element with the provided id -- if it's not found it creates one.
37865 * @param {String} id The id of the div to use <b>or create</b>
37866 * @param {String} text The text for the tab
37867 * @param {String} content (optional) Content to put in the TabPanelItem body
37868 * @param {Boolean} closable (optional) True to create a close icon on the tab
37869 * @return {Roo.TabPanelItem} The created TabPanelItem
37871 addTab : function(id, text, content, closable, tpl)
37873 var item = new Roo.bootstrap.panel.TabItem({
37877 closable : closable,
37880 this.addTabItem(item);
37882 item.setContent(content);
37888 * Returns the {@link Roo.TabPanelItem} with the specified id/index
37889 * @param {String/Number} id The id or index of the TabPanelItem to fetch.
37890 * @return {Roo.TabPanelItem}
37892 getTab : function(id){
37893 return this.items[id];
37897 * Hides the {@link Roo.TabPanelItem} with the specified id/index
37898 * @param {String/Number} id The id or index of the TabPanelItem to hide.
37900 hideTab : function(id){
37901 var t = this.items[id];
37904 this.hiddenCount++;
37905 this.autoSizeTabs();
37910 * "Unhides" the {@link Roo.TabPanelItem} with the specified id/index.
37911 * @param {String/Number} id The id or index of the TabPanelItem to unhide.
37913 unhideTab : function(id){
37914 var t = this.items[id];
37916 t.setHidden(false);
37917 this.hiddenCount--;
37918 this.autoSizeTabs();
37923 * Adds an existing {@link Roo.TabPanelItem}.
37924 * @param {Roo.TabPanelItem} item The TabPanelItem to add
37926 addTabItem : function(item){
37927 this.items[item.id] = item;
37928 this.items.push(item);
37929 // if(this.resizeTabs){
37930 // item.setWidth(this.currentTabWidth || this.preferredTabWidth);
37931 // this.autoSizeTabs();
37933 // item.autoSize();
37938 * Removes a {@link Roo.TabPanelItem}.
37939 * @param {String/Number} id The id or index of the TabPanelItem to remove.
37941 removeTab : function(id){
37942 var items = this.items;
37943 var tab = items[id];
37944 if(!tab) { return; }
37945 var index = items.indexOf(tab);
37946 if(this.active == tab && items.length > 1){
37947 var newTab = this.getNextAvailable(index);
37952 this.stripEl.dom.removeChild(tab.pnode.dom);
37953 if(tab.bodyEl.dom.parentNode == this.bodyEl.dom){ // if it was moved already prevent error
37954 this.bodyEl.dom.removeChild(tab.bodyEl.dom);
37956 items.splice(index, 1);
37957 delete this.items[tab.id];
37958 tab.fireEvent("close", tab);
37959 tab.purgeListeners();
37960 this.autoSizeTabs();
37963 getNextAvailable : function(start){
37964 var items = this.items;
37966 // look for a next tab that will slide over to
37967 // replace the one being removed
37968 while(index < items.length){
37969 var item = items[++index];
37970 if(item && !item.isHidden()){
37974 // if one isn't found select the previous tab (on the left)
37977 var item = items[--index];
37978 if(item && !item.isHidden()){
37986 * Disables a {@link Roo.TabPanelItem}. It cannot be the active tab, if it is this call is ignored.
37987 * @param {String/Number} id The id or index of the TabPanelItem to disable.
37989 disableTab : function(id){
37990 var tab = this.items[id];
37991 if(tab && this.active != tab){
37997 * Enables a {@link Roo.TabPanelItem} that is disabled.
37998 * @param {String/Number} id The id or index of the TabPanelItem to enable.
38000 enableTab : function(id){
38001 var tab = this.items[id];
38006 * Activates a {@link Roo.TabPanelItem}. The currently active one will be deactivated.
38007 * @param {String/Number} id The id or index of the TabPanelItem to activate.
38008 * @return {Roo.TabPanelItem} The TabPanelItem.
38010 activate : function(id){
38011 var tab = this.items[id];
38015 if(tab == this.active || tab.disabled){
38019 this.fireEvent("beforetabchange", this, e, tab);
38020 if(e.cancel !== true && !tab.disabled){
38022 this.active.hide();
38024 this.active = this.items[id];
38025 this.active.show();
38026 this.fireEvent("tabchange", this, this.active);
38032 * Gets the active {@link Roo.TabPanelItem}.
38033 * @return {Roo.TabPanelItem} The active TabPanelItem or null if none are active.
38035 getActiveTab : function(){
38036 return this.active;
38040 * Updates the tab body element to fit the height of the container element
38041 * for overflow scrolling
38042 * @param {Number} targetHeight (optional) Override the starting height from the elements height
38044 syncHeight : function(targetHeight){
38045 var height = (targetHeight || this.el.getHeight())-this.el.getBorderWidth("tb")-this.el.getPadding("tb");
38046 var bm = this.bodyEl.getMargins();
38047 var newHeight = height-(this.stripWrap.getHeight()||0)-(bm.top+bm.bottom);
38048 this.bodyEl.setHeight(newHeight);
38052 onResize : function(){
38053 if(this.monitorResize){
38054 this.autoSizeTabs();
38059 * Disables tab resizing while tabs are being added (if {@link #resizeTabs} is false this does nothing)
38061 beginUpdate : function(){
38062 this.updating = true;
38066 * Stops an update and resizes the tabs (if {@link #resizeTabs} is false this does nothing)
38068 endUpdate : function(){
38069 this.updating = false;
38070 this.autoSizeTabs();
38074 * Manual call to resize the tabs (if {@link #resizeTabs} is false this does nothing)
38076 autoSizeTabs : function(){
38077 var count = this.items.length;
38078 var vcount = count - this.hiddenCount;
38079 if(!this.resizeTabs || count < 1 || vcount < 1 || this.updating) {
38082 var w = Math.max(this.el.getWidth() - this.cpad, 10);
38083 var availWidth = Math.floor(w / vcount);
38084 var b = this.stripBody;
38085 if(b.getWidth() > w){
38086 var tabs = this.items;
38087 this.setTabWidth(Math.max(availWidth, this.minTabWidth)-2);
38088 if(availWidth < this.minTabWidth){
38089 /*if(!this.sleft){ // incomplete scrolling code
38090 this.createScrollButtons();
38093 this.stripClip.setWidth(w - (this.sleft.getWidth()+this.sright.getWidth()));*/
38096 if(this.currentTabWidth < this.preferredTabWidth){
38097 this.setTabWidth(Math.min(availWidth, this.preferredTabWidth)-2);
38103 * Returns the number of tabs in this TabPanel.
38106 getCount : function(){
38107 return this.items.length;
38111 * Resizes all the tabs to the passed width
38112 * @param {Number} The new width
38114 setTabWidth : function(width){
38115 this.currentTabWidth = width;
38116 for(var i = 0, len = this.items.length; i < len; i++) {
38117 if(!this.items[i].isHidden()) {
38118 this.items[i].setWidth(width);
38124 * Destroys this TabPanel
38125 * @param {Boolean} removeEl (optional) True to remove the element from the DOM as well (defaults to undefined)
38127 destroy : function(removeEl){
38128 Roo.EventManager.removeResizeListener(this.onResize, this);
38129 for(var i = 0, len = this.items.length; i < len; i++){
38130 this.items[i].purgeListeners();
38132 if(removeEl === true){
38133 this.el.update("");
38138 createStrip : function(container)
38140 var strip = document.createElement("nav");
38141 strip.className = "navbar navbar-default"; //"x-tabs-wrap";
38142 container.appendChild(strip);
38146 createStripList : function(strip)
38148 // div wrapper for retard IE
38149 // returns the "tr" element.
38150 strip.innerHTML = '<ul class="nav nav-tabs" role="tablist"></ul>';
38151 //'<div class="x-tabs-strip-wrap">'+
38152 // '<table class="x-tabs-strip" cellspacing="0" cellpadding="0" border="0"><tbody><tr>'+
38153 // '<td class="x-tab-strip-toolbar"></td></tr></tbody></table></div>';
38154 return strip.firstChild; //.firstChild.firstChild.firstChild;
38156 createBody : function(container)
38158 var body = document.createElement("div");
38159 Roo.id(body, "tab-body");
38160 //Roo.fly(body).addClass("x-tabs-body");
38161 Roo.fly(body).addClass("tab-content");
38162 container.appendChild(body);
38165 createItemBody :function(bodyEl, id){
38166 var body = Roo.getDom(id);
38168 body = document.createElement("div");
38171 //Roo.fly(body).addClass("x-tabs-item-body");
38172 Roo.fly(body).addClass("tab-pane");
38173 bodyEl.insertBefore(body, bodyEl.firstChild);
38177 createStripElements : function(stripEl, text, closable, tpl)
38179 var td = document.createElement("li"); // was td..
38182 //stripEl.insertBefore(td, stripEl.childNodes[stripEl.childNodes.length-1]);
38185 stripEl.appendChild(td);
38187 td.className = "x-tabs-closable";
38188 if(!this.closeTpl){
38189 this.closeTpl = new Roo.Template(
38190 '<a href="#" class="x-tabs-right"><span class="x-tabs-left"><em class="x-tabs-inner">' +
38191 '<span unselectable="on"' + (this.disableTooltips ? '' : ' title="{text}"') +' class="x-tabs-text">{text}</span>' +
38192 '<div unselectable="on" class="close-icon"> </div></em></span></a>'
38195 var el = this.closeTpl.overwrite(td, {"text": text});
38196 var close = el.getElementsByTagName("div")[0];
38197 var inner = el.getElementsByTagName("em")[0];
38198 return {"el": el, "close": close, "inner": inner};
38201 // not sure what this is..
38202 // if(!this.tabTpl){
38203 //this.tabTpl = new Roo.Template(
38204 // '<a href="#" class="x-tabs-right"><span class="x-tabs-left"><em class="x-tabs-inner">' +
38205 // '<span unselectable="on"' + (this.disableTooltips ? '' : ' title="{text}"') +' class="x-tabs-text">{text}</span></em></span></a>'
38207 // this.tabTpl = new Roo.Template(
38208 // '<a href="#">' +
38209 // '<span unselectable="on"' +
38210 // (this.disableTooltips ? '' : ' title="{text}"') +
38211 // ' >{text}</span></a>'
38217 var template = tpl || this.tabTpl || false;
38221 template = new Roo.Template(
38223 '<span unselectable="on"' +
38224 (this.disableTooltips ? '' : ' title="{text}"') +
38225 ' >{text}</span></a>'
38229 switch (typeof(template)) {
38233 template = new Roo.Template(template);
38239 var el = template.overwrite(td, {"text": text});
38241 var inner = el.getElementsByTagName("span")[0];
38243 return {"el": el, "inner": inner};
38251 * @class Roo.TabPanelItem
38252 * @extends Roo.util.Observable
38253 * Represents an individual item (tab plus body) in a TabPanel.
38254 * @param {Roo.TabPanel} tabPanel The {@link Roo.TabPanel} this TabPanelItem belongs to
38255 * @param {String} id The id of this TabPanelItem
38256 * @param {String} text The text for the tab of this TabPanelItem
38257 * @param {Boolean} closable True to allow this TabPanelItem to be closable (defaults to false)
38259 Roo.bootstrap.panel.TabItem = function(config){
38261 * The {@link Roo.TabPanel} this TabPanelItem belongs to
38262 * @type Roo.TabPanel
38264 this.tabPanel = config.panel;
38266 * The id for this TabPanelItem
38269 this.id = config.id;
38271 this.disabled = false;
38273 this.text = config.text;
38275 this.loaded = false;
38276 this.closable = config.closable;
38279 * The body element for this TabPanelItem.
38280 * @type Roo.Element
38282 this.bodyEl = Roo.get(this.tabPanel.createItemBody(this.tabPanel.bodyEl.dom, config.id));
38283 this.bodyEl.setVisibilityMode(Roo.Element.VISIBILITY);
38284 this.bodyEl.setStyle("display", "block");
38285 this.bodyEl.setStyle("zoom", "1");
38286 //this.hideAction();
38288 var els = this.tabPanel.createStripElements(this.tabPanel.stripEl.dom, config.text, config.closable, config.tpl);
38290 this.el = Roo.get(els.el);
38291 this.inner = Roo.get(els.inner, true);
38292 this.textEl = Roo.get(this.el.dom.firstChild, true);
38293 this.pnode = Roo.get(els.el.parentNode, true);
38294 // this.el.on("mousedown", this.onTabMouseDown, this);
38295 this.el.on("click", this.onTabClick, this);
38297 if(config.closable){
38298 var c = Roo.get(els.close, true);
38299 c.dom.title = this.closeText;
38300 c.addClassOnOver("close-over");
38301 c.on("click", this.closeClick, this);
38307 * Fires when this tab becomes the active tab.
38308 * @param {Roo.TabPanel} tabPanel The parent TabPanel
38309 * @param {Roo.TabPanelItem} this
38313 * @event beforeclose
38314 * Fires before this tab is closed. To cancel the close, set cancel to true on e (e.cancel = true).
38315 * @param {Roo.TabPanelItem} this
38316 * @param {Object} e Set cancel to true on this object to cancel the close.
38318 "beforeclose": true,
38321 * Fires when this tab is closed.
38322 * @param {Roo.TabPanelItem} this
38326 * @event deactivate
38327 * Fires when this tab is no longer the active tab.
38328 * @param {Roo.TabPanel} tabPanel The parent TabPanel
38329 * @param {Roo.TabPanelItem} this
38331 "deactivate" : true
38333 this.hidden = false;
38335 Roo.bootstrap.panel.TabItem.superclass.constructor.call(this);
38338 Roo.extend(Roo.bootstrap.panel.TabItem, Roo.util.Observable,
38340 purgeListeners : function(){
38341 Roo.util.Observable.prototype.purgeListeners.call(this);
38342 this.el.removeAllListeners();
38345 * Shows this TabPanelItem -- this <b>does not</b> deactivate the currently active TabPanelItem.
38348 this.pnode.addClass("active");
38351 this.tabPanel.stripWrap.repaint();
38353 this.fireEvent("activate", this.tabPanel, this);
38357 * Returns true if this tab is the active tab.
38358 * @return {Boolean}
38360 isActive : function(){
38361 return this.tabPanel.getActiveTab() == this;
38365 * Hides this TabPanelItem -- if you don't activate another TabPanelItem this could look odd.
38368 this.pnode.removeClass("active");
38370 this.fireEvent("deactivate", this.tabPanel, this);
38373 hideAction : function(){
38374 this.bodyEl.hide();
38375 this.bodyEl.setStyle("position", "absolute");
38376 this.bodyEl.setLeft("-20000px");
38377 this.bodyEl.setTop("-20000px");
38380 showAction : function(){
38381 this.bodyEl.setStyle("position", "relative");
38382 this.bodyEl.setTop("");
38383 this.bodyEl.setLeft("");
38384 this.bodyEl.show();
38388 * Set the tooltip for the tab.
38389 * @param {String} tooltip The tab's tooltip
38391 setTooltip : function(text){
38392 if(Roo.QuickTips && Roo.QuickTips.isEnabled()){
38393 this.textEl.dom.qtip = text;
38394 this.textEl.dom.removeAttribute('title');
38396 this.textEl.dom.title = text;
38400 onTabClick : function(e){
38401 e.preventDefault();
38402 this.tabPanel.activate(this.id);
38405 onTabMouseDown : function(e){
38406 e.preventDefault();
38407 this.tabPanel.activate(this.id);
38410 getWidth : function(){
38411 return this.inner.getWidth();
38414 setWidth : function(width){
38415 var iwidth = width - this.pnode.getPadding("lr");
38416 this.inner.setWidth(iwidth);
38417 this.textEl.setWidth(iwidth-this.inner.getPadding("lr"));
38418 this.pnode.setWidth(width);
38422 * Show or hide the tab
38423 * @param {Boolean} hidden True to hide or false to show.
38425 setHidden : function(hidden){
38426 this.hidden = hidden;
38427 this.pnode.setStyle("display", hidden ? "none" : "");
38431 * Returns true if this tab is "hidden"
38432 * @return {Boolean}
38434 isHidden : function(){
38435 return this.hidden;
38439 * Returns the text for this tab
38442 getText : function(){
38446 autoSize : function(){
38447 //this.el.beginMeasure();
38448 this.textEl.setWidth(1);
38450 * #2804 [new] Tabs in Roojs
38451 * increase the width by 2-4 pixels to prevent the ellipssis showing in chrome
38453 //this.setWidth(this.textEl.dom.scrollWidth+this.pnode.getPadding("lr")+this.inner.getPadding("lr") + 2);
38454 //this.el.endMeasure();
38458 * Sets the text for the tab (Note: this also sets the tooltip text)
38459 * @param {String} text The tab's text and tooltip
38461 setText : function(text){
38463 this.textEl.update(text);
38464 this.setTooltip(text);
38465 //if(!this.tabPanel.resizeTabs){
38466 // this.autoSize();
38470 * Activates this TabPanelItem -- this <b>does</b> deactivate the currently active TabPanelItem.
38472 activate : function(){
38473 this.tabPanel.activate(this.id);
38477 * Disables this TabPanelItem -- this does nothing if this is the active TabPanelItem.
38479 disable : function(){
38480 if(this.tabPanel.active != this){
38481 this.disabled = true;
38482 this.pnode.addClass("disabled");
38487 * Enables this TabPanelItem if it was previously disabled.
38489 enable : function(){
38490 this.disabled = false;
38491 this.pnode.removeClass("disabled");
38495 * Sets the content for this TabPanelItem.
38496 * @param {String} content The content
38497 * @param {Boolean} loadScripts true to look for and load scripts
38499 setContent : function(content, loadScripts){
38500 this.bodyEl.update(content, loadScripts);
38504 * Gets the {@link Roo.UpdateManager} for the body of this TabPanelItem. Enables you to perform Ajax updates.
38505 * @return {Roo.UpdateManager} The UpdateManager
38507 getUpdateManager : function(){
38508 return this.bodyEl.getUpdateManager();
38512 * Set a URL to be used to load the content for this TabPanelItem.
38513 * @param {String/Function} url The URL to load the content from, or a function to call to get the URL
38514 * @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)
38515 * @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)
38516 * @return {Roo.UpdateManager} The UpdateManager
38518 setUrl : function(url, params, loadOnce){
38519 if(this.refreshDelegate){
38520 this.un('activate', this.refreshDelegate);
38522 this.refreshDelegate = this._handleRefresh.createDelegate(this, [url, params, loadOnce]);
38523 this.on("activate", this.refreshDelegate);
38524 return this.bodyEl.getUpdateManager();
38528 _handleRefresh : function(url, params, loadOnce){
38529 if(!loadOnce || !this.loaded){
38530 var updater = this.bodyEl.getUpdateManager();
38531 updater.update(url, params, this._setLoaded.createDelegate(this));
38536 * Forces a content refresh from the URL specified in the {@link #setUrl} method.
38537 * Will fail silently if the setUrl method has not been called.
38538 * This does not activate the panel, just updates its content.
38540 refresh : function(){
38541 if(this.refreshDelegate){
38542 this.loaded = false;
38543 this.refreshDelegate();
38548 _setLoaded : function(){
38549 this.loaded = true;
38553 closeClick : function(e){
38556 this.fireEvent("beforeclose", this, o);
38557 if(o.cancel !== true){
38558 this.tabPanel.removeTab(this.id);
38562 * The text displayed in the tooltip for the close icon.
38565 closeText : "Close this tab"
38568 * This script refer to:
38569 * Title: International Telephone Input
38570 * Author: Jack O'Connor
38571 * Code version: v12.1.12
38572 * Availability: https://github.com/jackocnr/intl-tel-input.git
38575 Roo.bootstrap.PhoneInputData = function() {
38578 "Afghanistan (افغانستان)",
38583 "Albania (Shqipëri)",
38588 "Algeria (الجزائر)",
38613 "Antigua and Barbuda",
38623 "Armenia (Հայաստան)",
38639 "Austria (Österreich)",
38644 "Azerbaijan (Azərbaycan)",
38654 "Bahrain (البحرين)",
38659 "Bangladesh (বাংলাদেশ)",
38669 "Belarus (Беларусь)",
38674 "Belgium (België)",
38704 "Bosnia and Herzegovina (Босна и Херцеговина)",
38719 "British Indian Ocean Territory",
38724 "British Virgin Islands",
38734 "Bulgaria (България)",
38744 "Burundi (Uburundi)",
38749 "Cambodia (កម្ពុជា)",
38754 "Cameroon (Cameroun)",
38763 ["204", "226", "236", "249", "250", "289", "306", "343", "365", "387", "403", "416", "418", "431", "437", "438", "450", "506", "514", "519", "548", "579", "581", "587", "604", "613", "639", "647", "672", "705", "709", "742", "778", "780", "782", "807", "819", "825", "867", "873", "902", "905"]
38766 "Cape Verde (Kabu Verdi)",
38771 "Caribbean Netherlands",
38782 "Central African Republic (République centrafricaine)",
38802 "Christmas Island",
38808 "Cocos (Keeling) Islands",
38819 "Comoros (جزر القمر)",
38824 "Congo (DRC) (Jamhuri ya Kidemokrasia ya Kongo)",
38829 "Congo (Republic) (Congo-Brazzaville)",
38849 "Croatia (Hrvatska)",
38870 "Czech Republic (Česká republika)",
38875 "Denmark (Danmark)",
38890 "Dominican Republic (República Dominicana)",
38894 ["809", "829", "849"]
38912 "Equatorial Guinea (Guinea Ecuatorial)",
38932 "Falkland Islands (Islas Malvinas)",
38937 "Faroe Islands (Føroyar)",
38958 "French Guiana (Guyane française)",
38963 "French Polynesia (Polynésie française)",
38978 "Georgia (საქართველო)",
38983 "Germany (Deutschland)",
39003 "Greenland (Kalaallit Nunaat)",
39040 "Guinea-Bissau (Guiné Bissau)",
39065 "Hungary (Magyarország)",
39070 "Iceland (Ísland)",
39090 "Iraq (العراق)",
39106 "Israel (ישראל)",
39133 "Jordan (الأردن)",
39138 "Kazakhstan (Казахстан)",
39159 "Kuwait (الكويت)",
39164 "Kyrgyzstan (Кыргызстан)",
39174 "Latvia (Latvija)",
39179 "Lebanon (لبنان)",
39194 "Libya (ليبيا)",
39204 "Lithuania (Lietuva)",
39219 "Macedonia (FYROM) (Македонија)",
39224 "Madagascar (Madagasikara)",
39254 "Marshall Islands",
39264 "Mauritania (موريتانيا)",
39269 "Mauritius (Moris)",
39290 "Moldova (Republica Moldova)",
39300 "Mongolia (Монгол)",
39305 "Montenegro (Crna Gora)",
39315 "Morocco (المغرب)",
39321 "Mozambique (Moçambique)",
39326 "Myanmar (Burma) (မြန်မာ)",
39331 "Namibia (Namibië)",
39346 "Netherlands (Nederland)",
39351 "New Caledonia (Nouvelle-Calédonie)",
39386 "North Korea (조선 민주주의 인민 공화국)",
39391 "Northern Mariana Islands",
39407 "Pakistan (پاکستان)",
39417 "Palestine (فلسطين)",
39427 "Papua New Guinea",
39469 "Réunion (La Réunion)",
39475 "Romania (România)",
39491 "Saint Barthélemy",
39502 "Saint Kitts and Nevis",
39512 "Saint Martin (Saint-Martin (partie française))",
39518 "Saint Pierre and Miquelon (Saint-Pierre-et-Miquelon)",
39523 "Saint Vincent and the Grenadines",
39538 "São Tomé and Príncipe (São Tomé e Príncipe)",
39543 "Saudi Arabia (المملكة العربية السعودية)",
39548 "Senegal (Sénégal)",
39578 "Slovakia (Slovensko)",
39583 "Slovenia (Slovenija)",
39593 "Somalia (Soomaaliya)",
39603 "South Korea (대한민국)",
39608 "South Sudan (جنوب السودان)",
39618 "Sri Lanka (ශ්රී ලංකාව)",
39623 "Sudan (السودان)",
39633 "Svalbard and Jan Mayen",
39644 "Sweden (Sverige)",
39649 "Switzerland (Schweiz)",
39654 "Syria (سوريا)",
39699 "Trinidad and Tobago",
39704 "Tunisia (تونس)",
39709 "Turkey (Türkiye)",
39719 "Turks and Caicos Islands",
39729 "U.S. Virgin Islands",
39739 "Ukraine (Україна)",
39744 "United Arab Emirates (الإمارات العربية المتحدة)",
39766 "Uzbekistan (Oʻzbekiston)",
39776 "Vatican City (Città del Vaticano)",
39787 "Vietnam (Việt Nam)",
39792 "Wallis and Futuna (Wallis-et-Futuna)",
39797 "Western Sahara (الصحراء الغربية)",
39803 "Yemen (اليمن)",
39827 * This script refer to:
39828 * Title: International Telephone Input
39829 * Author: Jack O'Connor
39830 * Code version: v12.1.12
39831 * Availability: https://github.com/jackocnr/intl-tel-input.git
39835 * @class Roo.bootstrap.PhoneInput
39836 * @extends Roo.bootstrap.TriggerField
39837 * An input with International dial-code selection
39839 * @cfg {String} defaultDialCode default '+852'
39840 * @cfg {Array} preferedCountries default []
39843 * Create a new PhoneInput.
39844 * @param {Object} config Configuration options
39847 Roo.bootstrap.PhoneInput = function(config) {
39848 Roo.bootstrap.PhoneInput.superclass.constructor.call(this, config);
39851 Roo.extend(Roo.bootstrap.PhoneInput, Roo.bootstrap.TriggerField, {
39853 listWidth: undefined,
39855 selectedClass: 'active',
39857 invalidClass : "has-warning",
39859 validClass: 'has-success',
39861 allowed: '0123456789',
39864 * @cfg {String} defaultDialCode The default dial code when initializing the input
39866 defaultDialCode: '+852',
39869 * @cfg {Array} preferedCountries A list of iso2 in array (e.g. ['hk','us']). Those related countries will show at the top of the input's choices
39871 preferedCountries: false,
39873 getAutoCreate : function()
39875 var data = Roo.bootstrap.PhoneInputData();
39876 var align = this.labelAlign || this.parentLabelAlign();
39879 this.allCountries = [];
39880 this.dialCodeMapping = [];
39882 for (var i = 0; i < data.length; i++) {
39884 this.allCountries[i] = {
39888 priority: c[3] || 0,
39889 areaCodes: c[4] || null
39891 this.dialCodeMapping[c[2]] = {
39894 priority: c[3] || 0,
39895 areaCodes: c[4] || null
39907 cls : 'form-control tel-input',
39908 autocomplete: 'new-password'
39911 var hiddenInput = {
39914 cls: 'hidden-tel-input'
39918 hiddenInput.name = this.name;
39921 if (this.disabled) {
39922 input.disabled = true;
39925 var flag_container = {
39942 cls: this.hasFeedback ? 'has-feedback' : '',
39948 cls: 'dial-code-holder',
39955 cls: 'roo-select2-container input-group',
39962 if (this.fieldLabel.length) {
39965 tooltip: 'This field is required'
39971 cls: 'control-label',
39977 html: this.fieldLabel
39980 indicator.cls = 'roo-required-indicator text-danger fa fa-lg fa-star left-indicator';
39986 if(this.indicatorpos == 'right') {
39987 indicator.cls = 'roo-required-indicator text-danger fa fa-lg fa-star right-indicator';
39994 if(align == 'left') {
40002 if(this.labelWidth > 12){
40003 label.style = "width: " + this.labelWidth + 'px';
40005 if(this.labelWidth < 13 && this.labelmd == 0){
40006 this.labelmd = this.labelWidth;
40008 if(this.labellg > 0){
40009 label.cls += ' col-lg-' + this.labellg;
40010 input.cls += ' col-lg-' + (12 - this.labellg);
40012 if(this.labelmd > 0){
40013 label.cls += ' col-md-' + this.labelmd;
40014 container.cls += ' col-md-' + (12 - this.labelmd);
40016 if(this.labelsm > 0){
40017 label.cls += ' col-sm-' + this.labelsm;
40018 container.cls += ' col-sm-' + (12 - this.labelsm);
40020 if(this.labelxs > 0){
40021 label.cls += ' col-xs-' + this.labelxs;
40022 container.cls += ' col-xs-' + (12 - this.labelxs);
40032 var settings = this;
40034 ['xs','sm','md','lg'].map(function(size){
40035 if (settings[size]) {
40036 cfg.cls += ' col-' + size + '-' + settings[size];
40040 this.store = new Roo.data.Store({
40041 proxy : new Roo.data.MemoryProxy({}),
40042 reader : new Roo.data.JsonReader({
40053 'name' : 'dialCode',
40057 'name' : 'priority',
40061 'name' : 'areaCodes',
40068 if(!this.preferedCountries) {
40069 this.preferedCountries = [
40076 var p = this.preferedCountries.reverse();
40079 for (var i = 0; i < p.length; i++) {
40080 for (var j = 0; j < this.allCountries.length; j++) {
40081 if(this.allCountries[j].iso2 == p[i]) {
40082 var t = this.allCountries[j];
40083 this.allCountries.splice(j,1);
40084 this.allCountries.unshift(t);
40090 this.store.proxy.data = {
40092 data: this.allCountries
40098 initEvents : function()
40101 Roo.bootstrap.PhoneInput.superclass.initEvents.call(this);
40103 this.indicator = this.indicatorEl();
40104 this.flag = this.flagEl();
40105 this.dialCodeHolder = this.dialCodeHolderEl();
40107 this.trigger = this.el.select('div.flag-box',true).first();
40108 this.trigger.on("click", this.onTriggerClick, this, {preventDefault:true});
40113 var lw = _this.listWidth || Math.max(_this.inputEl().getWidth(), _this.minListWidth);
40114 _this.list.setWidth(lw);
40117 this.list.on('mouseover', this.onViewOver, this);
40118 this.list.on('mousemove', this.onViewMove, this);
40119 this.inputEl().on("keyup", this.onKeyUp, this);
40121 this.tpl = '<li><a href="#"><div class="flag {iso2}"></div>{name} <span class="dial-code">+{dialCode}</span></a></li>';
40123 this.view = new Roo.View(this.list, this.tpl, {
40124 singleSelect:true, store: this.store, selectedClass: this.selectedClass
40127 this.view.on('click', this.onViewClick, this);
40128 this.setValue(this.defaultDialCode);
40131 onTriggerClick : function(e)
40133 Roo.log('trigger click');
40138 if(this.isExpanded()){
40140 this.hasFocus = false;
40142 this.store.load({});
40143 this.hasFocus = true;
40148 isExpanded : function()
40150 return this.list.isVisible();
40153 collapse : function()
40155 if(!this.isExpanded()){
40159 Roo.get(document).un('mousedown', this.collapseIf, this);
40160 Roo.get(document).un('mousewheel', this.collapseIf, this);
40161 this.fireEvent('collapse', this);
40165 expand : function()
40169 if(this.isExpanded() || !this.hasFocus){
40173 var lw = this.listWidth || Math.max(this.inputEl().getWidth(), this.minListWidth);
40174 this.list.setWidth(lw);
40177 this.restrictHeight();
40179 Roo.get(document).on('mousedown', this.collapseIf, this);
40180 Roo.get(document).on('mousewheel', this.collapseIf, this);
40182 this.fireEvent('expand', this);
40185 restrictHeight : function()
40187 this.list.alignTo(this.inputEl(), this.listAlign);
40188 this.list.alignTo(this.inputEl(), this.listAlign);
40191 onViewOver : function(e, t)
40193 if(this.inKeyMode){
40196 var item = this.view.findItemFromChild(t);
40199 var index = this.view.indexOf(item);
40200 this.select(index, false);
40205 onViewClick : function(view, doFocus, el, e)
40207 var index = this.view.getSelectedIndexes()[0];
40209 var r = this.store.getAt(index);
40212 this.onSelect(r, index);
40214 if(doFocus !== false && !this.blockFocus){
40215 this.inputEl().focus();
40219 onViewMove : function(e, t)
40221 this.inKeyMode = false;
40224 select : function(index, scrollIntoView)
40226 this.selectedIndex = index;
40227 this.view.select(index);
40228 if(scrollIntoView !== false){
40229 var el = this.view.getNode(index);
40231 this.list.scrollChildIntoView(el, false);
40236 createList : function()
40238 this.list = Roo.get(document.body).createChild({
40240 cls: 'typeahead typeahead-long dropdown-menu tel-list',
40241 style: 'display:none'
40244 this.list.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
40247 collapseIf : function(e)
40249 var in_combo = e.within(this.el);
40250 var in_list = e.within(this.list);
40251 var is_list = (Roo.get(e.getTarget()).id == this.list.id) ? true : false;
40253 if (in_combo || in_list || is_list) {
40259 onSelect : function(record, index)
40261 if(this.fireEvent('beforeselect', this, record, index) !== false){
40263 this.setFlagClass(record.data.iso2);
40264 this.setDialCode(record.data.dialCode);
40265 this.hasFocus = false;
40267 this.fireEvent('select', this, record, index);
40271 flagEl : function()
40273 var flag = this.el.select('div.flag',true).first();
40280 dialCodeHolderEl : function()
40282 var d = this.el.select('input.dial-code-holder',true).first();
40289 setDialCode : function(v)
40291 this.dialCodeHolder.dom.value = '+'+v;
40294 setFlagClass : function(n)
40296 this.flag.dom.className = 'flag '+n;
40299 getValue : function()
40301 var v = this.inputEl().getValue();
40302 if(this.dialCodeHolder) {
40303 v = this.dialCodeHolder.dom.value+this.inputEl().getValue();
40308 setValue : function(v)
40310 var d = this.getDialCode(v);
40312 //invalid dial code
40313 if(v.length == 0 || !d || d.length == 0) {
40315 this.inputEl().dom.value = (v === null || v === undefined ? '' : v);
40316 this.hiddenEl().dom.value = (v === null || v === undefined ? '' : v);
40322 this.setFlagClass(this.dialCodeMapping[d].iso2);
40323 this.setDialCode(d);
40324 this.inputEl().dom.value = v.replace('+'+d,'');
40325 this.hiddenEl().dom.value = this.getValue();
40330 getDialCode : function(v)
40334 if (v.length == 0) {
40335 return this.dialCodeHolder.dom.value;
40339 if (v.charAt(0) != "+") {
40342 var numericChars = "";
40343 for (var i = 1; i < v.length; i++) {
40344 var c = v.charAt(i);
40347 if (this.dialCodeMapping[numericChars]) {
40348 dialCode = v.substr(1, i);
40350 if (numericChars.length == 4) {
40360 this.setValue(this.defaultDialCode);
40364 hiddenEl : function()
40366 return this.el.select('input.hidden-tel-input',true).first();
40369 onKeyUp : function(e){
40371 var k = e.getKey();
40372 var c = e.getCharCode();
40375 (String.fromCharCode(c) == '.' || String.fromCharCode(c) == '-') &&
40376 this.allowed.indexOf(String.fromCharCode(c)) === -1
40381 // if(!Roo.isIE && (e.isSpecialKey() || k == e.BACKSPACE || k == e.DELETE)){
40384 if(this.allowed.indexOf(String.fromCharCode(c)) === -1){
40388 this.setValue(this.getValue());
40393 * @class Roo.bootstrap.MoneyField
40394 * @extends Roo.bootstrap.ComboBox
40395 * Bootstrap MoneyField class
40398 * Create a new MoneyField.
40399 * @param {Object} config Configuration options
40402 Roo.bootstrap.MoneyField = function(config) {
40404 Roo.bootstrap.MoneyField.superclass.constructor.call(this, config);
40408 Roo.extend(Roo.bootstrap.MoneyField, Roo.bootstrap.ComboBox, {
40411 * @cfg {Boolean} allowDecimals False to disallow decimal values (defaults to true)
40413 allowDecimals : true,
40415 * @cfg {String} decimalSeparator Character(s) to allow as the decimal separator (defaults to '.')
40417 decimalSeparator : ".",
40419 * @cfg {Number} decimalPrecision The maximum precision to display after the decimal separator (defaults to 2)
40421 decimalPrecision : 0,
40423 * @cfg {Boolean} allowNegative False to prevent entering a negative sign (defaults to true)
40425 allowNegative : true,
40427 * @cfg {Boolean} allowZero False to blank out if the user enters '0' (defaults to true)
40431 * @cfg {Number} minValue The minimum allowed value (defaults to Number.NEGATIVE_INFINITY)
40433 minValue : Number.NEGATIVE_INFINITY,
40435 * @cfg {Number} maxValue The maximum allowed value (defaults to Number.MAX_VALUE)
40437 maxValue : Number.MAX_VALUE,
40439 * @cfg {String} minText Error text to display if the minimum value validation fails (defaults to "The minimum value for this field is {minValue}")
40441 minText : "The minimum value for this field is {0}",
40443 * @cfg {String} maxText Error text to display if the maximum value validation fails (defaults to "The maximum value for this field is {maxValue}")
40445 maxText : "The maximum value for this field is {0}",
40447 * @cfg {String} nanText Error text to display if the value is not a valid number. For example, this can happen
40448 * if a valid character like '.' or '-' is left in the field with no number (defaults to "{value} is not a valid number")
40450 nanText : "{0} is not a valid number",
40452 * @cfg {Boolean} castInt (true|false) cast int if true (defalut true)
40456 * @cfg {String} defaults currency of the MoneyField
40457 * value should be in lkey
40459 defaultCurrency : false,
40461 * @cfg {String} thousandsDelimiter Symbol of thousandsDelimiter
40463 thousandsDelimiter : false,
40473 getAutoCreate : function()
40475 var align = this.labelAlign || this.parentLabelAlign();
40487 cls : 'form-control roo-money-amount-input',
40488 autocomplete: 'new-password'
40491 var hiddenInput = {
40495 cls: 'hidden-number-input'
40499 hiddenInput.name = this.name;
40502 if (this.disabled) {
40503 input.disabled = true;
40506 var clg = 12 - this.inputlg;
40507 var cmd = 12 - this.inputmd;
40508 var csm = 12 - this.inputsm;
40509 var cxs = 12 - this.inputxs;
40513 cls : 'row roo-money-field',
40517 cls : 'roo-money-currency column col-lg-' + clg + ' col-md-' + cmd + ' col-sm-' + csm + ' col-xs-' + cxs,
40521 cls: 'roo-select2-container input-group',
40525 cls : 'form-control roo-money-currency-input',
40526 autocomplete: 'new-password',
40528 name : this.currencyName
40532 cls : 'input-group-addon',
40546 cls : 'roo-money-amount column col-lg-' + this.inputlg + ' col-md-' + this.inputmd + ' col-sm-' + this.inputsm + ' col-xs-' + this.inputxs,
40550 cls: this.hasFeedback ? 'has-feedback' : '',
40561 if (this.fieldLabel.length) {
40564 tooltip: 'This field is required'
40570 cls: 'control-label',
40576 html: this.fieldLabel
40579 indicator.cls = 'roo-required-indicator text-danger fa fa-lg fa-star left-indicator';
40585 if(this.indicatorpos == 'right') {
40586 indicator.cls = 'roo-required-indicator text-danger fa fa-lg fa-star right-indicator';
40593 if(align == 'left') {
40601 if(this.labelWidth > 12){
40602 label.style = "width: " + this.labelWidth + 'px';
40604 if(this.labelWidth < 13 && this.labelmd == 0){
40605 this.labelmd = this.labelWidth;
40607 if(this.labellg > 0){
40608 label.cls += ' col-lg-' + this.labellg;
40609 input.cls += ' col-lg-' + (12 - this.labellg);
40611 if(this.labelmd > 0){
40612 label.cls += ' col-md-' + this.labelmd;
40613 container.cls += ' col-md-' + (12 - this.labelmd);
40615 if(this.labelsm > 0){
40616 label.cls += ' col-sm-' + this.labelsm;
40617 container.cls += ' col-sm-' + (12 - this.labelsm);
40619 if(this.labelxs > 0){
40620 label.cls += ' col-xs-' + this.labelxs;
40621 container.cls += ' col-xs-' + (12 - this.labelxs);
40632 var settings = this;
40634 ['xs','sm','md','lg'].map(function(size){
40635 if (settings[size]) {
40636 cfg.cls += ' col-' + size + '-' + settings[size];
40643 initEvents : function()
40645 this.indicator = this.indicatorEl();
40647 this.initCurrencyEvent();
40649 this.initNumberEvent();
40652 initCurrencyEvent : function()
40655 throw "can not find store for combo";
40658 this.store = Roo.factory(this.store, Roo.data);
40659 this.store.parent = this;
40663 this.triggerEl = this.el.select('.input-group-addon', true).first();
40665 this.triggerEl.on("click", this.onTriggerClick, this, { preventDefault : true });
40670 var lw = _this.listWidth || Math.max(_this.inputEl().getWidth(), _this.minListWidth);
40671 _this.list.setWidth(lw);
40674 this.list.on('mouseover', this.onViewOver, this);
40675 this.list.on('mousemove', this.onViewMove, this);
40676 this.list.on('scroll', this.onViewScroll, this);
40679 this.tpl = '<li><a href="#">{' + this.currencyField + '}</a></li>';
40682 this.view = new Roo.View(this.list, this.tpl, {
40683 singleSelect:true, store: this.store, selectedClass: this.selectedClass
40686 this.view.on('click', this.onViewClick, this);
40688 this.store.on('beforeload', this.onBeforeLoad, this);
40689 this.store.on('load', this.onLoad, this);
40690 this.store.on('loadexception', this.onLoadException, this);
40692 this.keyNav = new Roo.KeyNav(this.currencyEl(), {
40693 "up" : function(e){
40694 this.inKeyMode = true;
40698 "down" : function(e){
40699 if(!this.isExpanded()){
40700 this.onTriggerClick();
40702 this.inKeyMode = true;
40707 "enter" : function(e){
40710 if(this.fireEvent("specialkey", this, e)){
40711 this.onViewClick(false);
40717 "esc" : function(e){
40721 "tab" : function(e){
40724 if(this.fireEvent("specialkey", this, e)){
40725 this.onViewClick(false);
40733 doRelay : function(foo, bar, hname){
40734 if(hname == 'down' || this.scope.isExpanded()){
40735 return Roo.KeyNav.prototype.doRelay.apply(this, arguments);
40743 this.currencyEl().on("click", this.onTriggerClick, this, { preventDefault : true });
40747 initNumberEvent : function(e)
40749 this.inputEl().on("keydown" , this.fireKey, this);
40750 this.inputEl().on("focus", this.onFocus, this);
40751 this.inputEl().on("blur", this.onBlur, this);
40753 this.inputEl().relayEvent('keyup', this);
40755 if(this.indicator){
40756 this.indicator.addClass('invisible');
40759 this.originalValue = this.getValue();
40761 if(this.validationEvent == 'keyup'){
40762 this.validationTask = new Roo.util.DelayedTask(this.validate, this);
40763 this.inputEl().on('keyup', this.filterValidation, this);
40765 else if(this.validationEvent !== false){
40766 this.inputEl().on(this.validationEvent, this.validate, this, {buffer: this.validationDelay});
40769 if(this.selectOnFocus){
40770 this.on("focus", this.preFocus, this);
40773 if(this.maskRe || (this.vtype && this.disableKeyFilter !== true && (this.maskRe = Roo.form.VTypes[this.vtype+'Mask']))){
40774 this.inputEl().on("keypress", this.filterKeys, this);
40776 this.inputEl().relayEvent('keypress', this);
40779 var allowed = "0123456789";
40781 if(this.allowDecimals){
40782 allowed += this.decimalSeparator;
40785 if(this.allowNegative){
40789 if(this.thousandsDelimiter) {
40793 this.stripCharsRe = new RegExp('[^'+allowed+']', 'gi');
40795 var keyPress = function(e){
40797 var k = e.getKey();
40799 var c = e.getCharCode();
40802 (String.fromCharCode(c) == '.' || String.fromCharCode(c) == '-') &&
40803 allowed.indexOf(String.fromCharCode(c)) === -1
40809 if(!Roo.isIE && (e.isSpecialKey() || k == e.BACKSPACE || k == e.DELETE)){
40813 if(allowed.indexOf(String.fromCharCode(c)) === -1){
40818 this.inputEl().on("keypress", keyPress, this);
40822 onTriggerClick : function(e)
40829 this.loadNext = false;
40831 if(this.isExpanded()){
40836 this.hasFocus = true;
40838 if(this.triggerAction == 'all') {
40839 this.doQuery(this.allQuery, true);
40843 this.doQuery(this.getRawValue());
40846 getCurrency : function()
40848 var v = this.currencyEl().getValue();
40853 restrictHeight : function()
40855 this.list.alignTo(this.currencyEl(), this.listAlign);
40856 this.list.alignTo(this.currencyEl(), this.listAlign);
40859 onViewClick : function(view, doFocus, el, e)
40861 var index = this.view.getSelectedIndexes()[0];
40863 var r = this.store.getAt(index);
40866 this.onSelect(r, index);
40870 onSelect : function(record, index){
40872 if(this.fireEvent('beforeselect', this, record, index) !== false){
40874 this.setFromCurrencyData(index > -1 ? record.data : false);
40878 this.fireEvent('select', this, record, index);
40882 setFromCurrencyData : function(o)
40886 this.lastCurrency = o;
40888 if (this.currencyField) {
40889 currency = !o || typeof(o[this.currencyField]) == 'undefined' ? '' : o[this.currencyField];
40891 Roo.log('no currencyField value set for '+ (this.name ? this.name : this.id));
40894 this.lastSelectionText = currency;
40896 //setting default currency
40897 if(o[this.currencyField] * 1 == 0 && this.defaultCurrency) {
40898 this.setCurrency(this.defaultCurrency);
40902 this.setCurrency(currency);
40905 setFromData : function(o)
40909 c[this.currencyField] = !o || typeof(o[this.currencyName]) == 'undefined' ? '' : o[this.currencyName];
40911 this.setFromCurrencyData(c);
40916 value = !o || typeof(o[this.name]) == 'undefined' ? '' : o[this.name];
40918 Roo.log('no value set for '+ (this.name ? this.name : this.id));
40921 this.setValue(value);
40925 setCurrency : function(v)
40927 this.currencyValue = v;
40930 this.currencyEl().dom.value = (v === null || v === undefined ? '' : v);
40935 setValue : function(v)
40937 v = String(this.fixPrecision(v)).replace(".", this.decimalSeparator);
40943 this.hiddenEl().dom.value = (v === null || v === undefined ? '' : v);
40945 this.inputEl().dom.value = (v == '') ? '' :
40946 Roo.util.Format.number(v, this.decimalPrecision, this.thousandsDelimiter || '');
40948 if(!this.allowZero && v === '0') {
40949 this.hiddenEl().dom.value = '';
40950 this.inputEl().dom.value = '';
40957 getRawValue : function()
40959 var v = this.inputEl().getValue();
40964 getValue : function()
40966 return this.fixPrecision(this.parseValue(this.getRawValue()));
40969 parseValue : function(value)
40971 if(this.thousandsDelimiter) {
40973 r = new RegExp(",", "g");
40974 value = value.replace(r, "");
40977 value = parseFloat(String(value).replace(this.decimalSeparator, "."));
40978 return isNaN(value) ? '' : value;
40982 fixPrecision : function(value)
40984 if(this.thousandsDelimiter) {
40986 r = new RegExp(",", "g");
40987 value = value.replace(r, "");
40990 var nan = isNaN(value);
40992 if(!this.allowDecimals || this.decimalPrecision == -1 || nan || !value){
40993 return nan ? '' : value;
40995 return parseFloat(value).toFixed(this.decimalPrecision);
40998 decimalPrecisionFcn : function(v)
41000 return Math.floor(v);
41003 validateValue : function(value)
41005 if(!Roo.bootstrap.MoneyField.superclass.validateValue.call(this, value)){
41009 var num = this.parseValue(value);
41012 this.markInvalid(String.format(this.nanText, value));
41016 if(num < this.minValue){
41017 this.markInvalid(String.format(this.minText, this.minValue));
41021 if(num > this.maxValue){
41022 this.markInvalid(String.format(this.maxText, this.maxValue));
41029 validate : function()
41031 if(this.disabled || this.allowBlank){
41036 var currency = this.getCurrency();
41038 if(this.validateValue(this.getRawValue()) && currency.length){
41043 this.markInvalid();
41047 getName: function()
41052 beforeBlur : function()
41058 var v = this.parseValue(this.getRawValue());
41065 onBlur : function()
41069 if(!Roo.isOpera && this.focusClass){ // don't touch in Opera
41070 //this.el.removeClass(this.focusClass);
41073 this.hasFocus = false;
41075 if(this.validationEvent !== false && this.validateOnBlur && this.validationEvent != "blur"){
41079 var v = this.getValue();
41081 if(String(v) !== String(this.startValue)){
41082 this.fireEvent('change', this, v, this.startValue);
41085 this.fireEvent("blur", this);
41088 inputEl : function()
41090 return this.el.select('.roo-money-amount-input', true).first();
41093 currencyEl : function()
41095 return this.el.select('.roo-money-currency-input', true).first();
41098 hiddenEl : function()
41100 return this.el.select('input.hidden-number-input',true).first();