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;
929 setWeight : function(str)
931 this.el.removeClass(this.weightClass);
932 this.el.addClass('btn-' + str);
946 * @class Roo.bootstrap.Column
947 * @extends Roo.bootstrap.Component
948 * Bootstrap Column class
949 * @cfg {Number} xs colspan out of 12 for mobile-sized screens or 0 for hidden
950 * @cfg {Number} sm colspan out of 12 for tablet-sized screens or 0 for hidden
951 * @cfg {Number} md colspan out of 12 for computer-sized screens or 0 for hidden
952 * @cfg {Number} lg colspan out of 12 for large computer-sized screens or 0 for hidden
953 * @cfg {Number} xsoff colspan offset out of 12 for mobile-sized screens or 0 for hidden
954 * @cfg {Number} smoff colspan offset out of 12 for tablet-sized screens or 0 for hidden
955 * @cfg {Number} mdoff colspan offset out of 12 for computer-sized screens or 0 for hidden
956 * @cfg {Number} lgoff colspan offset out of 12 for large computer-sized screens or 0 for hidden
959 * @cfg {Boolean} hidden (true|false) hide the element
960 * @cfg {String} alert (success|info|warning|danger) type alert (changes background / border...)
961 * @cfg {String} fa (ban|check|...) font awesome icon
962 * @cfg {Number} fasize (1|2|....) font awsome size
964 * @cfg {String} icon (info-sign|check|...) glyphicon name
966 * @cfg {String} html content of column.
969 * Create a new Column
970 * @param {Object} config The config object
973 Roo.bootstrap.Column = function(config){
974 Roo.bootstrap.Column.superclass.constructor.call(this, config);
977 Roo.extend(Roo.bootstrap.Column, Roo.bootstrap.Component, {
995 getAutoCreate : function(){
996 var cfg = Roo.apply({}, Roo.bootstrap.Column.superclass.getAutoCreate.call(this));
1004 ['xs','sm','md','lg'].map(function(size){
1005 //Roo.log( size + ':' + settings[size]);
1007 if (settings[size+'off'] !== false) {
1008 cfg.cls += ' col-' + size + '-offset-' + settings[size+'off'] ;
1011 if (settings[size] === false) {
1015 if (!settings[size]) { // 0 = hidden
1016 cfg.cls += ' hidden-' + size;
1019 cfg.cls += ' col-' + size + '-' + settings[size];
1024 cfg.cls += ' hidden';
1027 if (this.alert && ["success","info","warning", "danger"].indexOf(this.alert) > -1) {
1028 cfg.cls +=' alert alert-' + this.alert;
1032 if (this.html.length) {
1033 cfg.html = this.html;
1037 if (this.fasize > 1) {
1038 fasize = ' fa-' + this.fasize + 'x';
1040 cfg.html = '<i class="fa fa-'+this.fa + fasize + '"></i>' + (cfg.html || '');
1045 cfg.html = '<i class="glyphicon glyphicon-'+this.icon + '"></i>' + (cfg.html || '');
1064 * @class Roo.bootstrap.Container
1065 * @extends Roo.bootstrap.Component
1066 * Bootstrap Container class
1067 * @cfg {Boolean} jumbotron is it a jumbotron element
1068 * @cfg {String} html content of element
1069 * @cfg {String} well (lg|sm|md) a well, large, small or medium.
1070 * @cfg {String} panel (default|primary|success|info|warning|danger) render as panel - type - primary/success.....
1071 * @cfg {String} header content of header (for panel)
1072 * @cfg {String} footer content of footer (for panel)
1073 * @cfg {String} sticky (footer|wrap|push) block to use as footer or body- needs css-bootstrap/sticky-footer.css
1074 * @cfg {String} tag (header|aside|section) type of HTML tag.
1075 * @cfg {String} alert (success|info|warning|danger) type alert (changes background / border...)
1076 * @cfg {String} fa font awesome icon
1077 * @cfg {String} icon (info-sign|check|...) glyphicon name
1078 * @cfg {Boolean} hidden (true|false) hide the element
1079 * @cfg {Boolean} expandable (true|false) default false
1080 * @cfg {Boolean} expanded (true|false) default true
1081 * @cfg {String} rheader contet on the right of header
1082 * @cfg {Boolean} clickable (true|false) default false
1086 * Create a new Container
1087 * @param {Object} config The config object
1090 Roo.bootstrap.Container = function(config){
1091 Roo.bootstrap.Container.superclass.constructor.call(this, config);
1097 * After the panel has been expand
1099 * @param {Roo.bootstrap.Container} this
1104 * After the panel has been collapsed
1106 * @param {Roo.bootstrap.Container} this
1111 * When a element is chick
1112 * @param {Roo.bootstrap.Container} this
1113 * @param {Roo.EventObject} e
1119 Roo.extend(Roo.bootstrap.Container, Roo.bootstrap.Component, {
1137 getChildContainer : function() {
1143 if (this.panel.length) {
1144 return this.el.select('.panel-body',true).first();
1151 getAutoCreate : function(){
1154 tag : this.tag || 'div',
1158 if (this.jumbotron) {
1159 cfg.cls = 'jumbotron';
1164 // - this is applied by the parent..
1166 // cfg.cls = this.cls + '';
1169 if (this.sticky.length) {
1171 var bd = Roo.get(document.body);
1172 if (!bd.hasClass('bootstrap-sticky')) {
1173 bd.addClass('bootstrap-sticky');
1174 Roo.select('html',true).setStyle('height', '100%');
1177 cfg.cls += 'bootstrap-sticky-' + this.sticky;
1181 if (this.well.length) {
1182 switch (this.well) {
1185 cfg.cls +=' well well-' +this.well;
1194 cfg.cls += ' hidden';
1198 if (this.alert && ["success","info","warning", "danger"].indexOf(this.alert) > -1) {
1199 cfg.cls +=' alert alert-' + this.alert;
1204 if (this.panel.length) {
1205 cfg.cls += ' panel panel-' + this.panel;
1207 if (this.header.length) {
1211 if(this.expandable){
1213 cfg.cls = cfg.cls + ' expandable';
1217 cls: (this.expanded ? 'fa fa-minus' : 'fa fa-plus')
1225 cls : 'panel-title',
1226 html : (this.expandable ? ' ' : '') + this.header
1230 cls: 'panel-header-right',
1236 cls : 'panel-heading',
1237 style : this.expandable ? 'cursor: pointer' : '',
1245 cls : 'panel-body' + (this.expanded ? '' : ' hide'),
1250 if (this.footer.length) {
1252 cls : 'panel-footer',
1261 body.html = this.html || cfg.html;
1262 // prefix with the icons..
1264 body.html = '<i class="fa fa-'+this.fa + '"></i>' + body.html ;
1267 body.html = '<i class="glyphicon glyphicon-'+this.icon + '"></i>' + body.html ;
1272 if ((!this.cls || !this.cls.length) && (!cfg.cls || !cfg.cls.length)) {
1273 cfg.cls = 'container';
1279 initEvents: function()
1281 if(this.expandable){
1282 var headerEl = this.headerEl();
1285 headerEl.on('click', this.onToggleClick, this);
1290 this.el.on('click', this.onClick, this);
1295 onToggleClick : function()
1297 var headerEl = this.headerEl();
1313 if(this.fireEvent('expand', this)) {
1315 this.expanded = true;
1317 //this.el.select('.panel-body',true).first().setVisibilityMode(Roo.Element.DISPLAY).show();
1319 this.el.select('.panel-body',true).first().removeClass('hide');
1321 var toggleEl = this.toggleEl();
1327 toggleEl.removeClass(['fa-minus', 'fa-plus']).addClass(['fa-minus']);
1332 collapse : function()
1334 if(this.fireEvent('collapse', this)) {
1336 this.expanded = false;
1338 //this.el.select('.panel-body',true).first().setVisibilityMode(Roo.Element.DISPLAY).hide();
1339 this.el.select('.panel-body',true).first().addClass('hide');
1341 var toggleEl = this.toggleEl();
1347 toggleEl.removeClass(['fa-minus', 'fa-plus']).addClass(['fa-plus']);
1351 toggleEl : function()
1353 if(!this.el || !this.panel.length || !this.header.length || !this.expandable){
1357 return this.el.select('.panel-heading .fa',true).first();
1360 headerEl : function()
1362 if(!this.el || !this.panel.length || !this.header.length){
1366 return this.el.select('.panel-heading',true).first()
1371 if(!this.el || !this.panel.length){
1375 return this.el.select('.panel-body',true).first()
1378 titleEl : function()
1380 if(!this.el || !this.panel.length || !this.header.length){
1384 return this.el.select('.panel-title',true).first();
1387 setTitle : function(v)
1389 var titleEl = this.titleEl();
1395 titleEl.dom.innerHTML = v;
1398 getTitle : function()
1401 var titleEl = this.titleEl();
1407 return titleEl.dom.innerHTML;
1410 setRightTitle : function(v)
1412 var t = this.el.select('.panel-header-right',true).first();
1418 t.dom.innerHTML = v;
1421 onClick : function(e)
1425 this.fireEvent('click', this, e);
1438 * @class Roo.bootstrap.Img
1439 * @extends Roo.bootstrap.Component
1440 * Bootstrap Img class
1441 * @cfg {Boolean} imgResponsive false | true
1442 * @cfg {String} border rounded | circle | thumbnail
1443 * @cfg {String} src image source
1444 * @cfg {String} alt image alternative text
1445 * @cfg {String} href a tag href
1446 * @cfg {String} target (_self|_blank|_parent|_top)target for a href.
1447 * @cfg {String} xsUrl xs image source
1448 * @cfg {String} smUrl sm image source
1449 * @cfg {String} mdUrl md image source
1450 * @cfg {String} lgUrl lg image source
1453 * Create a new Input
1454 * @param {Object} config The config object
1457 Roo.bootstrap.Img = function(config){
1458 Roo.bootstrap.Img.superclass.constructor.call(this, config);
1464 * The img click event for the img.
1465 * @param {Roo.EventObject} e
1471 Roo.extend(Roo.bootstrap.Img, Roo.bootstrap.Component, {
1473 imgResponsive: true,
1483 getAutoCreate : function()
1485 if(this.src || (!this.xsUrl && !this.smUrl && !this.mdUrl && !this.lgUrl)){
1486 return this.createSingleImg();
1491 cls: 'roo-image-responsive-group',
1496 Roo.each(['xs', 'sm', 'md', 'lg'], function(size){
1498 if(!_this[size + 'Url']){
1504 cls: (_this.imgResponsive) ? 'img-responsive' : '',
1505 html: _this.html || cfg.html,
1506 src: _this[size + 'Url']
1509 img.cls += ' roo-image-responsive-' + size;
1511 var s = ['xs', 'sm', 'md', 'lg'];
1513 s.splice(s.indexOf(size), 1);
1515 Roo.each(s, function(ss){
1516 img.cls += ' hidden-' + ss;
1519 if (['rounded','circle','thumbnail'].indexOf(_this.border)>-1) {
1520 cfg.cls += ' img-' + _this.border;
1524 cfg.alt = _this.alt;
1537 a.target = _this.target;
1541 cfg.cn.push((_this.href) ? a : img);
1548 createSingleImg : function()
1552 cls: (this.imgResponsive) ? 'img-responsive' : '',
1554 src : 'about:blank' // just incase src get's set to undefined?!?
1557 cfg.html = this.html || cfg.html;
1559 cfg.src = this.src || cfg.src;
1561 if (['rounded','circle','thumbnail'].indexOf(this.border)>-1) {
1562 cfg.cls += ' img-' + this.border;
1579 a.target = this.target;
1584 return (this.href) ? a : cfg;
1587 initEvents: function()
1590 this.el.on('click', this.onClick, this);
1595 onClick : function(e)
1597 Roo.log('img onclick');
1598 this.fireEvent('click', this, e);
1601 * Sets the url of the image - used to update it
1602 * @param {String} url the url of the image
1605 setSrc : function(url)
1609 if(this.src || (!this.xsUrl && !this.smUrl && !this.mdUrl && !this.lgUrl)){
1610 this.el.dom.src = url;
1614 this.el.select('img', true).first().dom.src = url;
1630 * @class Roo.bootstrap.Link
1631 * @extends Roo.bootstrap.Component
1632 * Bootstrap Link Class
1633 * @cfg {String} alt image alternative text
1634 * @cfg {String} href a tag href
1635 * @cfg {String} target (_self|_blank|_parent|_top) target for a href.
1636 * @cfg {String} html the content of the link.
1637 * @cfg {String} anchor name for the anchor link
1638 * @cfg {String} fa - favicon
1640 * @cfg {Boolean} preventDefault (true | false) default false
1644 * Create a new Input
1645 * @param {Object} config The config object
1648 Roo.bootstrap.Link = function(config){
1649 Roo.bootstrap.Link.superclass.constructor.call(this, config);
1655 * The img click event for the img.
1656 * @param {Roo.EventObject} e
1662 Roo.extend(Roo.bootstrap.Link, Roo.bootstrap.Component, {
1666 preventDefault: false,
1672 getAutoCreate : function()
1674 var html = this.html || '';
1676 if (this.fa !== false) {
1677 html = '<i class="fa fa-' + this.fa + '"></i>';
1682 // anchor's do not require html/href...
1683 if (this.anchor === false) {
1685 cfg.href = this.href || '#';
1687 cfg.name = this.anchor;
1688 if (this.html !== false || this.fa !== false) {
1691 if (this.href !== false) {
1692 cfg.href = this.href;
1696 if(this.alt !== false){
1701 if(this.target !== false) {
1702 cfg.target = this.target;
1708 initEvents: function() {
1710 if(!this.href || this.preventDefault){
1711 this.el.on('click', this.onClick, this);
1715 onClick : function(e)
1717 if(this.preventDefault){
1720 //Roo.log('img onclick');
1721 this.fireEvent('click', this, e);
1734 * @class Roo.bootstrap.Header
1735 * @extends Roo.bootstrap.Component
1736 * Bootstrap Header class
1737 * @cfg {String} html content of header
1738 * @cfg {Number} level (1|2|3|4|5|6) default 1
1741 * Create a new Header
1742 * @param {Object} config The config object
1746 Roo.bootstrap.Header = function(config){
1747 Roo.bootstrap.Header.superclass.constructor.call(this, config);
1750 Roo.extend(Roo.bootstrap.Header, Roo.bootstrap.Component, {
1758 getAutoCreate : function(){
1763 tag: 'h' + (1 *this.level),
1764 html: this.html || ''
1776 * Ext JS Library 1.1.1
1777 * Copyright(c) 2006-2007, Ext JS, LLC.
1779 * Originally Released Under LGPL - original licence link has changed is not relivant.
1782 * <script type="text/javascript">
1786 * @class Roo.bootstrap.MenuMgr
1787 * Provides a common registry of all menu items on a page so that they can be easily accessed by id.
1790 Roo.bootstrap.MenuMgr = function(){
1791 var menus, active, groups = {}, attached = false, lastShow = new Date();
1793 // private - called when first menu is created
1796 active = new Roo.util.MixedCollection();
1797 Roo.get(document).addKeyListener(27, function(){
1798 if(active.length > 0){
1806 if(active && active.length > 0){
1807 var c = active.clone();
1817 if(active.length < 1){
1818 Roo.get(document).un("mouseup", onMouseDown);
1826 var last = active.last();
1827 lastShow = new Date();
1830 Roo.get(document).on("mouseup", onMouseDown);
1835 //m.getEl().setZIndex(parseInt(m.parentMenu.getEl().getStyle("z-index"), 10) + 3);
1836 m.parentMenu.activeChild = m;
1837 }else if(last && last.isVisible()){
1838 //m.getEl().setZIndex(parseInt(last.getEl().getStyle("z-index"), 10) + 3);
1843 function onBeforeHide(m){
1845 m.activeChild.hide();
1847 if(m.autoHideTimer){
1848 clearTimeout(m.autoHideTimer);
1849 delete m.autoHideTimer;
1854 function onBeforeShow(m){
1855 var pm = m.parentMenu;
1856 if(!pm && !m.allowOtherMenus){
1858 }else if(pm && pm.activeChild && active != m){
1859 pm.activeChild.hide();
1863 // private this should really trigger on mouseup..
1864 function onMouseDown(e){
1865 Roo.log("on Mouse Up");
1867 if(lastShow.getElapsed() > 50 && active.length > 0 && !e.getTarget(".dropdown-menu") && !e.getTarget('.user-menu')){
1868 Roo.log("MenuManager hideAll");
1877 function onBeforeCheck(mi, state){
1879 var g = groups[mi.group];
1880 for(var i = 0, l = g.length; i < l; i++){
1882 g[i].setChecked(false);
1891 * Hides all menus that are currently visible
1893 hideAll : function(){
1898 register : function(menu){
1902 menus[menu.id] = menu;
1903 menu.on("beforehide", onBeforeHide);
1904 menu.on("hide", onHide);
1905 menu.on("beforeshow", onBeforeShow);
1906 menu.on("show", onShow);
1908 if(g && menu.events["checkchange"]){
1912 groups[g].push(menu);
1913 menu.on("checkchange", onCheck);
1918 * Returns a {@link Roo.menu.Menu} object
1919 * @param {String/Object} menu The string menu id, an existing menu object reference, or a Menu config that will
1920 * be used to generate and return a new Menu instance.
1922 get : function(menu){
1923 if(typeof menu == "string"){ // menu id
1925 }else if(menu.events){ // menu instance
1928 /*else if(typeof menu.length == 'number'){ // array of menu items?
1929 return new Roo.bootstrap.Menu({items:menu});
1930 }else{ // otherwise, must be a config
1931 return new Roo.bootstrap.Menu(menu);
1938 unregister : function(menu){
1939 delete menus[menu.id];
1940 menu.un("beforehide", onBeforeHide);
1941 menu.un("hide", onHide);
1942 menu.un("beforeshow", onBeforeShow);
1943 menu.un("show", onShow);
1945 if(g && menu.events["checkchange"]){
1946 groups[g].remove(menu);
1947 menu.un("checkchange", onCheck);
1952 registerCheckable : function(menuItem){
1953 var g = menuItem.group;
1958 groups[g].push(menuItem);
1959 menuItem.on("beforecheckchange", onBeforeCheck);
1964 unregisterCheckable : function(menuItem){
1965 var g = menuItem.group;
1967 groups[g].remove(menuItem);
1968 menuItem.un("beforecheckchange", onBeforeCheck);
1980 * @class Roo.bootstrap.Menu
1981 * @extends Roo.bootstrap.Component
1982 * Bootstrap Menu class - container for MenuItems
1983 * @cfg {String} type (dropdown|treeview|submenu) type of menu
1984 * @cfg {bool} hidden if the menu should be hidden when rendered.
1985 * @cfg {bool} stopEvent (true|false) Stop event after trigger press (default true)
1986 * @cfg {bool} isLink (true|false) the menu has link disable auto expand and collaspe (default false)
1990 * @param {Object} config The config object
1994 Roo.bootstrap.Menu = function(config){
1995 Roo.bootstrap.Menu.superclass.constructor.call(this, config);
1996 if (this.registerMenu && this.type != 'treeview') {
1997 Roo.bootstrap.MenuMgr.register(this);
2002 * Fires before this menu is displayed
2003 * @param {Roo.menu.Menu} this
2008 * Fires before this menu is hidden
2009 * @param {Roo.menu.Menu} this
2014 * Fires after this menu is displayed
2015 * @param {Roo.menu.Menu} this
2020 * Fires after this menu is hidden
2021 * @param {Roo.menu.Menu} this
2026 * Fires when this menu is clicked (or when the enter key is pressed while it is active)
2027 * @param {Roo.menu.Menu} this
2028 * @param {Roo.menu.Item} menuItem The menu item that was clicked
2029 * @param {Roo.EventObject} e
2034 * Fires when the mouse is hovering over 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 the mouse exits this menu
2043 * @param {Roo.menu.Menu} this
2044 * @param {Roo.EventObject} e
2045 * @param {Roo.menu.Item} menuItem The menu item that was clicked
2050 * Fires when a menu item contained in this menu is clicked
2051 * @param {Roo.menu.BaseItem} baseItem The BaseItem that was clicked
2052 * @param {Roo.EventObject} e
2056 this.menuitems = new Roo.util.MixedCollection(false, function(o) { return o.el.id; });
2059 Roo.extend(Roo.bootstrap.Menu, Roo.bootstrap.Component, {
2063 triggerEl : false, // is this set by component builder? -- it should really be fetched from parent()???
2066 * @cfg {Boolean} registerMenu True (default) - means that clicking on screen etc. hides it.
2068 registerMenu : true,
2070 menuItems :false, // stores the menu items..
2080 getChildContainer : function() {
2084 getAutoCreate : function(){
2086 //if (['right'].indexOf(this.align)!==-1) {
2087 // cfg.cn[1].cls += ' pull-right'
2093 cls : 'dropdown-menu' ,
2094 style : 'z-index:1000'
2098 if (this.type === 'submenu') {
2099 cfg.cls = 'submenu active';
2101 if (this.type === 'treeview') {
2102 cfg.cls = 'treeview-menu';
2107 initEvents : function() {
2109 // Roo.log("ADD event");
2110 // Roo.log(this.triggerEl.dom);
2112 this.triggerEl.on('click', this.onTriggerClick, this);
2114 this.triggerEl.on(Roo.isTouch ? 'touchstart' : 'mouseup', this.onTriggerPress, this);
2116 this.triggerEl.addClass('dropdown-toggle');
2119 this.el.on('touchstart' , this.onTouch, this);
2121 this.el.on('click' , this.onClick, this);
2123 this.el.on("mouseover", this.onMouseOver, this);
2124 this.el.on("mouseout", this.onMouseOut, this);
2128 findTargetItem : function(e)
2130 var t = e.getTarget(".dropdown-menu-item", this.el, true);
2134 //Roo.log(t); Roo.log(t.id);
2136 //Roo.log(this.menuitems);
2137 return this.menuitems.get(t.id);
2139 //return this.items.get(t.menuItemId);
2145 onTouch : function(e)
2147 Roo.log("menu.onTouch");
2148 //e.stopEvent(); this make the user popdown broken
2152 onClick : function(e)
2154 Roo.log("menu.onClick");
2156 var t = this.findTargetItem(e);
2157 if(!t || t.isContainer){
2162 if (Roo.isTouch && e.type == 'touchstart' && t.menu && !t.disabled) {
2163 if(t == this.activeItem && t.shouldDeactivate(e)){
2164 this.activeItem.deactivate();
2165 delete this.activeItem;
2169 this.setActiveItem(t, true);
2177 Roo.log('pass click event');
2181 this.fireEvent("click", this, t, e);
2185 if(!t.href.length || t.href == '#'){
2186 (function() { _this.hide(); }).defer(100);
2191 onMouseOver : function(e){
2192 var t = this.findTargetItem(e);
2195 // if(t.canActivate && !t.disabled){
2196 // this.setActiveItem(t, true);
2200 this.fireEvent("mouseover", this, e, t);
2202 isVisible : function(){
2203 return !this.hidden;
2205 onMouseOut : function(e){
2206 var t = this.findTargetItem(e);
2209 // if(t == this.activeItem && t.shouldDeactivate(e)){
2210 // this.activeItem.deactivate();
2211 // delete this.activeItem;
2214 this.fireEvent("mouseout", this, e, t);
2219 * Displays this menu relative to another element
2220 * @param {String/HTMLElement/Roo.Element} element The element to align to
2221 * @param {String} position (optional) The {@link Roo.Element#alignTo} anchor position to use in aligning to
2222 * the element (defaults to this.defaultAlign)
2223 * @param {Roo.menu.Menu} parentMenu (optional) This menu's parent menu, if applicable (defaults to undefined)
2225 show : function(el, pos, parentMenu){
2226 this.parentMenu = parentMenu;
2230 this.fireEvent("beforeshow", this);
2231 this.showAt(this.el.getAlignToXY(el, pos || this.defaultAlign), parentMenu, false);
2234 * Displays this menu at a specific xy position
2235 * @param {Array} xyPosition Contains X & Y [x, y] values for the position at which to show the menu (coordinates are page-based)
2236 * @param {Roo.menu.Menu} parentMenu (optional) This menu's parent menu, if applicable (defaults to undefined)
2238 showAt : function(xy, parentMenu, /* private: */_e){
2239 this.parentMenu = parentMenu;
2244 this.fireEvent("beforeshow", this);
2245 //xy = this.el.adjustForConstraints(xy);
2249 this.hideMenuItems();
2250 this.hidden = false;
2251 this.triggerEl.addClass('open');
2253 // reassign x when hitting right
2254 if(this.el.getWidth() + xy[0] >= Roo.lib.Dom.getViewWidth()){
2255 xy[0] = xy[0] - this.el.getWidth() + this.triggerEl.getWidth();
2258 // reassign y when hitting bottom
2259 if(this.el.getHeight() + xy[1] >= Roo.lib.Dom.getViewHeight()){
2260 xy[1] = xy[1] - this.el.getHeight() - this.triggerEl.getHeight();
2263 // but the list may align on trigger left or trigger top... should it be a properity?
2265 if(this.el.getStyle('top') != 'auto' && this.el.getStyle('top').slice(-1) != "%"){
2270 this.fireEvent("show", this);
2276 this.doFocus.defer(50, this);
2280 doFocus : function(){
2282 this.focusEl.focus();
2287 * Hides this menu and optionally all parent menus
2288 * @param {Boolean} deep (optional) True to hide all parent menus recursively, if any (defaults to false)
2290 hide : function(deep)
2293 this.hideMenuItems();
2294 if(this.el && this.isVisible()){
2295 this.fireEvent("beforehide", this);
2296 if(this.activeItem){
2297 this.activeItem.deactivate();
2298 this.activeItem = null;
2300 this.triggerEl.removeClass('open');;
2302 this.fireEvent("hide", this);
2304 if(deep === true && this.parentMenu){
2305 this.parentMenu.hide(true);
2309 onTriggerClick : function(e)
2311 Roo.log('trigger click');
2313 var target = e.getTarget();
2315 Roo.log(target.nodeName.toLowerCase());
2317 if(target.nodeName.toLowerCase() === 'i'){
2323 onTriggerPress : function(e)
2325 Roo.log('trigger press');
2326 //Roo.log(e.getTarget());
2327 // Roo.log(this.triggerEl.dom);
2329 // trigger only occurs on normal menu's -- if it's a treeview or dropdown... do not hide/show..
2330 var pel = Roo.get(e.getTarget());
2331 if (pel.findParent('.dropdown-menu') || pel.findParent('.treeview-menu') ) {
2332 Roo.log('is treeview or dropdown?');
2336 if(e.getTarget().nodeName.toLowerCase() !== 'i' && this.isLink){
2340 if (this.isVisible()) {
2345 this.show(this.triggerEl, false, false);
2348 if(this.stopEvent || e.getTarget().nodeName.toLowerCase() === 'i'){
2355 hideMenuItems : function()
2357 Roo.log("hide Menu Items");
2361 //$(backdrop).remove()
2362 this.el.select('.open',true).each(function(aa) {
2364 aa.removeClass('open');
2365 //var parent = getParent($(this))
2366 //var relatedTarget = { relatedTarget: this }
2368 //$parent.trigger(e = $.Event('hide.bs.dropdown', relatedTarget))
2369 //if (e.isDefaultPrevented()) return
2370 //$parent.removeClass('open').trigger('hidden.bs.dropdown', relatedTarget)
2373 addxtypeChild : function (tree, cntr) {
2374 var comp= Roo.bootstrap.Menu.superclass.addxtypeChild.call(this, tree, cntr);
2376 this.menuitems.add(comp);
2388 this.getEl().dom.innerHTML = '';
2389 this.menuitems.clear();
2403 * @class Roo.bootstrap.MenuItem
2404 * @extends Roo.bootstrap.Component
2405 * Bootstrap MenuItem class
2406 * @cfg {String} html the menu label
2407 * @cfg {String} href the link
2408 * @cfg {Boolean} preventDefault do not trigger A href on clicks (default false).
2409 * @cfg {Boolean} isContainer is it a container - just returns a drop down item..
2410 * @cfg {Boolean} active used on sidebars to highlight active itesm
2411 * @cfg {String} fa favicon to show on left of menu item.
2412 * @cfg {Roo.bootsrap.Menu} menu the child menu.
2416 * Create a new MenuItem
2417 * @param {Object} config The config object
2421 Roo.bootstrap.MenuItem = function(config){
2422 Roo.bootstrap.MenuItem.superclass.constructor.call(this, config);
2427 * The raw click event for the entire grid.
2428 * @param {Roo.bootstrap.MenuItem} this
2429 * @param {Roo.EventObject} e
2435 Roo.extend(Roo.bootstrap.MenuItem, Roo.bootstrap.Component, {
2439 preventDefault: false,
2440 isContainer : false,
2444 getAutoCreate : function(){
2446 if(this.isContainer){
2449 cls: 'dropdown-menu-item'
2463 if (this.fa !== false) {
2466 cls : 'fa fa-' + this.fa
2475 cls: 'dropdown-menu-item',
2478 if (this.parent().type == 'treeview') {
2479 cfg.cls = 'treeview-menu';
2482 cfg.cls += ' active';
2487 anc.href = this.href || cfg.cn[0].href ;
2488 ctag.html = this.html || cfg.cn[0].html ;
2492 initEvents: function()
2494 if (this.parent().type == 'treeview') {
2495 this.el.select('a').on('click', this.onClick, this);
2499 this.menu.parentType = this.xtype;
2500 this.menu.triggerEl = this.el;
2501 this.menu = this.addxtype(Roo.apply({}, this.menu));
2505 onClick : function(e)
2507 Roo.log('item on click ');
2509 if(this.preventDefault){
2512 //this.parent().hideMenuItems();
2514 this.fireEvent('click', this, e);
2533 * @class Roo.bootstrap.MenuSeparator
2534 * @extends Roo.bootstrap.Component
2535 * Bootstrap MenuSeparator class
2538 * Create a new MenuItem
2539 * @param {Object} config The config object
2543 Roo.bootstrap.MenuSeparator = function(config){
2544 Roo.bootstrap.MenuSeparator.superclass.constructor.call(this, config);
2547 Roo.extend(Roo.bootstrap.MenuSeparator, Roo.bootstrap.Component, {
2549 getAutoCreate : function(){
2568 * @class Roo.bootstrap.Modal
2569 * @extends Roo.bootstrap.Component
2570 * Bootstrap Modal class
2571 * @cfg {String} title Title of dialog
2572 * @cfg {String} html - the body of the dialog (for simple ones) - you can also use template..
2573 * @cfg {Roo.Template} tmpl - a template with variables. to use it, add a handler in show:method adn
2574 * @cfg {Boolean} specificTitle default false
2575 * @cfg {Array} buttons Array of buttons or standard button set..
2576 * @cfg {String} buttonPosition (left|right|center) default right
2577 * @cfg {Boolean} animate default true
2578 * @cfg {Boolean} allow_close default true
2579 * @cfg {Boolean} fitwindow default false
2580 * @cfg {String} size (sm|lg) default empty
2581 * @cfg {Number} max_width set the max width of modal
2585 * Create a new Modal Dialog
2586 * @param {Object} config The config object
2589 Roo.bootstrap.Modal = function(config){
2590 Roo.bootstrap.Modal.superclass.constructor.call(this, config);
2595 * The raw btnclick event for the button
2596 * @param {Roo.EventObject} e
2601 * Fire when dialog resize
2602 * @param {Roo.bootstrap.Modal} this
2603 * @param {Roo.EventObject} e
2607 this.buttons = this.buttons || [];
2610 this.tmpl = Roo.factory(this.tmpl);
2615 Roo.extend(Roo.bootstrap.Modal, Roo.bootstrap.Component, {
2617 title : 'test dialog',
2627 specificTitle: false,
2629 buttonPosition: 'right',
2650 onRender : function(ct, position)
2652 Roo.bootstrap.Component.superclass.onRender.call(this, ct, position);
2655 var cfg = Roo.apply({}, this.getAutoCreate());
2658 // cfg.name = typeof(this.name) == 'undefined' ? this.id : this.name;
2660 //if (!cfg.name.length) {
2664 cfg.cls += ' ' + this.cls;
2667 cfg.style = this.style;
2669 this.el = Roo.get(document.body).createChild(cfg, position);
2671 //var type = this.el.dom.type;
2674 if(this.tabIndex !== undefined){
2675 this.el.dom.setAttribute('tabIndex', this.tabIndex);
2678 this.dialogEl = this.el.select('.modal-dialog',true).first();
2679 this.bodyEl = this.el.select('.modal-body',true).first();
2680 this.closeEl = this.el.select('.modal-header .close', true).first();
2681 this.headerEl = this.el.select('.modal-header',true).first();
2682 this.titleEl = this.el.select('.modal-title',true).first();
2683 this.footerEl = this.el.select('.modal-footer',true).first();
2685 this.maskEl = Roo.DomHelper.append(document.body, {tag: "div", cls:"x-dlg-mask"}, true);
2687 //this.el.addClass("x-dlg-modal");
2689 if (this.buttons.length) {
2690 Roo.each(this.buttons, function(bb) {
2691 var b = Roo.apply({}, bb);
2692 b.xns = b.xns || Roo.bootstrap;
2693 b.xtype = b.xtype || 'Button';
2694 if (typeof(b.listeners) == 'undefined') {
2695 b.listeners = { click : this.onButtonClick.createDelegate(this) };
2698 var btn = Roo.factory(b);
2700 btn.render(this.el.select('.modal-footer div').first());
2704 // render the children.
2707 if(typeof(this.items) != 'undefined'){
2708 var items = this.items;
2711 for(var i =0;i < items.length;i++) {
2712 nitems.push(this.addxtype(Roo.apply({}, items[i])));
2716 this.items = nitems;
2718 // where are these used - they used to be body/close/footer
2722 //this.el.addClass([this.fieldClass, this.cls]);
2726 getAutoCreate : function()
2730 html : this.html || ''
2735 cls : 'modal-title',
2739 if(this.specificTitle){
2745 if (this.allow_close) {
2757 if(this.size.length){
2758 size = 'modal-' + this.size;
2765 cls: "modal-dialog " + size,
2768 cls : "modal-content",
2771 cls : 'modal-header',
2776 cls : 'modal-footer',
2780 cls: 'btn-' + this.buttonPosition
2797 modal.cls += ' fade';
2803 getChildContainer : function() {
2808 getButtonContainer : function() {
2809 return this.el.select('.modal-footer div',true).first();
2812 initEvents : function()
2814 if (this.allow_close) {
2815 this.closeEl.on('click', this.hide, this);
2817 Roo.EventManager.onWindowResize(this.resize, this, true);
2824 this.maskEl.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
2826 if (this.fitwindow) {
2827 var w = this.width || Roo.lib.Dom.getViewportWidth(true) - 30;
2828 var h = this.height || Roo.lib.Dom.getViewportHeight(true) - 60;
2832 if(!this.fitwindow && this.max_width !== 0){
2833 var w = Math.min(this.max_width, Roo.lib.Dom.getViewportWidth(true) - 30);
2834 // var h = this.height || Roo.lib.Dom.getViewportHeight(true) - 60;
2835 this.setSize(w,this.height);
2837 var view_height = Roo.lib.Dom.getViewportHeight(true) - 60;
2838 var modal_height = this.headerEl.getHeight() + this.bodyEl.getHeight() + this.footerEl.getHeight();
2840 Roo.log(view_height);
2841 Roo.log(modal_height);
2845 this.headerEl.getHeight() +
2846 this.bodyEl.getHeight() +
2847 this.footerEl.getHeight()
2850 this.setSize(w,view_height);
2856 setSize : function(w,h)
2866 if (!this.rendered) {
2870 //this.el.setStyle('display', 'block');
2871 this.el.removeClass('hideing');
2872 this.el.addClass('show');
2874 if(this.animate){ // element has 'fade' - so stuff happens after .3s ?- not sure why the delay?
2877 this.el.addClass('in');
2880 this.el.addClass('in');
2883 // not sure how we can show data in here..
2885 // this.getChildContainer().dom.innerHTML = this.tmpl.applyTemplate(this);
2888 Roo.get(document.body).addClass("x-body-masked");
2890 this.maskEl.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
2891 this.maskEl.setStyle('z-index', Roo.bootstrap.Modal.zIndex++);
2892 this.maskEl.addClass('show');
2896 this.fireEvent('show', this);
2898 // set zindex here - otherwise it appears to be ignored...
2899 this.el.setStyle('z-index', Roo.bootstrap.Modal.zIndex++);
2902 this.items.forEach( function(e) {
2903 e.layout ? e.layout() : false;
2911 if(this.fireEvent("beforehide", this) !== false){
2912 this.maskEl.removeClass('show');
2913 Roo.get(document.body).removeClass("x-body-masked");
2914 this.el.removeClass('in');
2915 this.el.select('.modal-dialog', true).first().setStyle('transform','');
2917 if(this.animate){ // why
2918 this.el.addClass('hideing');
2920 if (!this.el.hasClass('hideing')) {
2921 return; // it's been shown again...
2923 this.el.removeClass('show');
2924 this.el.removeClass('hideing');
2928 this.el.removeClass('show');
2930 this.fireEvent('hide', this);
2933 isVisible : function()
2936 return this.el.hasClass('show') && !this.el.hasClass('hideing');
2940 addButton : function(str, cb)
2944 var b = Roo.apply({}, { html : str } );
2945 b.xns = b.xns || Roo.bootstrap;
2946 b.xtype = b.xtype || 'Button';
2947 if (typeof(b.listeners) == 'undefined') {
2948 b.listeners = { click : cb.createDelegate(this) };
2951 var btn = Roo.factory(b);
2953 btn.render(this.el.select('.modal-footer div').first());
2959 setDefaultButton : function(btn)
2961 //this.el.select('.modal-footer').()
2965 resizeTo: function(w,h)
2969 this.dialogEl.setWidth(w);
2970 if (this.diff === false) {
2971 this.diff = this.dialogEl.getHeight() - this.bodyEl.getHeight();
2974 this.bodyEl.setHeight(h-this.diff);
2976 this.fireEvent('resize', this);
2979 setContentSize : function(w, h)
2983 onButtonClick: function(btn,e)
2986 this.fireEvent('btnclick', btn.name, e);
2989 * Set the title of the Dialog
2990 * @param {String} str new Title
2992 setTitle: function(str) {
2993 this.titleEl.dom.innerHTML = str;
2996 * Set the body of the Dialog
2997 * @param {String} str new Title
2999 setBody: function(str) {
3000 this.bodyEl.dom.innerHTML = str;
3003 * Set the body of the Dialog using the template
3004 * @param {Obj} data - apply this data to the template and replace the body contents.
3006 applyBody: function(obj)
3009 Roo.log("Error - using apply Body without a template");
3012 this.tmpl.overwrite(this.bodyEl, obj);
3018 Roo.apply(Roo.bootstrap.Modal, {
3020 * Button config that displays a single OK button
3029 * Button config that displays Yes and No buttons
3045 * Button config that displays OK and Cancel buttons
3060 * Button config that displays Yes, No and Cancel buttons
3084 * messagebox - can be used as a replace
3088 * @class Roo.MessageBox
3089 * Utility class for generating different styles of message boxes. The alias Roo.Msg can also be used.
3093 Roo.Msg.alert('Status', 'Changes saved successfully.');
3095 // Prompt for user data:
3096 Roo.Msg.prompt('Name', 'Please enter your name:', function(btn, text){
3098 // process text value...
3102 // Show a dialog using config options:
3104 title:'Save Changes?',
3105 msg: 'Your are closing a tab that has unsaved changes. Would you like to save your changes?',
3106 buttons: Roo.Msg.YESNOCANCEL,
3113 Roo.bootstrap.MessageBox = function(){
3114 var dlg, opt, mask, waitTimer;
3115 var bodyEl, msgEl, textboxEl, textareaEl, progressEl, pp;
3116 var buttons, activeTextEl, bwidth;
3120 var handleButton = function(button){
3122 Roo.callback(opt.fn, opt.scope||window, [button, activeTextEl.dom.value], 1);
3126 var handleHide = function(){
3128 dlg.el.removeClass(opt.cls);
3131 // Roo.TaskMgr.stop(waitTimer);
3132 // waitTimer = null;
3137 var updateButtons = function(b){
3140 buttons["ok"].hide();
3141 buttons["cancel"].hide();
3142 buttons["yes"].hide();
3143 buttons["no"].hide();
3144 //dlg.footer.dom.style.display = 'none';
3147 dlg.footerEl.dom.style.display = '';
3148 for(var k in buttons){
3149 if(typeof buttons[k] != "function"){
3152 buttons[k].setText(typeof b[k] == "string" ? b[k] : Roo.bootstrap.MessageBox.buttonText[k]);
3153 width += buttons[k].el.getWidth()+15;
3163 var handleEsc = function(d, k, e){
3164 if(opt && opt.closable !== false){
3174 * Returns a reference to the underlying {@link Roo.BasicDialog} element
3175 * @return {Roo.BasicDialog} The BasicDialog element
3177 getDialog : function(){
3179 dlg = new Roo.bootstrap.Modal( {
3182 //constraintoviewport:false,
3184 //collapsible : false,
3189 //buttonAlign:"center",
3190 closeClick : function(){
3191 if(opt && opt.buttons && opt.buttons.no && !opt.buttons.cancel){
3194 handleButton("cancel");
3199 dlg.on("hide", handleHide);
3201 //dlg.addKeyListener(27, handleEsc);
3203 this.buttons = buttons;
3204 var bt = this.buttonText;
3205 buttons["ok"] = dlg.addButton(bt["ok"], handleButton.createCallback("ok"));
3206 buttons["yes"] = dlg.addButton(bt["yes"], handleButton.createCallback("yes"));
3207 buttons["no"] = dlg.addButton(bt["no"], handleButton.createCallback("no"));
3208 buttons["cancel"] = dlg.addButton(bt["cancel"], handleButton.createCallback("cancel"));
3210 bodyEl = dlg.bodyEl.createChild({
3212 html:'<span class="roo-mb-text"></span><br /><input type="text" class="roo-mb-input" />' +
3213 '<textarea class="roo-mb-textarea"></textarea>' +
3214 '<div class="roo-mb-progress-wrap"><div class="roo-mb-progress"><div class="roo-mb-progress-bar"> </div></div></div>'
3216 msgEl = bodyEl.dom.firstChild;
3217 textboxEl = Roo.get(bodyEl.dom.childNodes[2]);
3218 textboxEl.enableDisplayMode();
3219 textboxEl.addKeyListener([10,13], function(){
3220 if(dlg.isVisible() && opt && opt.buttons){
3223 }else if(opt.buttons.yes){
3224 handleButton("yes");
3228 textareaEl = Roo.get(bodyEl.dom.childNodes[3]);
3229 textareaEl.enableDisplayMode();
3230 progressEl = Roo.get(bodyEl.dom.childNodes[4]);
3231 progressEl.enableDisplayMode();
3233 // This is supposed to be the progessElement.. but I think it's controlling the height of everything..
3234 var pf = progressEl.dom.firstChild;
3236 pp = Roo.get(pf.firstChild);
3237 pp.setHeight(pf.offsetHeight);
3245 * Updates the message box body text
3246 * @param {String} text (optional) Replaces the message box element's innerHTML with the specified string (defaults to
3247 * the XHTML-compliant non-breaking space character '&#160;')
3248 * @return {Roo.MessageBox} This message box
3250 updateText : function(text)
3252 if(!dlg.isVisible() && !opt.width){
3253 dlg.dialogEl.setStyle({ 'max-width' : this.maxWidth});
3254 // dlg.resizeTo(this.maxWidth, 100); // forcing the height breaks long alerts()
3256 msgEl.innerHTML = text || ' ';
3258 var cw = Math.max(msgEl.offsetWidth, msgEl.parentNode.scrollWidth);
3259 //Roo.log("guesed size: " + JSON.stringify([cw,msgEl.offsetWidth, msgEl.parentNode.scrollWidth]));
3261 Math.min(opt.width || cw , this.maxWidth),
3262 Math.max(opt.minWidth || this.minWidth, bwidth)
3265 activeTextEl.setWidth(w);
3267 if(dlg.isVisible()){
3268 dlg.fixedcenter = false;
3270 // to big, make it scroll. = But as usual stupid IE does not support
3273 if ( bodyEl.getHeight() > (Roo.lib.Dom.getViewHeight() - 100)) {
3274 bodyEl.setHeight ( Roo.lib.Dom.getViewHeight() - 100 );
3275 bodyEl.dom.style.overflowY = 'auto' + ( Roo.isIE ? '' : ' !important');
3277 bodyEl.dom.style.height = '';
3278 bodyEl.dom.style.overflowY = '';
3281 bodyEl.dom.style.get = 'auto' + ( Roo.isIE ? '' : ' !important');
3283 bodyEl.dom.style.overflowX = '';
3286 dlg.setContentSize(w, bodyEl.getHeight());
3287 if(dlg.isVisible()){
3288 dlg.fixedcenter = true;
3294 * Updates a progress-style message box's text and progress bar. Only relevant on message boxes
3295 * initiated via {@link Roo.MessageBox#progress} or by calling {@link Roo.MessageBox#show} with progress: true.
3296 * @param {Number} value Any number between 0 and 1 (e.g., .5)
3297 * @param {String} text (optional) If defined, the message box's body text is replaced with the specified string (defaults to undefined)
3298 * @return {Roo.MessageBox} This message box
3300 updateProgress : function(value, text){
3302 this.updateText(text);
3305 if (pp) { // weird bug on my firefox - for some reason this is not defined
3306 pp.setWidth(Math.floor(value*progressEl.dom.firstChild.offsetWidth));
3307 pp.setHeight(Math.floor(progressEl.dom.firstChild.offsetHeight));
3313 * Returns true if the message box is currently displayed
3314 * @return {Boolean} True if the message box is visible, else false
3316 isVisible : function(){
3317 return dlg && dlg.isVisible();
3321 * Hides the message box if it is displayed
3324 if(this.isVisible()){
3330 * Displays a new message box, or reinitializes an existing message box, based on the config options
3331 * passed in. All functions (e.g. prompt, alert, etc) on MessageBox call this function internally.
3332 * The following config object properties are supported:
3334 Property Type Description
3335 ---------- --------------- ------------------------------------------------------------------------------------
3336 animEl String/Element An id or Element from which the message box should animate as it opens and
3337 closes (defaults to undefined)
3338 buttons Object/Boolean A button config object (e.g., Roo.MessageBox.OKCANCEL or {ok:'Foo',
3339 cancel:'Bar'}), or false to not show any buttons (defaults to false)
3340 closable Boolean False to hide the top-right close button (defaults to true). Note that
3341 progress and wait dialogs will ignore this property and always hide the
3342 close button as they can only be closed programmatically.
3343 cls String A custom CSS class to apply to the message box element
3344 defaultTextHeight Number The default height in pixels of the message box's multiline textarea if
3345 displayed (defaults to 75)
3346 fn Function A callback function to execute after closing the dialog. The arguments to the
3347 function will be btn (the name of the button that was clicked, if applicable,
3348 e.g. "ok"), and text (the value of the active text field, if applicable).
3349 Progress and wait dialogs will ignore this option since they do not respond to
3350 user actions and can only be closed programmatically, so any required function
3351 should be called by the same code after it closes the dialog.
3352 icon String A CSS class that provides a background image to be used as an icon for
3353 the dialog (e.g., Roo.MessageBox.WARNING or 'custom-class', defaults to '')
3354 maxWidth Number The maximum width in pixels of the message box (defaults to 600)
3355 minWidth Number The minimum width in pixels of the message box (defaults to 100)
3356 modal Boolean False to allow user interaction with the page while the message box is
3357 displayed (defaults to true)
3358 msg String A string that will replace the existing message box body text (defaults
3359 to the XHTML-compliant non-breaking space character ' ')
3360 multiline Boolean True to prompt the user to enter multi-line text (defaults to false)
3361 progress Boolean True to display a progress bar (defaults to false)
3362 progressText String The text to display inside the progress bar if progress = true (defaults to '')
3363 prompt Boolean True to prompt the user to enter single-line text (defaults to false)
3364 proxyDrag Boolean True to display a lightweight proxy while dragging (defaults to false)
3365 title String The title text
3366 value String The string value to set into the active textbox element if displayed
3367 wait Boolean True to display a progress bar (defaults to false)
3368 width Number The width of the dialog in pixels
3375 msg: 'Please enter your address:',
3377 buttons: Roo.MessageBox.OKCANCEL,
3380 animEl: 'addAddressBtn'
3383 * @param {Object} config Configuration options
3384 * @return {Roo.MessageBox} This message box
3386 show : function(options)
3389 // this causes nightmares if you show one dialog after another
3390 // especially on callbacks..
3392 if(this.isVisible()){
3395 Roo.log("[Roo.Messagebox] Show called while message displayed:" );
3396 Roo.log("Old Dialog Message:" + msgEl.innerHTML );
3397 Roo.log("New Dialog Message:" + options.msg )
3398 //this.alert("ERROR", "Multiple dialogs where displayed at the same time");
3399 //throw "Roo.MessageBox ERROR : Multiple dialogs where displayed at the same time";
3402 var d = this.getDialog();
3404 d.setTitle(opt.title || " ");
3405 d.closeEl.setDisplayed(opt.closable !== false);
3406 activeTextEl = textboxEl;
3407 opt.prompt = opt.prompt || (opt.multiline ? true : false);
3412 textareaEl.setHeight(typeof opt.multiline == "number" ?
3413 opt.multiline : this.defaultTextHeight);
3414 activeTextEl = textareaEl;
3423 progressEl.setDisplayed(opt.progress === true);
3424 this.updateProgress(0);
3425 activeTextEl.dom.value = opt.value || "";
3427 dlg.setDefaultButton(activeTextEl);
3429 var bs = opt.buttons;
3433 }else if(bs && bs.yes){
3434 db = buttons["yes"];
3436 dlg.setDefaultButton(db);
3438 bwidth = updateButtons(opt.buttons);
3439 this.updateText(opt.msg);
3441 d.el.addClass(opt.cls);
3443 d.proxyDrag = opt.proxyDrag === true;
3444 d.modal = opt.modal !== false;
3445 d.mask = opt.modal !== false ? mask : false;
3447 // force it to the end of the z-index stack so it gets a cursor in FF
3448 document.body.appendChild(dlg.el.dom);
3449 d.animateTarget = null;
3450 d.show(options.animEl);
3456 * Displays a message box with a progress bar. This message box has no buttons and is not closeable by
3457 * the user. You are responsible for updating the progress bar as needed via {@link Roo.MessageBox#updateProgress}
3458 * and closing the message box when the process is complete.
3459 * @param {String} title The title bar text
3460 * @param {String} msg The message box body text
3461 * @return {Roo.MessageBox} This message box
3463 progress : function(title, msg){
3470 minWidth: this.minProgressWidth,
3477 * Displays a standard read-only message box with an OK button (comparable to the basic JavaScript Window.alert).
3478 * If a callback function is passed it will be called after the user clicks the button, and the
3479 * id of the button that was clicked will be passed as the only parameter to the callback
3480 * (could also be the top-right close button).
3481 * @param {String} title The title bar text
3482 * @param {String} msg The message box body text
3483 * @param {Function} fn (optional) The callback function invoked after the message box is closed
3484 * @param {Object} scope (optional) The scope of the callback function
3485 * @return {Roo.MessageBox} This message box
3487 alert : function(title, msg, fn, scope)
3502 * Displays a message box with an infinitely auto-updating progress bar. This can be used to block user
3503 * interaction while waiting for a long-running process to complete that does not have defined intervals.
3504 * You are responsible for closing the message box when the process is complete.
3505 * @param {String} msg The message box body text
3506 * @param {String} title (optional) The title bar text
3507 * @return {Roo.MessageBox} This message box
3509 wait : function(msg, title){
3520 waitTimer = Roo.TaskMgr.start({
3522 Roo.MessageBox.updateProgress(((((i+20)%20)+1)*5)*.01);
3530 * Displays a confirmation message box with Yes and No buttons (comparable to JavaScript's Window.confirm).
3531 * If a callback function is passed it will be called after the user clicks either button, and the id of the
3532 * button that was clicked will be passed as the only parameter to the callback (could also be the top-right close button).
3533 * @param {String} title The title bar text
3534 * @param {String} msg The message box body text
3535 * @param {Function} fn (optional) The callback function invoked after the message box is closed
3536 * @param {Object} scope (optional) The scope of the callback function
3537 * @return {Roo.MessageBox} This message box
3539 confirm : function(title, msg, fn, scope){
3543 buttons: this.YESNO,
3552 * Displays a message box with OK and Cancel buttons prompting the user to enter some text (comparable to
3553 * JavaScript's Window.prompt). The prompt can be a single-line or multi-line textbox. If a callback function
3554 * is passed it will be called after the user clicks either button, and the id of the button that was clicked
3555 * (could also be the top-right close button) and the text that was entered will be passed as the two
3556 * parameters to the callback.
3557 * @param {String} title The title bar text
3558 * @param {String} msg The message box body text
3559 * @param {Function} fn (optional) The callback function invoked after the message box is closed
3560 * @param {Object} scope (optional) The scope of the callback function
3561 * @param {Boolean/Number} multiline (optional) True to create a multiline textbox using the defaultTextHeight
3562 * property, or the height in pixels to create the textbox (defaults to false / single-line)
3563 * @return {Roo.MessageBox} This message box
3565 prompt : function(title, msg, fn, scope, multiline){
3569 buttons: this.OKCANCEL,
3574 multiline: multiline,
3581 * Button config that displays a single OK button
3586 * Button config that displays Yes and No buttons
3589 YESNO : {yes:true, no:true},
3591 * Button config that displays OK and Cancel buttons
3594 OKCANCEL : {ok:true, cancel:true},
3596 * Button config that displays Yes, No and Cancel buttons
3599 YESNOCANCEL : {yes:true, no:true, cancel:true},
3602 * The default height in pixels of the message box's multiline textarea if displayed (defaults to 75)
3605 defaultTextHeight : 75,
3607 * The maximum width in pixels of the message box (defaults to 600)
3612 * The minimum width in pixels of the message box (defaults to 100)
3617 * The minimum width in pixels of the message box if it is a progress-style dialog. This is useful
3618 * for setting a different minimum width than text-only dialogs may need (defaults to 250)
3621 minProgressWidth : 250,
3623 * An object containing the default button text strings that can be overriden for localized language support.
3624 * Supported properties are: ok, cancel, yes and no.
3625 * Customize the default text like so: Roo.MessageBox.buttonText.yes = "S?";
3638 * Shorthand for {@link Roo.MessageBox}
3640 Roo.MessageBox = Roo.MessageBox || Roo.bootstrap.MessageBox;
3641 Roo.Msg = Roo.Msg || Roo.MessageBox;
3650 * @class Roo.bootstrap.Navbar
3651 * @extends Roo.bootstrap.Component
3652 * Bootstrap Navbar class
3655 * Create a new Navbar
3656 * @param {Object} config The config object
3660 Roo.bootstrap.Navbar = function(config){
3661 Roo.bootstrap.Navbar.superclass.constructor.call(this, config);
3665 * @event beforetoggle
3666 * Fire before toggle the menu
3667 * @param {Roo.EventObject} e
3669 "beforetoggle" : true
3673 Roo.extend(Roo.bootstrap.Navbar, Roo.bootstrap.Component, {
3682 getAutoCreate : function(){
3685 throw { message : "nav bar is now a abstract base class - use NavSimplebar / NavHeaderbar / NavSidebar etc..."};
3689 initEvents :function ()
3691 //Roo.log(this.el.select('.navbar-toggle',true));
3692 this.el.select('.navbar-toggle',true).on('click', function() {
3693 if(this.fireEvent('beforetoggle', this) !== false){
3694 this.el.select('.navbar-collapse',true).toggleClass('in');
3704 this.maskEl = Roo.DomHelper.append(this.el, mark, true);
3706 var size = this.el.getSize();
3707 this.maskEl.setSize(size.width, size.height);
3708 this.maskEl.enableDisplayMode("block");
3717 getChildContainer : function()
3719 if (this.el.select('.collapse').getCount()) {
3720 return this.el.select('.collapse',true).first();
3753 * @class Roo.bootstrap.NavSimplebar
3754 * @extends Roo.bootstrap.Navbar
3755 * Bootstrap Sidebar class
3757 * @cfg {Boolean} inverse is inverted color
3759 * @cfg {String} type (nav | pills | tabs)
3760 * @cfg {Boolean} arrangement stacked | justified
3761 * @cfg {String} align (left | right) alignment
3763 * @cfg {Boolean} main (true|false) main nav bar? default false
3764 * @cfg {Boolean} loadMask (true|false) loadMask on the bar
3766 * @cfg {String} tag (header|footer|nav|div) default is nav
3772 * Create a new Sidebar
3773 * @param {Object} config The config object
3777 Roo.bootstrap.NavSimplebar = function(config){
3778 Roo.bootstrap.NavSimplebar.superclass.constructor.call(this, config);
3781 Roo.extend(Roo.bootstrap.NavSimplebar, Roo.bootstrap.Navbar, {
3797 getAutoCreate : function(){
3801 tag : this.tag || 'div',
3814 this.type = this.type || 'nav';
3815 if (['tabs','pills'].indexOf(this.type)!==-1) {
3816 cfg.cn[0].cls += ' nav-' + this.type
3820 if (this.type!=='nav') {
3821 Roo.log('nav type must be nav/tabs/pills')
3823 cfg.cn[0].cls += ' navbar-nav'
3829 if (['stacked','justified'].indexOf(this.arrangement)!==-1) {
3830 cfg.cn[0].cls += ' nav-' + this.arrangement;
3834 if (this.align === 'right') {
3835 cfg.cn[0].cls += ' navbar-right';
3839 cfg.cls += ' navbar-inverse';
3866 * @class Roo.bootstrap.NavHeaderbar
3867 * @extends Roo.bootstrap.NavSimplebar
3868 * Bootstrap Sidebar class
3870 * @cfg {String} brand what is brand
3871 * @cfg {String} position (fixed-top|fixed-bottom|static-top) position
3872 * @cfg {String} brand_href href of the brand
3873 * @cfg {Boolean} srButton generate the (screen reader / mobile) sr-only button default true
3874 * @cfg {Boolean} autohide a top nav bar header that hides on scroll.
3875 * @cfg {Boolean} desktopCenter should the header be centered on desktop using a container class
3876 * @cfg {Roo.bootstrap.Row} mobilerow - a row to display on mobile only..
3879 * Create a new Sidebar
3880 * @param {Object} config The config object
3884 Roo.bootstrap.NavHeaderbar = function(config){
3885 Roo.bootstrap.NavHeaderbar.superclass.constructor.call(this, config);
3889 Roo.extend(Roo.bootstrap.NavHeaderbar, Roo.bootstrap.NavSimplebar, {
3896 desktopCenter : false,
3899 getAutoCreate : function(){
3902 tag: this.nav || 'nav',
3909 if (this.desktopCenter) {
3910 cn.push({cls : 'container', cn : []});
3917 cls: 'navbar-header',
3922 cls: 'navbar-toggle',
3923 'data-toggle': 'collapse',
3928 html: 'Toggle navigation'
3950 cls: 'collapse navbar-collapse',
3954 cfg.cls += this.inverse ? ' navbar-inverse' : ' navbar-default';
3956 if (['fixed-top','fixed-bottom','static-top'].indexOf(this.position)>-1) {
3957 cfg.cls += ' navbar-' + this.position;
3959 // tag can override this..
3961 cfg.tag = this.tag || (this.position == 'fixed-bottom' ? 'footer' : 'header');
3964 if (this.brand !== '') {
3967 href: this.brand_href ? this.brand_href : '#',
3968 cls: 'navbar-brand',
3976 cfg.cls += ' main-nav';
3984 getHeaderChildContainer : function()
3986 if (this.srButton && this.el.select('.navbar-header').getCount()) {
3987 return this.el.select('.navbar-header',true).first();
3990 return this.getChildContainer();
3994 initEvents : function()
3996 Roo.bootstrap.NavHeaderbar.superclass.initEvents.call(this);
3998 if (this.autohide) {
4003 Roo.get(document).on('scroll',function(e) {
4004 var ns = Roo.get(document).getScroll().top;
4005 var os = prevScroll;
4009 ft.removeClass('slideDown');
4010 ft.addClass('slideUp');
4013 ft.removeClass('slideUp');
4014 ft.addClass('slideDown');
4035 * @class Roo.bootstrap.NavSidebar
4036 * @extends Roo.bootstrap.Navbar
4037 * Bootstrap Sidebar class
4040 * Create a new Sidebar
4041 * @param {Object} config The config object
4045 Roo.bootstrap.NavSidebar = function(config){
4046 Roo.bootstrap.NavSidebar.superclass.constructor.call(this, config);
4049 Roo.extend(Roo.bootstrap.NavSidebar, Roo.bootstrap.Navbar, {
4051 sidebar : true, // used by Navbar Item and NavbarGroup at present...
4053 getAutoCreate : function(){
4058 cls: 'sidebar sidebar-nav'
4080 * @class Roo.bootstrap.NavGroup
4081 * @extends Roo.bootstrap.Component
4082 * Bootstrap NavGroup class
4083 * @cfg {String} align (left|right)
4084 * @cfg {Boolean} inverse
4085 * @cfg {String} type (nav|pills|tab) default nav
4086 * @cfg {String} navId - reference Id for navbar.
4090 * Create a new nav group
4091 * @param {Object} config The config object
4094 Roo.bootstrap.NavGroup = function(config){
4095 Roo.bootstrap.NavGroup.superclass.constructor.call(this, config);
4098 Roo.bootstrap.NavGroup.register(this);
4102 * Fires when the active item changes
4103 * @param {Roo.bootstrap.NavGroup} this
4104 * @param {Roo.bootstrap.Navbar.Item} selected The item selected
4105 * @param {Roo.bootstrap.Navbar.Item} prev The previously selected item
4112 Roo.extend(Roo.bootstrap.NavGroup, Roo.bootstrap.Component, {
4123 getAutoCreate : function()
4125 var cfg = Roo.apply({}, Roo.bootstrap.NavGroup.superclass.getAutoCreate.call(this));
4132 if (['tabs','pills'].indexOf(this.type)!==-1) {
4133 cfg.cls += ' nav-' + this.type
4135 if (this.type!=='nav') {
4136 Roo.log('nav type must be nav/tabs/pills')
4138 cfg.cls += ' navbar-nav'
4141 if (this.parent() && this.parent().sidebar) {
4144 cls: 'dashboard-menu sidebar-menu'
4150 if (this.form === true) {
4156 if (this.align === 'right') {
4157 cfg.cls += ' navbar-right';
4159 cfg.cls += ' navbar-left';
4163 if (this.align === 'right') {
4164 cfg.cls += ' navbar-right';
4168 cfg.cls += ' navbar-inverse';
4176 * sets the active Navigation item
4177 * @param {Roo.bootstrap.NavItem} the new current navitem
4179 setActiveItem : function(item)
4182 Roo.each(this.navItems, function(v){
4187 v.setActive(false, true);
4194 item.setActive(true, true);
4195 this.fireEvent('changed', this, item, prev);
4200 * gets the active Navigation item
4201 * @return {Roo.bootstrap.NavItem} the current navitem
4203 getActive : function()
4207 Roo.each(this.navItems, function(v){
4218 indexOfNav : function()
4222 Roo.each(this.navItems, function(v,i){
4233 * adds a Navigation item
4234 * @param {Roo.bootstrap.NavItem} the navitem to add
4236 addItem : function(cfg)
4238 var cn = new Roo.bootstrap.NavItem(cfg);
4240 cn.parentId = this.id;
4241 cn.onRender(this.el, null);
4245 * register a Navigation item
4246 * @param {Roo.bootstrap.NavItem} the navitem to add
4248 register : function(item)
4250 this.navItems.push( item);
4251 item.navId = this.navId;
4256 * clear all the Navigation item
4259 clearAll : function()
4262 this.el.dom.innerHTML = '';
4265 getNavItem: function(tabId)
4268 Roo.each(this.navItems, function(e) {
4269 if (e.tabId == tabId) {
4279 setActiveNext : function()
4281 var i = this.indexOfNav(this.getActive());
4282 if (i > this.navItems.length) {
4285 this.setActiveItem(this.navItems[i+1]);
4287 setActivePrev : function()
4289 var i = this.indexOfNav(this.getActive());
4293 this.setActiveItem(this.navItems[i-1]);
4295 clearWasActive : function(except) {
4296 Roo.each(this.navItems, function(e) {
4297 if (e.tabId != except.tabId && e.was_active) {
4298 e.was_active = false;
4305 getWasActive : function ()
4308 Roo.each(this.navItems, function(e) {
4323 Roo.apply(Roo.bootstrap.NavGroup, {
4327 * register a Navigation Group
4328 * @param {Roo.bootstrap.NavGroup} the navgroup to add
4330 register : function(navgrp)
4332 this.groups[navgrp.navId] = navgrp;
4336 * fetch a Navigation Group based on the navigation ID
4337 * @param {string} the navgroup to add
4338 * @returns {Roo.bootstrap.NavGroup} the navgroup
4340 get: function(navId) {
4341 if (typeof(this.groups[navId]) == 'undefined') {
4343 //this.register(new Roo.bootstrap.NavGroup({ navId : navId }));
4345 return this.groups[navId] ;
4360 * @class Roo.bootstrap.NavItem
4361 * @extends Roo.bootstrap.Component
4362 * Bootstrap Navbar.NavItem class
4363 * @cfg {String} href link to
4364 * @cfg {String} html content of button
4365 * @cfg {String} badge text inside badge
4366 * @cfg {String} badgecls (bg-green|bg-red|bg-yellow)the extra classes for the badge
4367 * @cfg {String} glyphicon name of glyphicon
4368 * @cfg {String} icon name of font awesome icon
4369 * @cfg {Boolean} active Is item active
4370 * @cfg {Boolean} disabled Is item disabled
4372 * @cfg {Boolean} preventDefault (true | false) default false
4373 * @cfg {String} tabId the tab that this item activates.
4374 * @cfg {String} tagtype (a|span) render as a href or span?
4375 * @cfg {Boolean} animateRef (true|false) link to element default false
4378 * Create a new Navbar Item
4379 * @param {Object} config The config object
4381 Roo.bootstrap.NavItem = function(config){
4382 Roo.bootstrap.NavItem.superclass.constructor.call(this, config);
4387 * The raw click event for the entire grid.
4388 * @param {Roo.EventObject} e
4393 * Fires when the active item active state changes
4394 * @param {Roo.bootstrap.NavItem} this
4395 * @param {boolean} state the new state
4401 * Fires when scroll to element
4402 * @param {Roo.bootstrap.NavItem} this
4403 * @param {Object} options
4404 * @param {Roo.EventObject} e
4412 Roo.extend(Roo.bootstrap.NavItem, Roo.bootstrap.Component, {
4420 preventDefault : false,
4427 getAutoCreate : function(){
4436 cfg.cls = typeof(cfg.cls) == 'undefined' ? 'active' : cfg.cls + ' active';
4438 if (this.disabled) {
4439 cfg.cls += ' disabled';
4442 if (this.href || this.html || this.glyphicon || this.icon) {
4446 href : this.href || "#",
4447 html: this.html || ''
4452 cfg.cn[0].html = '<i class="'+this.icon+'"></i> <span>' + cfg.cn[0].html + '</span>'
4455 if(this.glyphicon) {
4456 cfg.cn[0].html = '<span class="glyphicon glyphicon-' + this.glyphicon + '"></span> ' + cfg.cn[0].html;
4461 cfg.cn[0].html += " <span class='caret'></span>";
4465 if (this.badge !== '') {
4467 cfg.cn[0].html += ' <span class="badge">' + this.badge + '</span>';
4475 initEvents: function()
4477 if (typeof (this.menu) != 'undefined') {
4478 this.menu.parentType = this.xtype;
4479 this.menu.triggerEl = this.el;
4480 this.menu = this.addxtype(Roo.apply({}, this.menu));
4483 this.el.select('a',true).on('click', this.onClick, this);
4485 if(this.tagtype == 'span'){
4486 this.el.select('span',true).on('click', this.onClick, this);
4489 // at this point parent should be available..
4490 this.parent().register(this);
4493 onClick : function(e)
4495 if (e.getTarget('.dropdown-menu-item')) {
4496 // did you click on a menu itemm.... - then don't trigger onclick..
4501 this.preventDefault ||
4504 Roo.log("NavItem - prevent Default?");
4508 if (this.disabled) {
4512 var tg = Roo.bootstrap.TabGroup.get(this.navId);
4513 if (tg && tg.transition) {
4514 Roo.log("waiting for the transitionend");
4520 //Roo.log("fire event clicked");
4521 if(this.fireEvent('click', this, e) === false){
4525 if(this.tagtype == 'span'){
4529 //Roo.log(this.href);
4530 var ael = this.el.select('a',true).first();
4533 if(ael && this.animateRef && this.href.indexOf('#') > -1){
4534 //Roo.log(["test:",ael.dom.href.split("#")[0], document.location.toString().split("#")[0]]);
4535 if (ael.dom.href.split("#")[0] != document.location.toString().split("#")[0]) {
4536 return; // ignore... - it's a 'hash' to another page.
4538 Roo.log("NavItem - prevent Default?");
4540 this.scrollToElement(e);
4544 var p = this.parent();
4546 if (['tabs','pills'].indexOf(p.type)!==-1) {
4547 if (typeof(p.setActiveItem) !== 'undefined') {
4548 p.setActiveItem(this);
4552 // if parent is a navbarheader....- and link is probably a '#' page ref.. then remove the expanded menu.
4553 if (p.parentType == 'NavHeaderbar' && !this.menu) {
4554 // remove the collapsed menu expand...
4555 p.parent().el.select('.navbar-collapse',true).removeClass('in');
4559 isActive: function () {
4562 setActive : function(state, fire, is_was_active)
4564 if (this.active && !state && this.navId) {
4565 this.was_active = true;
4566 var nv = Roo.bootstrap.NavGroup.get(this.navId);
4568 nv.clearWasActive(this);
4572 this.active = state;
4575 this.el.removeClass('active');
4576 } else if (!this.el.hasClass('active')) {
4577 this.el.addClass('active');
4580 this.fireEvent('changed', this, state);
4583 // show a panel if it's registered and related..
4585 if (!this.navId || !this.tabId || !state || is_was_active) {
4589 var tg = Roo.bootstrap.TabGroup.get(this.navId);
4593 var pan = tg.getPanelByName(this.tabId);
4597 // if we can not flip to new panel - go back to old nav highlight..
4598 if (false == tg.showPanel(pan)) {
4599 var nv = Roo.bootstrap.NavGroup.get(this.navId);
4601 var onav = nv.getWasActive();
4603 onav.setActive(true, false, true);
4612 // this should not be here...
4613 setDisabled : function(state)
4615 this.disabled = state;
4617 this.el.removeClass('disabled');
4618 } else if (!this.el.hasClass('disabled')) {
4619 this.el.addClass('disabled');
4625 * Fetch the element to display the tooltip on.
4626 * @return {Roo.Element} defaults to this.el
4628 tooltipEl : function()
4630 return this.el.select('' + this.tagtype + '', true).first();
4633 scrollToElement : function(e)
4635 var c = document.body;
4638 * Firefox / IE places the overflow at the html level, unless specifically styled to behave differently.
4640 if(Roo.isFirefox || Roo.isIE || Roo.isIE11){
4641 c = document.documentElement;
4644 var target = Roo.get(c).select('a[name=' + this.href.split('#')[1] +']', true).first();
4650 var o = target.calcOffsetsTo(c);
4657 this.fireEvent('scrollto', this, options, e);
4659 Roo.get(c).scrollTo('top', options.value, true);
4672 * <span> icon </span>
4673 * <span> text </span>
4674 * <span>badge </span>
4678 * @class Roo.bootstrap.NavSidebarItem
4679 * @extends Roo.bootstrap.NavItem
4680 * Bootstrap Navbar.NavSidebarItem class
4681 * {String} badgeWeight (default|primary|success|info|warning|danger)the extra classes for the badge
4682 * {Boolean} open is the menu open
4683 * {Boolean} buttonView use button as the tigger el rather that a (default false)
4684 * {String} buttonWeight (default|primary|success|info|warning|danger)the extra classes for the button
4685 * {String} buttonSize (sm|md|lg)the extra classes for the button
4686 * {Boolean} showArrow show arrow next to the text (default true)
4688 * Create a new Navbar Button
4689 * @param {Object} config The config object
4691 Roo.bootstrap.NavSidebarItem = function(config){
4692 Roo.bootstrap.NavSidebarItem.superclass.constructor.call(this, config);
4697 * The raw click event for the entire grid.
4698 * @param {Roo.EventObject} e
4703 * Fires when the active item active state changes
4704 * @param {Roo.bootstrap.NavSidebarItem} this
4705 * @param {boolean} state the new state
4713 Roo.extend(Roo.bootstrap.NavSidebarItem, Roo.bootstrap.NavItem, {
4715 badgeWeight : 'default',
4721 buttonWeight : 'default',
4727 getAutoCreate : function(){
4732 href : this.href || '#',
4738 if(this.buttonView){
4741 href : this.href || '#',
4742 cls: 'btn btn-' + this.buttonWeight + ' btn-' + this.buttonSize + 'roo-button-dropdown-toggle',
4755 cfg.cls += ' active';
4758 if (this.disabled) {
4759 cfg.cls += ' disabled';
4762 cfg.cls += ' open x-open';
4765 if (this.glyphicon || this.icon) {
4766 var c = this.glyphicon ? ('glyphicon glyphicon-'+this.glyphicon) : this.icon;
4767 a.cn.push({ tag : 'i', cls : c }) ;
4770 if(!this.buttonView){
4773 html : this.html || ''
4780 if (this.badge !== '') {
4781 a.cn.push({ tag: 'span', cls : 'badge pull-right badge-' + this.badgeWeight, html: this.badge });
4787 a.cn.push({ tag : 'i', cls : 'glyphicon glyphicon-chevron-down pull-right'});
4790 a.cls += ' dropdown-toggle treeview' ;
4796 initEvents : function()
4798 if (typeof (this.menu) != 'undefined') {
4799 this.menu.parentType = this.xtype;
4800 this.menu.triggerEl = this.el;
4801 this.menu = this.addxtype(Roo.apply({}, this.menu));
4804 this.el.on('click', this.onClick, this);
4806 if(this.badge !== ''){
4807 this.badgeEl = this.el.select('.badge', true).first().setVisibilityMode(Roo.Element.DISPLAY);
4812 onClick : function(e)
4819 if(this.preventDefault){
4823 this.fireEvent('click', this);
4826 disable : function()
4828 this.setDisabled(true);
4833 this.setDisabled(false);
4836 setDisabled : function(state)
4838 if(this.disabled == state){
4842 this.disabled = state;
4845 this.el.addClass('disabled');
4849 this.el.removeClass('disabled');
4854 setActive : function(state)
4856 if(this.active == state){
4860 this.active = state;
4863 this.el.addClass('active');
4867 this.el.removeClass('active');
4872 isActive: function ()
4877 setBadge : function(str)
4883 this.badgeEl.dom.innerHTML = str;
4900 * @class Roo.bootstrap.Row
4901 * @extends Roo.bootstrap.Component
4902 * Bootstrap Row class (contains columns...)
4906 * @param {Object} config The config object
4909 Roo.bootstrap.Row = function(config){
4910 Roo.bootstrap.Row.superclass.constructor.call(this, config);
4913 Roo.extend(Roo.bootstrap.Row, Roo.bootstrap.Component, {
4915 getAutoCreate : function(){
4934 * @class Roo.bootstrap.Element
4935 * @extends Roo.bootstrap.Component
4936 * Bootstrap Element class
4937 * @cfg {String} html contents of the element
4938 * @cfg {String} tag tag of the element
4939 * @cfg {String} cls class of the element
4940 * @cfg {Boolean} preventDefault (true|false) default false
4941 * @cfg {Boolean} clickable (true|false) default false
4944 * Create a new Element
4945 * @param {Object} config The config object
4948 Roo.bootstrap.Element = function(config){
4949 Roo.bootstrap.Element.superclass.constructor.call(this, config);
4955 * When a element is chick
4956 * @param {Roo.bootstrap.Element} this
4957 * @param {Roo.EventObject} e
4963 Roo.extend(Roo.bootstrap.Element, Roo.bootstrap.Component, {
4968 preventDefault: false,
4971 getAutoCreate : function(){
4975 // cls: this.cls, double assign in parent class Component.js :: onRender
4982 initEvents: function()
4984 Roo.bootstrap.Element.superclass.initEvents.call(this);
4987 this.el.on('click', this.onClick, this);
4992 onClick : function(e)
4994 if(this.preventDefault){
4998 this.fireEvent('click', this, e);
5001 getValue : function()
5003 return this.el.dom.innerHTML;
5006 setValue : function(value)
5008 this.el.dom.innerHTML = value;
5023 * @class Roo.bootstrap.Pagination
5024 * @extends Roo.bootstrap.Component
5025 * Bootstrap Pagination class
5026 * @cfg {String} size xs | sm | md | lg
5027 * @cfg {Boolean} inverse false | true
5030 * Create a new Pagination
5031 * @param {Object} config The config object
5034 Roo.bootstrap.Pagination = function(config){
5035 Roo.bootstrap.Pagination.superclass.constructor.call(this, config);
5038 Roo.extend(Roo.bootstrap.Pagination, Roo.bootstrap.Component, {
5044 getAutoCreate : function(){
5050 cfg.cls += ' inverse';
5056 cfg.cls += " " + this.cls;
5074 * @class Roo.bootstrap.PaginationItem
5075 * @extends Roo.bootstrap.Component
5076 * Bootstrap PaginationItem class
5077 * @cfg {String} html text
5078 * @cfg {String} href the link
5079 * @cfg {Boolean} preventDefault (true | false) default true
5080 * @cfg {Boolean} active (true | false) default false
5081 * @cfg {Boolean} disabled default false
5085 * Create a new PaginationItem
5086 * @param {Object} config The config object
5090 Roo.bootstrap.PaginationItem = function(config){
5091 Roo.bootstrap.PaginationItem.superclass.constructor.call(this, config);
5096 * The raw click event for the entire grid.
5097 * @param {Roo.EventObject} e
5103 Roo.extend(Roo.bootstrap.PaginationItem, Roo.bootstrap.Component, {
5107 preventDefault: true,
5112 getAutoCreate : function(){
5118 href : this.href ? this.href : '#',
5119 html : this.html ? this.html : ''
5129 cfg.cls = typeof(cfg.cls) !== 'undefined' ? cfg.cls + ' disabled' : 'disabled';
5133 cfg.cls = typeof(cfg.cls) !== 'undefined' ? cfg.cls + ' active' : 'active';
5139 initEvents: function() {
5141 this.el.on('click', this.onClick, this);
5144 onClick : function(e)
5146 Roo.log('PaginationItem on click ');
5147 if(this.preventDefault){
5155 this.fireEvent('click', this, e);
5171 * @class Roo.bootstrap.Slider
5172 * @extends Roo.bootstrap.Component
5173 * Bootstrap Slider class
5176 * Create a new Slider
5177 * @param {Object} config The config object
5180 Roo.bootstrap.Slider = function(config){
5181 Roo.bootstrap.Slider.superclass.constructor.call(this, config);
5184 Roo.extend(Roo.bootstrap.Slider, Roo.bootstrap.Component, {
5186 getAutoCreate : function(){
5190 cls: 'slider slider-sample1 vertical-handler ui-slider ui-slider-horizontal ui-widget ui-widget-content ui-corner-all',
5194 cls: 'ui-slider-handle ui-state-default ui-corner-all'
5206 * Ext JS Library 1.1.1
5207 * Copyright(c) 2006-2007, Ext JS, LLC.
5209 * Originally Released Under LGPL - original licence link has changed is not relivant.
5212 * <script type="text/javascript">
5217 * @class Roo.grid.ColumnModel
5218 * @extends Roo.util.Observable
5219 * This is the default implementation of a ColumnModel used by the Grid. It defines
5220 * the columns in the grid.
5223 var colModel = new Roo.grid.ColumnModel([
5224 {header: "Ticker", width: 60, sortable: true, locked: true},
5225 {header: "Company Name", width: 150, sortable: true},
5226 {header: "Market Cap.", width: 100, sortable: true},
5227 {header: "$ Sales", width: 100, sortable: true, renderer: money},
5228 {header: "Employees", width: 100, sortable: true, resizable: false}
5233 * The config options listed for this class are options which may appear in each
5234 * individual column definition.
5235 * <br/>RooJS Fix - column id's are not sequential but use Roo.id() - fixes bugs with layouts.
5237 * @param {Object} config An Array of column config objects. See this class's
5238 * config objects for details.
5240 Roo.grid.ColumnModel = function(config){
5242 * The config passed into the constructor
5244 this.config = config;
5247 // if no id, create one
5248 // if the column does not have a dataIndex mapping,
5249 // map it to the order it is in the config
5250 for(var i = 0, len = config.length; i < len; i++){
5252 if(typeof c.dataIndex == "undefined"){
5255 if(typeof c.renderer == "string"){
5256 c.renderer = Roo.util.Format[c.renderer];
5258 if(typeof c.id == "undefined"){
5261 if(c.editor && c.editor.xtype){
5262 c.editor = Roo.factory(c.editor, Roo.grid);
5264 if(c.editor && c.editor.isFormField){
5265 c.editor = new Roo.grid.GridEditor(c.editor);
5267 this.lookup[c.id] = c;
5271 * The width of columns which have no width specified (defaults to 100)
5274 this.defaultWidth = 100;
5277 * Default sortable of columns which have no sortable specified (defaults to false)
5280 this.defaultSortable = false;
5284 * @event widthchange
5285 * Fires when the width of a column changes.
5286 * @param {ColumnModel} this
5287 * @param {Number} columnIndex The column index
5288 * @param {Number} newWidth The new width
5290 "widthchange": true,
5292 * @event headerchange
5293 * Fires when the text of a header changes.
5294 * @param {ColumnModel} this
5295 * @param {Number} columnIndex The column index
5296 * @param {Number} newText The new header text
5298 "headerchange": true,
5300 * @event hiddenchange
5301 * Fires when a column is hidden or "unhidden".
5302 * @param {ColumnModel} this
5303 * @param {Number} columnIndex The column index
5304 * @param {Boolean} hidden true if hidden, false otherwise
5306 "hiddenchange": true,
5308 * @event columnmoved
5309 * Fires when a column is moved.
5310 * @param {ColumnModel} this
5311 * @param {Number} oldIndex
5312 * @param {Number} newIndex
5314 "columnmoved" : true,
5316 * @event columlockchange
5317 * Fires when a column's locked state is changed
5318 * @param {ColumnModel} this
5319 * @param {Number} colIndex
5320 * @param {Boolean} locked true if locked
5322 "columnlockchange" : true
5324 Roo.grid.ColumnModel.superclass.constructor.call(this);
5326 Roo.extend(Roo.grid.ColumnModel, Roo.util.Observable, {
5328 * @cfg {String} header The header text to display in the Grid view.
5331 * @cfg {String} dataIndex (Optional) The name of the field in the grid's {@link Roo.data.Store}'s
5332 * {@link Roo.data.Record} definition from which to draw the column's value. If not
5333 * specified, the column's index is used as an index into the Record's data Array.
5336 * @cfg {Number} width (Optional) The initial width in pixels of the column. Using this
5337 * instead of {@link Roo.grid.Grid#autoSizeColumns} is more efficient.
5340 * @cfg {Boolean} sortable (Optional) True if sorting is to be allowed on this column.
5341 * Defaults to the value of the {@link #defaultSortable} property.
5342 * Whether local/remote sorting is used is specified in {@link Roo.data.Store#remoteSort}.
5345 * @cfg {Boolean} locked (Optional) True to lock the column in place while scrolling the Grid. Defaults to false.
5348 * @cfg {Boolean} fixed (Optional) True if the column width cannot be changed. Defaults to false.
5351 * @cfg {Boolean} resizable (Optional) False to disable column resizing. Defaults to true.
5354 * @cfg {Boolean} hidden (Optional) True to hide the column. Defaults to false.
5357 * @cfg {Function} renderer (Optional) A function used to generate HTML markup for a cell
5358 * given the cell's data value. See {@link #setRenderer}. If not specified, the
5359 * default renderer returns the escaped data value. If an object is returned (bootstrap only)
5360 * then it is treated as a Roo Component object instance, and it is rendered after the initial row is rendered
5363 * @cfg {Roo.grid.GridEditor} editor (Optional) For grid editors - returns the grid editor
5366 * @cfg {String} align (Optional) Set the CSS text-align property of the column. Defaults to undefined.
5369 * @cfg {String} valign (Optional) Set the CSS vertical-align property of the column (eg. middle, top, bottom etc). Defaults to undefined.
5372 * @cfg {String} cursor (Optional)
5375 * @cfg {String} tooltip (Optional)
5378 * @cfg {Number} xs (Optional)
5381 * @cfg {Number} sm (Optional)
5384 * @cfg {Number} md (Optional)
5387 * @cfg {Number} lg (Optional)
5390 * Returns the id of the column at the specified index.
5391 * @param {Number} index The column index
5392 * @return {String} the id
5394 getColumnId : function(index){
5395 return this.config[index].id;
5399 * Returns the column for a specified id.
5400 * @param {String} id The column id
5401 * @return {Object} the column
5403 getColumnById : function(id){
5404 return this.lookup[id];
5409 * Returns the column for a specified dataIndex.
5410 * @param {String} dataIndex The column dataIndex
5411 * @return {Object|Boolean} the column or false if not found
5413 getColumnByDataIndex: function(dataIndex){
5414 var index = this.findColumnIndex(dataIndex);
5415 return index > -1 ? this.config[index] : false;
5419 * Returns the index for a specified column id.
5420 * @param {String} id The column id
5421 * @return {Number} the index, or -1 if not found
5423 getIndexById : function(id){
5424 for(var i = 0, len = this.config.length; i < len; i++){
5425 if(this.config[i].id == id){
5433 * Returns the index for a specified column dataIndex.
5434 * @param {String} dataIndex The column dataIndex
5435 * @return {Number} the index, or -1 if not found
5438 findColumnIndex : function(dataIndex){
5439 for(var i = 0, len = this.config.length; i < len; i++){
5440 if(this.config[i].dataIndex == dataIndex){
5448 moveColumn : function(oldIndex, newIndex){
5449 var c = this.config[oldIndex];
5450 this.config.splice(oldIndex, 1);
5451 this.config.splice(newIndex, 0, c);
5452 this.dataMap = null;
5453 this.fireEvent("columnmoved", this, oldIndex, newIndex);
5456 isLocked : function(colIndex){
5457 return this.config[colIndex].locked === true;
5460 setLocked : function(colIndex, value, suppressEvent){
5461 if(this.isLocked(colIndex) == value){
5464 this.config[colIndex].locked = value;
5466 this.fireEvent("columnlockchange", this, colIndex, value);
5470 getTotalLockedWidth : function(){
5472 for(var i = 0; i < this.config.length; i++){
5473 if(this.isLocked(i) && !this.isHidden(i)){
5474 this.totalWidth += this.getColumnWidth(i);
5480 getLockedCount : function(){
5481 for(var i = 0, len = this.config.length; i < len; i++){
5482 if(!this.isLocked(i)){
5487 return this.config.length;
5491 * Returns the number of columns.
5494 getColumnCount : function(visibleOnly){
5495 if(visibleOnly === true){
5497 for(var i = 0, len = this.config.length; i < len; i++){
5498 if(!this.isHidden(i)){
5504 return this.config.length;
5508 * Returns the column configs that return true by the passed function that is called with (columnConfig, index)
5509 * @param {Function} fn
5510 * @param {Object} scope (optional)
5511 * @return {Array} result
5513 getColumnsBy : function(fn, scope){
5515 for(var i = 0, len = this.config.length; i < len; i++){
5516 var c = this.config[i];
5517 if(fn.call(scope||this, c, i) === true){
5525 * Returns true if the specified column is sortable.
5526 * @param {Number} col The column index
5529 isSortable : function(col){
5530 if(typeof this.config[col].sortable == "undefined"){
5531 return this.defaultSortable;
5533 return this.config[col].sortable;
5537 * Returns the rendering (formatting) function defined for the column.
5538 * @param {Number} col The column index.
5539 * @return {Function} The function used to render the cell. See {@link #setRenderer}.
5541 getRenderer : function(col){
5542 if(!this.config[col].renderer){
5543 return Roo.grid.ColumnModel.defaultRenderer;
5545 return this.config[col].renderer;
5549 * Sets the rendering (formatting) function for a column.
5550 * @param {Number} col The column index
5551 * @param {Function} fn The function to use to process the cell's raw data
5552 * to return HTML markup for the grid view. The render function is called with
5553 * the following parameters:<ul>
5554 * <li>Data value.</li>
5555 * <li>Cell metadata. An object in which you may set the following attributes:<ul>
5556 * <li>css A CSS style string to apply to the table cell.</li>
5557 * <li>attr An HTML attribute definition string to apply to the data container element <i>within</i> the table cell.</li></ul>
5558 * <li>The {@link Roo.data.Record} from which the data was extracted.</li>
5559 * <li>Row index</li>
5560 * <li>Column index</li>
5561 * <li>The {@link Roo.data.Store} object from which the Record was extracted</li></ul>
5563 setRenderer : function(col, fn){
5564 this.config[col].renderer = fn;
5568 * Returns the width for the specified column.
5569 * @param {Number} col The column index
5572 getColumnWidth : function(col){
5573 return this.config[col].width * 1 || this.defaultWidth;
5577 * Sets the width for a column.
5578 * @param {Number} col The column index
5579 * @param {Number} width The new width
5581 setColumnWidth : function(col, width, suppressEvent){
5582 this.config[col].width = width;
5583 this.totalWidth = null;
5585 this.fireEvent("widthchange", this, col, width);
5590 * Returns the total width of all columns.
5591 * @param {Boolean} includeHidden True to include hidden column widths
5594 getTotalWidth : function(includeHidden){
5595 if(!this.totalWidth){
5596 this.totalWidth = 0;
5597 for(var i = 0, len = this.config.length; i < len; i++){
5598 if(includeHidden || !this.isHidden(i)){
5599 this.totalWidth += this.getColumnWidth(i);
5603 return this.totalWidth;
5607 * Returns the header for the specified column.
5608 * @param {Number} col The column index
5611 getColumnHeader : function(col){
5612 return this.config[col].header;
5616 * Sets the header for a column.
5617 * @param {Number} col The column index
5618 * @param {String} header The new header
5620 setColumnHeader : function(col, header){
5621 this.config[col].header = header;
5622 this.fireEvent("headerchange", this, col, header);
5626 * Returns the tooltip for the specified column.
5627 * @param {Number} col The column index
5630 getColumnTooltip : function(col){
5631 return this.config[col].tooltip;
5634 * Sets the tooltip for a column.
5635 * @param {Number} col The column index
5636 * @param {String} tooltip The new tooltip
5638 setColumnTooltip : function(col, tooltip){
5639 this.config[col].tooltip = tooltip;
5643 * Returns the dataIndex for the specified column.
5644 * @param {Number} col The column index
5647 getDataIndex : function(col){
5648 return this.config[col].dataIndex;
5652 * Sets the dataIndex for a column.
5653 * @param {Number} col The column index
5654 * @param {Number} dataIndex The new dataIndex
5656 setDataIndex : function(col, dataIndex){
5657 this.config[col].dataIndex = dataIndex;
5663 * Returns true if the cell is editable.
5664 * @param {Number} colIndex The column index
5665 * @param {Number} rowIndex The row index - this is nto actually used..?
5668 isCellEditable : function(colIndex, rowIndex){
5669 return (this.config[colIndex].editable || (typeof this.config[colIndex].editable == "undefined" && this.config[colIndex].editor)) ? true : false;
5673 * Returns the editor defined for the cell/column.
5674 * return false or null to disable editing.
5675 * @param {Number} colIndex The column index
5676 * @param {Number} rowIndex The row index
5679 getCellEditor : function(colIndex, rowIndex){
5680 return this.config[colIndex].editor;
5684 * Sets if a column is editable.
5685 * @param {Number} col The column index
5686 * @param {Boolean} editable True if the column is editable
5688 setEditable : function(col, editable){
5689 this.config[col].editable = editable;
5694 * Returns true if the column is hidden.
5695 * @param {Number} colIndex The column index
5698 isHidden : function(colIndex){
5699 return this.config[colIndex].hidden;
5704 * Returns true if the column width cannot be changed
5706 isFixed : function(colIndex){
5707 return this.config[colIndex].fixed;
5711 * Returns true if the column can be resized
5714 isResizable : function(colIndex){
5715 return colIndex >= 0 && this.config[colIndex].resizable !== false && this.config[colIndex].fixed !== true;
5718 * Sets if a column is hidden.
5719 * @param {Number} colIndex The column index
5720 * @param {Boolean} hidden True if the column is hidden
5722 setHidden : function(colIndex, hidden){
5723 this.config[colIndex].hidden = hidden;
5724 this.totalWidth = null;
5725 this.fireEvent("hiddenchange", this, colIndex, hidden);
5729 * Sets the editor for a column.
5730 * @param {Number} col The column index
5731 * @param {Object} editor The editor object
5733 setEditor : function(col, editor){
5734 this.config[col].editor = editor;
5738 Roo.grid.ColumnModel.defaultRenderer = function(value)
5740 if(typeof value == "object") {
5743 if(typeof value == "string" && value.length < 1){
5747 return String.format("{0}", value);
5750 // Alias for backwards compatibility
5751 Roo.grid.DefaultColumnModel = Roo.grid.ColumnModel;
5754 * Ext JS Library 1.1.1
5755 * Copyright(c) 2006-2007, Ext JS, LLC.
5757 * Originally Released Under LGPL - original licence link has changed is not relivant.
5760 * <script type="text/javascript">
5764 * @class Roo.LoadMask
5765 * A simple utility class for generically masking elements while loading data. If the element being masked has
5766 * an underlying {@link Roo.data.Store}, the masking will be automatically synchronized with the store's loading
5767 * process and the mask element will be cached for reuse. For all other elements, this mask will replace the
5768 * element's UpdateManager load indicator and will be destroyed after the initial load.
5770 * Create a new LoadMask
5771 * @param {String/HTMLElement/Roo.Element} el The element or DOM node, or its id
5772 * @param {Object} config The config object
5774 Roo.LoadMask = function(el, config){
5775 this.el = Roo.get(el);
5776 Roo.apply(this, config);
5778 this.store.on('beforeload', this.onBeforeLoad, this);
5779 this.store.on('load', this.onLoad, this);
5780 this.store.on('loadexception', this.onLoadException, this);
5781 this.removeMask = false;
5783 var um = this.el.getUpdateManager();
5784 um.showLoadIndicator = false; // disable the default indicator
5785 um.on('beforeupdate', this.onBeforeLoad, this);
5786 um.on('update', this.onLoad, this);
5787 um.on('failure', this.onLoad, this);
5788 this.removeMask = true;
5792 Roo.LoadMask.prototype = {
5794 * @cfg {Boolean} removeMask
5795 * True to create a single-use mask that is automatically destroyed after loading (useful for page loads),
5796 * False to persist the mask element reference for multiple uses (e.g., for paged data widgets). Defaults to false.
5800 * The text to display in a centered loading message box (defaults to 'Loading...')
5804 * @cfg {String} msgCls
5805 * The CSS class to apply to the loading message element (defaults to "x-mask-loading")
5807 msgCls : 'x-mask-loading',
5810 * Read-only. True if the mask is currently disabled so that it will not be displayed (defaults to false)
5816 * Disables the mask to prevent it from being displayed
5818 disable : function(){
5819 this.disabled = true;
5823 * Enables the mask so that it can be displayed
5825 enable : function(){
5826 this.disabled = false;
5829 onLoadException : function()
5833 if (typeof(arguments[3]) != 'undefined') {
5834 Roo.MessageBox.alert("Error loading",arguments[3]);
5838 if (this.store && typeof(this.store.reader.jsonData.errorMsg) != 'undefined') {
5839 Roo.MessageBox.alert("Error loading",this.store.reader.jsonData.errorMsg);
5846 (function() { this.el.unmask(this.removeMask); }).defer(50, this);
5851 (function() { this.el.unmask(this.removeMask); }).defer(50, this);
5855 onBeforeLoad : function(){
5857 (function() { this.el.mask(this.msg, this.msgCls); }).defer(50, this);
5862 destroy : function(){
5864 this.store.un('beforeload', this.onBeforeLoad, this);
5865 this.store.un('load', this.onLoad, this);
5866 this.store.un('loadexception', this.onLoadException, this);
5868 var um = this.el.getUpdateManager();
5869 um.un('beforeupdate', this.onBeforeLoad, this);
5870 um.un('update', this.onLoad, this);
5871 um.un('failure', this.onLoad, this);
5882 * @class Roo.bootstrap.Table
5883 * @extends Roo.bootstrap.Component
5884 * Bootstrap Table class
5885 * @cfg {String} cls table class
5886 * @cfg {String} align (left|center|right) Specifies the alignment of a table according to surrounding text
5887 * @cfg {String} bgcolor Specifies the background color for a table
5888 * @cfg {Number} border Specifies whether the table cells should have borders or not
5889 * @cfg {Number} cellpadding Specifies the space between the cell wall and the cell content
5890 * @cfg {Number} cellspacing Specifies the space between cells
5891 * @cfg {String} frame Specifies which parts of the outside borders that should be visible
5892 * @cfg {String} rules Specifies which parts of the inside borders that should be visible
5893 * @cfg {String} sortable Specifies that the table should be sortable
5894 * @cfg {String} summary Specifies a summary of the content of a table
5895 * @cfg {Number} width Specifies the width of a table
5896 * @cfg {String} layout table layout (auto | fixed | initial | inherit)
5898 * @cfg {boolean} striped Should the rows be alternative striped
5899 * @cfg {boolean} bordered Add borders to the table
5900 * @cfg {boolean} hover Add hover highlighting
5901 * @cfg {boolean} condensed Format condensed
5902 * @cfg {boolean} responsive Format condensed
5903 * @cfg {Boolean} loadMask (true|false) default false
5904 * @cfg {Boolean} footerShow (true|false) generate tfoot, default true
5905 * @cfg {Boolean} headerShow (true|false) generate thead, default true
5906 * @cfg {Boolean} rowSelection (true|false) default false
5907 * @cfg {Boolean} cellSelection (true|false) default false
5908 * @cfg {Boolean} scrollBody (true|false) default false - body scrolled / fixed header
5909 * @cfg {Roo.bootstrap.PagingToolbar} footer a paging toolbar
5910 * @cfg {Boolean} lazyLoad auto load data while scrolling to the end (default false)
5911 * @cfg {Boolean} auto_hide_footer auto hide footer if only one page (default false)
5915 * Create a new Table
5916 * @param {Object} config The config object
5919 Roo.bootstrap.Table = function(config){
5920 Roo.bootstrap.Table.superclass.constructor.call(this, config);
5925 this.rowSelection = (typeof(config.rowSelection) != 'undefined') ? config.rowSelection : this.rowSelection;
5926 this.cellSelection = (typeof(config.cellSelection) != 'undefined') ? config.cellSelection : this.cellSelection;
5927 this.headerShow = (typeof(config.thead) != 'undefined') ? config.thead : this.headerShow;
5928 this.footerShow = (typeof(config.tfoot) != 'undefined') ? config.tfoot : this.footerShow;
5930 this.sm = this.sm || {xtype: 'RowSelectionModel'};
5932 this.sm.grid = this;
5933 this.selModel = Roo.factory(this.sm, Roo.bootstrap.Table);
5934 this.sm = this.selModel;
5935 this.sm.xmodule = this.xmodule || false;
5938 if (this.cm && typeof(this.cm.config) == 'undefined') {
5939 this.colModel = new Roo.grid.ColumnModel(this.cm);
5940 this.cm = this.colModel;
5941 this.cm.xmodule = this.xmodule || false;
5944 this.store= Roo.factory(this.store, Roo.data);
5945 this.ds = this.store;
5946 this.ds.xmodule = this.xmodule || false;
5949 if (this.footer && this.store) {
5950 this.footer.dataSource = this.ds;
5951 this.footer = Roo.factory(this.footer);
5958 * Fires when a cell is clicked
5959 * @param {Roo.bootstrap.Table} this
5960 * @param {Roo.Element} el
5961 * @param {Number} rowIndex
5962 * @param {Number} columnIndex
5963 * @param {Roo.EventObject} e
5967 * @event celldblclick
5968 * Fires when a cell is double clicked
5969 * @param {Roo.bootstrap.Table} this
5970 * @param {Roo.Element} el
5971 * @param {Number} rowIndex
5972 * @param {Number} columnIndex
5973 * @param {Roo.EventObject} e
5975 "celldblclick" : true,
5978 * Fires when a row is clicked
5979 * @param {Roo.bootstrap.Table} this
5980 * @param {Roo.Element} el
5981 * @param {Number} rowIndex
5982 * @param {Roo.EventObject} e
5986 * @event rowdblclick
5987 * Fires when a row is double clicked
5988 * @param {Roo.bootstrap.Table} this
5989 * @param {Roo.Element} el
5990 * @param {Number} rowIndex
5991 * @param {Roo.EventObject} e
5993 "rowdblclick" : true,
5996 * Fires when a mouseover occur
5997 * @param {Roo.bootstrap.Table} this
5998 * @param {Roo.Element} el
5999 * @param {Number} rowIndex
6000 * @param {Number} columnIndex
6001 * @param {Roo.EventObject} e
6006 * Fires when a mouseout occur
6007 * @param {Roo.bootstrap.Table} this
6008 * @param {Roo.Element} el
6009 * @param {Number} rowIndex
6010 * @param {Number} columnIndex
6011 * @param {Roo.EventObject} e
6016 * Fires when a row is rendered, so you can change add a style to it.
6017 * @param {Roo.bootstrap.Table} this
6018 * @param {Object} rowcfg contains record rowIndex colIndex and rowClass - set rowClass to add a style.
6022 * @event rowsrendered
6023 * Fires when all the rows have been rendered
6024 * @param {Roo.bootstrap.Table} this
6026 'rowsrendered' : true,
6028 * @event contextmenu
6029 * The raw contextmenu event for the entire grid.
6030 * @param {Roo.EventObject} e
6032 "contextmenu" : true,
6034 * @event rowcontextmenu
6035 * Fires when a row is right clicked
6036 * @param {Roo.bootstrap.Table} this
6037 * @param {Number} rowIndex
6038 * @param {Roo.EventObject} e
6040 "rowcontextmenu" : true,
6042 * @event cellcontextmenu
6043 * Fires when a cell is right clicked
6044 * @param {Roo.bootstrap.Table} this
6045 * @param {Number} rowIndex
6046 * @param {Number} cellIndex
6047 * @param {Roo.EventObject} e
6049 "cellcontextmenu" : true,
6051 * @event headercontextmenu
6052 * Fires when a header is right clicked
6053 * @param {Roo.bootstrap.Table} this
6054 * @param {Number} columnIndex
6055 * @param {Roo.EventObject} e
6057 "headercontextmenu" : true
6061 Roo.extend(Roo.bootstrap.Table, Roo.bootstrap.Component, {
6087 rowSelection : false,
6088 cellSelection : false,
6091 // Roo.Element - the tbody
6093 // Roo.Element - thead element
6096 container: false, // used by gridpanel...
6102 auto_hide_footer : false,
6104 getAutoCreate : function()
6106 var cfg = Roo.apply({}, Roo.bootstrap.Table.superclass.getAutoCreate.call(this));
6113 if (this.scrollBody) {
6114 cfg.cls += ' table-body-fixed';
6117 cfg.cls += ' table-striped';
6121 cfg.cls += ' table-hover';
6123 if (this.bordered) {
6124 cfg.cls += ' table-bordered';
6126 if (this.condensed) {
6127 cfg.cls += ' table-condensed';
6129 if (this.responsive) {
6130 cfg.cls += ' table-responsive';
6134 cfg.cls+= ' ' +this.cls;
6137 // this lot should be simplifed...
6150 ].forEach(function(k) {
6158 cfg.style = (typeof(cfg.style) == 'undefined') ? ('table-layout:' + this.layout + ';') : (cfg.style + ('table-layout:' + this.layout + ';'));
6161 if(this.store || this.cm){
6162 if(this.headerShow){
6163 cfg.cn.push(this.renderHeader());
6166 cfg.cn.push(this.renderBody());
6168 if(this.footerShow){
6169 cfg.cn.push(this.renderFooter());
6171 // where does this come from?
6172 //cfg.cls+= ' TableGrid';
6175 return { cn : [ cfg ] };
6178 initEvents : function()
6180 if(!this.store || !this.cm){
6183 if (this.selModel) {
6184 this.selModel.initEvents();
6188 //Roo.log('initEvents with ds!!!!');
6190 this.mainBody = this.el.select('tbody', true).first();
6191 this.mainHead = this.el.select('thead', true).first();
6192 this.mainFoot = this.el.select('tfoot', true).first();
6198 Roo.each(this.el.select('thead th.sortable', true).elements, function(e){
6199 e.on('click', _this.sort, _this);
6202 this.mainBody.on("click", this.onClick, this);
6203 this.mainBody.on("dblclick", this.onDblClick, this);
6205 // why is this done????? = it breaks dialogs??
6206 //this.parent().el.setStyle('position', 'relative');
6210 this.footer.parentId = this.id;
6211 this.footer.onRender(this.el.select('tfoot tr td').first(), null);
6214 this.el.select('tfoot tr td').first().addClass('hide');
6219 this.maskEl = new Roo.LoadMask(this.el, { store : this.ds, msgCls: 'roo-el-mask-msg' });
6222 this.store.on('load', this.onLoad, this);
6223 this.store.on('beforeload', this.onBeforeLoad, this);
6224 this.store.on('update', this.onUpdate, this);
6225 this.store.on('add', this.onAdd, this);
6226 this.store.on("clear", this.clear, this);
6228 this.el.on("contextmenu", this.onContextMenu, this);
6230 this.mainBody.on('scroll', this.onBodyScroll, this);
6232 this.cm.on("headerchange", this.onHeaderChange, this);
6234 this.cm.on("hiddenchange", this.onHiddenChange, this, arguments);
6238 onContextMenu : function(e, t)
6240 this.processEvent("contextmenu", e);
6243 processEvent : function(name, e)
6245 if (name != 'touchstart' ) {
6246 this.fireEvent(name, e);
6249 var t = e.getTarget();
6251 var cell = Roo.get(t);
6257 if(cell.findParent('tfoot', false, true)){
6261 if(cell.findParent('thead', false, true)){
6263 if(e.getTarget().nodeName.toLowerCase() != 'th'){
6264 cell = Roo.get(t).findParent('th', false, true);
6266 Roo.log("failed to find th in thead?");
6267 Roo.log(e.getTarget());
6272 var cellIndex = cell.dom.cellIndex;
6274 var ename = name == 'touchstart' ? 'click' : name;
6275 this.fireEvent("header" + ename, this, cellIndex, e);
6280 if(e.getTarget().nodeName.toLowerCase() != 'td'){
6281 cell = Roo.get(t).findParent('td', false, true);
6283 Roo.log("failed to find th in tbody?");
6284 Roo.log(e.getTarget());
6289 var row = cell.findParent('tr', false, true);
6290 var cellIndex = cell.dom.cellIndex;
6291 var rowIndex = row.dom.rowIndex - 1;
6295 this.fireEvent("row" + name, this, rowIndex, e);
6299 this.fireEvent("cell" + name, this, rowIndex, cellIndex, e);
6305 onMouseover : function(e, el)
6307 var cell = Roo.get(el);
6313 if(e.getTarget().nodeName.toLowerCase() != 'td'){
6314 cell = cell.findParent('td', false, true);
6317 var row = cell.findParent('tr', false, true);
6318 var cellIndex = cell.dom.cellIndex;
6319 var rowIndex = row.dom.rowIndex - 1; // start from 0
6321 this.fireEvent('mouseover', this, cell, rowIndex, cellIndex, e);
6325 onMouseout : function(e, el)
6327 var cell = Roo.get(el);
6333 if(e.getTarget().nodeName.toLowerCase() != 'td'){
6334 cell = cell.findParent('td', false, true);
6337 var row = cell.findParent('tr', false, true);
6338 var cellIndex = cell.dom.cellIndex;
6339 var rowIndex = row.dom.rowIndex - 1; // start from 0
6341 this.fireEvent('mouseout', this, cell, rowIndex, cellIndex, e);
6345 onClick : function(e, el)
6347 var cell = Roo.get(el);
6349 if(!cell || (!this.cellSelection && !this.rowSelection)){
6353 if(e.getTarget().nodeName.toLowerCase() != 'td'){
6354 cell = cell.findParent('td', false, true);
6357 if(!cell || typeof(cell) == 'undefined'){
6361 var row = cell.findParent('tr', false, true);
6363 if(!row || typeof(row) == 'undefined'){
6367 var cellIndex = cell.dom.cellIndex;
6368 var rowIndex = this.getRowIndex(row);
6370 // why??? - should these not be based on SelectionModel?
6371 if(this.cellSelection){
6372 this.fireEvent('cellclick', this, cell, rowIndex, cellIndex, e);
6375 if(this.rowSelection){
6376 this.fireEvent('rowclick', this, row, rowIndex, e);
6382 onDblClick : function(e,el)
6384 var cell = Roo.get(el);
6386 if(!cell || (!this.cellSelection && !this.rowSelection)){
6390 if(e.getTarget().nodeName.toLowerCase() != 'td'){
6391 cell = cell.findParent('td', false, true);
6394 if(!cell || typeof(cell) == 'undefined'){
6398 var row = cell.findParent('tr', false, true);
6400 if(!row || typeof(row) == 'undefined'){
6404 var cellIndex = cell.dom.cellIndex;
6405 var rowIndex = this.getRowIndex(row);
6407 if(this.cellSelection){
6408 this.fireEvent('celldblclick', this, cell, rowIndex, cellIndex, e);
6411 if(this.rowSelection){
6412 this.fireEvent('rowdblclick', this, row, rowIndex, e);
6416 sort : function(e,el)
6418 var col = Roo.get(el);
6420 if(!col.hasClass('sortable')){
6424 var sort = col.attr('sort');
6427 if(col.select('i', true).first().hasClass('glyphicon-arrow-up')){
6431 this.store.sortInfo = {field : sort, direction : dir};
6434 Roo.log("calling footer first");
6435 this.footer.onClick('first');
6438 this.store.load({ params : { start : 0 } });
6442 renderHeader : function()
6450 this.totalWidth = 0;
6452 for(var i = 0, len = cm.getColumnCount(); i < len; i++){
6454 var config = cm.config[i];
6458 cls : 'x-hcol-' + i,
6460 html: cm.getColumnHeader(i)
6465 if(typeof(config.sortable) != 'undefined' && config.sortable){
6467 c.html = '<i class="glyphicon"></i>' + c.html;
6470 if(typeof(config.lgHeader) != 'undefined'){
6471 hh += '<span class="hidden-xs hidden-sm hidden-md">' + config.lgHeader + '</span>';
6474 if(typeof(config.mdHeader) != 'undefined'){
6475 hh += '<span class="hidden-xs hidden-sm hidden-lg">' + config.mdHeader + '</span>';
6478 if(typeof(config.smHeader) != 'undefined'){
6479 hh += '<span class="hidden-xs hidden-md hidden-lg">' + config.smHeader + '</span>';
6482 if(typeof(config.xsHeader) != 'undefined'){
6483 hh += '<span class="hidden-sm hidden-md hidden-lg">' + config.xsHeader + '</span>';
6490 if(typeof(config.tooltip) != 'undefined'){
6491 c.tooltip = config.tooltip;
6494 if(typeof(config.colspan) != 'undefined'){
6495 c.colspan = config.colspan;
6498 if(typeof(config.hidden) != 'undefined' && config.hidden){
6499 c.style += ' display:none;';
6502 if(typeof(config.dataIndex) != 'undefined'){
6503 c.sort = config.dataIndex;
6508 if(typeof(config.align) != 'undefined' && config.align.length){
6509 c.style += ' text-align:' + config.align + ';';
6512 if(typeof(config.width) != 'undefined'){
6513 c.style += ' width:' + config.width + 'px;';
6514 this.totalWidth += config.width;
6516 this.totalWidth += 100; // assume minimum of 100 per column?
6519 if(typeof(config.cls) != 'undefined'){
6520 c.cls = (typeof(c.cls) == 'undefined') ? config.cls : (c.cls + ' ' + config.cls);
6523 ['xs','sm','md','lg'].map(function(size){
6525 if(typeof(config[size]) == 'undefined'){
6529 if (!config[size]) { // 0 = hidden
6530 c.cls += ' hidden-' + size;
6534 c.cls += ' col-' + size + '-' + config[size];
6544 renderBody : function()
6554 colspan : this.cm.getColumnCount()
6564 renderFooter : function()
6574 colspan : this.cm.getColumnCount()
6588 // Roo.log('ds onload');
6593 var ds = this.store;
6595 Roo.each(this.el.select('thead th.sortable', true).elements, function(e){
6596 e.select('i', true).removeClass(['glyphicon-arrow-up', 'glyphicon-arrow-down']);
6597 if (_this.store.sortInfo) {
6599 if(e.hasClass('sortable') && e.attr('sort') == _this.store.sortInfo.field && _this.store.sortInfo.direction.toUpperCase() == 'ASC'){
6600 e.select('i', true).addClass(['glyphicon-arrow-up']);
6603 if(e.hasClass('sortable') && e.attr('sort') == _this.store.sortInfo.field && _this.store.sortInfo.direction.toUpperCase() == 'DESC'){
6604 e.select('i', true).addClass(['glyphicon-arrow-down']);
6609 var tbody = this.mainBody;
6611 if(ds.getCount() > 0){
6612 ds.data.each(function(d,rowIndex){
6613 var row = this.renderRow(cm, ds, rowIndex);
6615 tbody.createChild(row);
6619 if(row.cellObjects.length){
6620 Roo.each(row.cellObjects, function(r){
6621 _this.renderCellObject(r);
6628 var tfoot = this.el.select('tfoot', true).first();
6630 if(this.footerShow && this.auto_hide_footer && this.mainFoot){
6632 this.mainFoot.setVisibilityMode(Roo.Element.DISPLAY).hide();
6634 var total = this.ds.getTotalCount();
6636 if(this.footer.pageSize < total){
6637 this.mainFoot.show();
6641 Roo.each(this.el.select('tbody td', true).elements, function(e){
6642 e.on('mouseover', _this.onMouseover, _this);
6645 Roo.each(this.el.select('tbody td', true).elements, function(e){
6646 e.on('mouseout', _this.onMouseout, _this);
6648 this.fireEvent('rowsrendered', this);
6654 onUpdate : function(ds,record)
6656 this.refreshRow(record);
6660 onRemove : function(ds, record, index, isUpdate){
6661 if(isUpdate !== true){
6662 this.fireEvent("beforerowremoved", this, index, record);
6664 var bt = this.mainBody.dom;
6666 var rows = this.el.select('tbody > tr', true).elements;
6668 if(typeof(rows[index]) != 'undefined'){
6669 bt.removeChild(rows[index].dom);
6672 // if(bt.rows[index]){
6673 // bt.removeChild(bt.rows[index]);
6676 if(isUpdate !== true){
6677 //this.stripeRows(index);
6678 //this.syncRowHeights(index, index);
6680 this.fireEvent("rowremoved", this, index, record);
6684 onAdd : function(ds, records, rowIndex)
6686 //Roo.log('on Add called');
6687 // - note this does not handle multiple adding very well..
6688 var bt = this.mainBody.dom;
6689 for (var i =0 ; i < records.length;i++) {
6690 //Roo.log('call insert row Add called on ' + rowIndex + ':' + i);
6691 //Roo.log(records[i]);
6692 //Roo.log(this.store.getAt(rowIndex+i));
6693 this.insertRow(this.store, rowIndex + i, false);
6700 refreshRow : function(record){
6701 var ds = this.store, index;
6702 if(typeof record == 'number'){
6704 record = ds.getAt(index);
6706 index = ds.indexOf(record);
6708 this.insertRow(ds, index, true);
6710 this.onRemove(ds, record, index+1, true);
6712 //this.syncRowHeights(index, index);
6714 this.fireEvent("rowupdated", this, index, record);
6717 insertRow : function(dm, rowIndex, isUpdate){
6720 this.fireEvent("beforerowsinserted", this, rowIndex);
6722 //var s = this.getScrollState();
6723 var row = this.renderRow(this.cm, this.store, rowIndex);
6724 // insert before rowIndex..
6725 var e = this.mainBody.createChild(row,this.getRowDom(rowIndex));
6729 if(row.cellObjects.length){
6730 Roo.each(row.cellObjects, function(r){
6731 _this.renderCellObject(r);
6736 this.fireEvent("rowsinserted", this, rowIndex);
6737 //this.syncRowHeights(firstRow, lastRow);
6738 //this.stripeRows(firstRow);
6745 getRowDom : function(rowIndex)
6747 var rows = this.el.select('tbody > tr', true).elements;
6749 return (typeof(rows[rowIndex]) == 'undefined') ? false : rows[rowIndex];
6752 // returns the object tree for a tr..
6755 renderRow : function(cm, ds, rowIndex)
6757 var d = ds.getAt(rowIndex);
6761 cls : 'x-row-' + rowIndex,
6765 var cellObjects = [];
6767 for(var i = 0, len = cm.getColumnCount(); i < len; i++){
6768 var config = cm.config[i];
6770 var renderer = cm.getRenderer(i);
6774 if(typeof(renderer) !== 'undefined'){
6775 value = renderer(d.data[cm.getDataIndex(i)], false, d);
6777 // if object are returned, then they are expected to be Roo.bootstrap.Component instances
6778 // and are rendered into the cells after the row is rendered - using the id for the element.
6780 if(typeof(value) === 'object'){
6790 rowIndex : rowIndex,
6795 this.fireEvent('rowclass', this, rowcfg);
6799 cls : rowcfg.rowClass + ' x-col-' + i,
6801 html: (typeof(value) === 'object') ? '' : value
6808 if(typeof(config.colspan) != 'undefined'){
6809 td.colspan = config.colspan;
6812 if(typeof(config.hidden) != 'undefined' && config.hidden){
6813 td.style += ' display:none;';
6816 if(typeof(config.align) != 'undefined' && config.align.length){
6817 td.style += ' text-align:' + config.align + ';';
6819 if(typeof(config.valign) != 'undefined' && config.valign.length){
6820 td.style += ' vertical-align:' + config.valign + ';';
6823 if(typeof(config.width) != 'undefined'){
6824 td.style += ' width:' + config.width + 'px;';
6827 if(typeof(config.cursor) != 'undefined'){
6828 td.style += ' cursor:' + config.cursor + ';';
6831 if(typeof(config.cls) != 'undefined'){
6832 td.cls = (typeof(td.cls) == 'undefined') ? config.cls : (td.cls + ' ' + config.cls);
6835 ['xs','sm','md','lg'].map(function(size){
6837 if(typeof(config[size]) == 'undefined'){
6841 if (!config[size]) { // 0 = hidden
6842 td.cls += ' hidden-' + size;
6846 td.cls += ' col-' + size + '-' + config[size];
6854 row.cellObjects = cellObjects;
6862 onBeforeLoad : function()
6871 this.el.select('tbody', true).first().dom.innerHTML = '';
6874 * Show or hide a row.
6875 * @param {Number} rowIndex to show or hide
6876 * @param {Boolean} state hide
6878 setRowVisibility : function(rowIndex, state)
6880 var bt = this.mainBody.dom;
6882 var rows = this.el.select('tbody > tr', true).elements;
6884 if(typeof(rows[rowIndex]) == 'undefined'){
6887 rows[rowIndex].dom.style.display = state ? '' : 'none';
6891 getSelectionModel : function(){
6893 this.selModel = new Roo.bootstrap.Table.RowSelectionModel({grid: this});
6895 return this.selModel;
6898 * Render the Roo.bootstrap object from renderder
6900 renderCellObject : function(r)
6904 r.cfg.parentId = (typeof(r.container) == 'string') ? r.container : r.container.id;
6906 var t = r.cfg.render(r.container);
6909 Roo.each(r.cfg.cn, function(c){
6911 container: t.getChildContainer(),
6914 _this.renderCellObject(child);
6919 getRowIndex : function(row)
6923 Roo.each(this.el.select('tbody > tr', true).elements, function(el, index){
6934 * Returns the grid's underlying element = used by panel.Grid
6935 * @return {Element} The element
6937 getGridEl : function(){
6941 * Forces a resize - used by panel.Grid
6942 * @return {Element} The element
6944 autoSize : function()
6946 //var ctr = Roo.get(this.container.dom.parentElement);
6947 var ctr = Roo.get(this.el.dom);
6949 var thd = this.getGridEl().select('thead',true).first();
6950 var tbd = this.getGridEl().select('tbody', true).first();
6951 var tfd = this.getGridEl().select('tfoot', true).first();
6953 var cw = ctr.getWidth();
6957 tbd.setSize(ctr.getWidth(),
6958 ctr.getHeight() - ((thd ? thd.getHeight() : 0) + (tfd ? tfd.getHeight() : 0))
6960 var barsize = (tbd.dom.offsetWidth - tbd.dom.clientWidth);
6963 cw = Math.max(cw, this.totalWidth);
6964 this.getGridEl().select('tr',true).setWidth(cw);
6965 // resize 'expandable coloumn?
6967 return; // we doe not have a view in this design..
6970 onBodyScroll: function()
6972 //Roo.log("body scrolled');" + this.mainBody.dom.scrollLeft);
6974 this.mainHead.setStyle({
6975 'position' : 'relative',
6976 'left': (-1* this.mainBody.dom.scrollLeft) + 'px'
6982 var scrollHeight = this.mainBody.dom.scrollHeight;
6984 var scrollTop = Math.ceil(this.mainBody.getScroll().top);
6986 var height = this.mainBody.getHeight();
6988 if(scrollHeight - height == scrollTop) {
6990 var total = this.ds.getTotalCount();
6992 if(this.footer.cursor + this.footer.pageSize < total){
6994 this.footer.ds.load({
6996 start : this.footer.cursor + this.footer.pageSize,
6997 limit : this.footer.pageSize
7007 onHeaderChange : function()
7009 var header = this.renderHeader();
7010 var table = this.el.select('table', true).first();
7012 this.mainHead.remove();
7013 this.mainHead = table.createChild(header, this.mainBody, false);
7016 onHiddenChange : function(colModel, colIndex, hidden)
7018 var thSelector = '#' + this.id + ' .x-hcol-' + colIndex;
7019 var tdSelector = '#' + this.id + ' .x-col-' + colIndex;
7021 this.CSS.updateRule(thSelector, "display", "");
7022 this.CSS.updateRule(tdSelector, "display", "");
7025 this.CSS.updateRule(thSelector, "display", "none");
7026 this.CSS.updateRule(tdSelector, "display", "none");
7029 this.onHeaderChange();
7046 * @class Roo.bootstrap.TableCell
7047 * @extends Roo.bootstrap.Component
7048 * Bootstrap TableCell class
7049 * @cfg {String} html cell contain text
7050 * @cfg {String} cls cell class
7051 * @cfg {String} tag cell tag (td|th) default td
7052 * @cfg {String} abbr Specifies an abbreviated version of the content in a cell
7053 * @cfg {String} align Aligns the content in a cell
7054 * @cfg {String} axis Categorizes cells
7055 * @cfg {String} bgcolor Specifies the background color of a cell
7056 * @cfg {Number} charoff Sets the number of characters the content will be aligned from the character specified by the char attribute
7057 * @cfg {Number} colspan Specifies the number of columns a cell should span
7058 * @cfg {String} headers Specifies one or more header cells a cell is related to
7059 * @cfg {Number} height Sets the height of a cell
7060 * @cfg {String} nowrap Specifies that the content inside a cell should not wrap
7061 * @cfg {Number} rowspan Sets the number of rows a cell should span
7062 * @cfg {String} scope Defines a way to associate header cells and data cells in a table
7063 * @cfg {String} valign Vertical aligns the content in a cell
7064 * @cfg {Number} width Specifies the width of a cell
7067 * Create a new TableCell
7068 * @param {Object} config The config object
7071 Roo.bootstrap.TableCell = function(config){
7072 Roo.bootstrap.TableCell.superclass.constructor.call(this, config);
7075 Roo.extend(Roo.bootstrap.TableCell, Roo.bootstrap.Component, {
7095 getAutoCreate : function(){
7096 var cfg = Roo.apply({}, Roo.bootstrap.TableCell.superclass.getAutoCreate.call(this));
7116 cfg.align=this.align
7122 cfg.bgcolor=this.bgcolor
7125 cfg.charoff=this.charoff
7128 cfg.colspan=this.colspan
7131 cfg.headers=this.headers
7134 cfg.height=this.height
7137 cfg.nowrap=this.nowrap
7140 cfg.rowspan=this.rowspan
7143 cfg.scope=this.scope
7146 cfg.valign=this.valign
7149 cfg.width=this.width
7168 * @class Roo.bootstrap.TableRow
7169 * @extends Roo.bootstrap.Component
7170 * Bootstrap TableRow class
7171 * @cfg {String} cls row class
7172 * @cfg {String} align Aligns the content in a table row
7173 * @cfg {String} bgcolor Specifies a background color for a table row
7174 * @cfg {Number} charoff Sets the number of characters the content will be aligned from the character specified by the char attribute
7175 * @cfg {String} valign Vertical aligns the content in a table row
7178 * Create a new TableRow
7179 * @param {Object} config The config object
7182 Roo.bootstrap.TableRow = function(config){
7183 Roo.bootstrap.TableRow.superclass.constructor.call(this, config);
7186 Roo.extend(Roo.bootstrap.TableRow, Roo.bootstrap.Component, {
7194 getAutoCreate : function(){
7195 var cfg = Roo.apply({}, Roo.bootstrap.TableRow.superclass.getAutoCreate.call(this));
7205 cfg.align = this.align;
7208 cfg.bgcolor = this.bgcolor;
7211 cfg.charoff = this.charoff;
7214 cfg.valign = this.valign;
7232 * @class Roo.bootstrap.TableBody
7233 * @extends Roo.bootstrap.Component
7234 * Bootstrap TableBody class
7235 * @cfg {String} cls element class
7236 * @cfg {String} tag element tag (thead|tbody|tfoot) default tbody
7237 * @cfg {String} align Aligns the content inside the element
7238 * @cfg {Number} charoff Sets the number of characters the content inside the element will be aligned from the character specified by the char attribute
7239 * @cfg {String} valign Vertical aligns the content inside the <tbody> element
7242 * Create a new TableBody
7243 * @param {Object} config The config object
7246 Roo.bootstrap.TableBody = function(config){
7247 Roo.bootstrap.TableBody.superclass.constructor.call(this, config);
7250 Roo.extend(Roo.bootstrap.TableBody, Roo.bootstrap.Component, {
7258 getAutoCreate : function(){
7259 var cfg = Roo.apply({}, Roo.bootstrap.TableBody.superclass.getAutoCreate.call(this));
7273 cfg.align = this.align;
7276 cfg.charoff = this.charoff;
7279 cfg.valign = this.valign;
7286 // initEvents : function()
7293 // this.store = Roo.factory(this.store, Roo.data);
7294 // this.store.on('load', this.onLoad, this);
7296 // this.store.load();
7300 // onLoad: function ()
7302 // this.fireEvent('load', this);
7312 * Ext JS Library 1.1.1
7313 * Copyright(c) 2006-2007, Ext JS, LLC.
7315 * Originally Released Under LGPL - original licence link has changed is not relivant.
7318 * <script type="text/javascript">
7321 // as we use this in bootstrap.
7322 Roo.namespace('Roo.form');
7324 * @class Roo.form.Action
7325 * Internal Class used to handle form actions
7327 * @param {Roo.form.BasicForm} el The form element or its id
7328 * @param {Object} config Configuration options
7333 // define the action interface
7334 Roo.form.Action = function(form, options){
7336 this.options = options || {};
7339 * Client Validation Failed
7342 Roo.form.Action.CLIENT_INVALID = 'client';
7344 * Server Validation Failed
7347 Roo.form.Action.SERVER_INVALID = 'server';
7349 * Connect to Server Failed
7352 Roo.form.Action.CONNECT_FAILURE = 'connect';
7354 * Reading Data from Server Failed
7357 Roo.form.Action.LOAD_FAILURE = 'load';
7359 Roo.form.Action.prototype = {
7361 failureType : undefined,
7362 response : undefined,
7366 run : function(options){
7371 success : function(response){
7376 handleResponse : function(response){
7380 // default connection failure
7381 failure : function(response){
7383 this.response = response;
7384 this.failureType = Roo.form.Action.CONNECT_FAILURE;
7385 this.form.afterAction(this, false);
7388 processResponse : function(response){
7389 this.response = response;
7390 if(!response.responseText){
7393 this.result = this.handleResponse(response);
7397 // utility functions used internally
7398 getUrl : function(appendParams){
7399 var url = this.options.url || this.form.url || this.form.el.dom.action;
7401 var p = this.getParams();
7403 url += (url.indexOf('?') != -1 ? '&' : '?') + p;
7409 getMethod : function(){
7410 return (this.options.method || this.form.method || this.form.el.dom.method || 'POST').toUpperCase();
7413 getParams : function(){
7414 var bp = this.form.baseParams;
7415 var p = this.options.params;
7417 if(typeof p == "object"){
7418 p = Roo.urlEncode(Roo.applyIf(p, bp));
7419 }else if(typeof p == 'string' && bp){
7420 p += '&' + Roo.urlEncode(bp);
7423 p = Roo.urlEncode(bp);
7428 createCallback : function(){
7430 success: this.success,
7431 failure: this.failure,
7433 timeout: (this.form.timeout*1000),
7434 upload: this.form.fileUpload ? this.success : undefined
7439 Roo.form.Action.Submit = function(form, options){
7440 Roo.form.Action.Submit.superclass.constructor.call(this, form, options);
7443 Roo.extend(Roo.form.Action.Submit, Roo.form.Action, {
7446 haveProgress : false,
7447 uploadComplete : false,
7449 // uploadProgress indicator.
7450 uploadProgress : function()
7452 if (!this.form.progressUrl) {
7456 if (!this.haveProgress) {
7457 Roo.MessageBox.progress("Uploading", "Uploading");
7459 if (this.uploadComplete) {
7460 Roo.MessageBox.hide();
7464 this.haveProgress = true;
7466 var uid = this.form.findField('UPLOAD_IDENTIFIER').getValue();
7468 var c = new Roo.data.Connection();
7470 url : this.form.progressUrl,
7475 success : function(req){
7476 //console.log(data);
7480 rdata = Roo.decode(req.responseText)
7482 Roo.log("Invalid data from server..");
7486 if (!rdata || !rdata.success) {
7488 Roo.MessageBox.alert(Roo.encode(rdata));
7491 var data = rdata.data;
7493 if (this.uploadComplete) {
7494 Roo.MessageBox.hide();
7499 Roo.MessageBox.updateProgress(data.bytes_uploaded/data.bytes_total,
7500 Math.floor((data.bytes_total - data.bytes_uploaded)/1000) + 'k remaining'
7503 this.uploadProgress.defer(2000,this);
7506 failure: function(data) {
7507 Roo.log('progress url failed ');
7518 // run get Values on the form, so it syncs any secondary forms.
7519 this.form.getValues();
7521 var o = this.options;
7522 var method = this.getMethod();
7523 var isPost = method == 'POST';
7524 if(o.clientValidation === false || this.form.isValid()){
7526 if (this.form.progressUrl) {
7527 this.form.findField('UPLOAD_IDENTIFIER').setValue(
7528 (new Date() * 1) + '' + Math.random());
7533 Roo.Ajax.request(Roo.apply(this.createCallback(), {
7534 form:this.form.el.dom,
7535 url:this.getUrl(!isPost),
7537 params:isPost ? this.getParams() : null,
7538 isUpload: this.form.fileUpload
7541 this.uploadProgress();
7543 }else if (o.clientValidation !== false){ // client validation failed
7544 this.failureType = Roo.form.Action.CLIENT_INVALID;
7545 this.form.afterAction(this, false);
7549 success : function(response)
7551 this.uploadComplete= true;
7552 if (this.haveProgress) {
7553 Roo.MessageBox.hide();
7557 var result = this.processResponse(response);
7558 if(result === true || result.success){
7559 this.form.afterAction(this, true);
7563 this.form.markInvalid(result.errors);
7564 this.failureType = Roo.form.Action.SERVER_INVALID;
7566 this.form.afterAction(this, false);
7568 failure : function(response)
7570 this.uploadComplete= true;
7571 if (this.haveProgress) {
7572 Roo.MessageBox.hide();
7575 this.response = response;
7576 this.failureType = Roo.form.Action.CONNECT_FAILURE;
7577 this.form.afterAction(this, false);
7580 handleResponse : function(response){
7581 if(this.form.errorReader){
7582 var rs = this.form.errorReader.read(response);
7585 for(var i = 0, len = rs.records.length; i < len; i++) {
7586 var r = rs.records[i];
7590 if(errors.length < 1){
7594 success : rs.success,
7600 ret = Roo.decode(response.responseText);
7604 errorMsg: "Failed to read server message: " + (response ? response.responseText : ' - no message'),
7614 Roo.form.Action.Load = function(form, options){
7615 Roo.form.Action.Load.superclass.constructor.call(this, form, options);
7616 this.reader = this.form.reader;
7619 Roo.extend(Roo.form.Action.Load, Roo.form.Action, {
7624 Roo.Ajax.request(Roo.apply(
7625 this.createCallback(), {
7626 method:this.getMethod(),
7627 url:this.getUrl(false),
7628 params:this.getParams()
7632 success : function(response){
7634 var result = this.processResponse(response);
7635 if(result === true || !result.success || !result.data){
7636 this.failureType = Roo.form.Action.LOAD_FAILURE;
7637 this.form.afterAction(this, false);
7640 this.form.clearInvalid();
7641 this.form.setValues(result.data);
7642 this.form.afterAction(this, true);
7645 handleResponse : function(response){
7646 if(this.form.reader){
7647 var rs = this.form.reader.read(response);
7648 var data = rs.records && rs.records[0] ? rs.records[0].data : null;
7650 success : rs.success,
7654 return Roo.decode(response.responseText);
7658 Roo.form.Action.ACTION_TYPES = {
7659 'load' : Roo.form.Action.Load,
7660 'submit' : Roo.form.Action.Submit
7669 * @class Roo.bootstrap.Form
7670 * @extends Roo.bootstrap.Component
7671 * Bootstrap Form class
7672 * @cfg {String} method GET | POST (default POST)
7673 * @cfg {String} labelAlign top | left (default top)
7674 * @cfg {String} align left | right - for navbars
7675 * @cfg {Boolean} loadMask load mask when submit (default true)
7680 * @param {Object} config The config object
7684 Roo.bootstrap.Form = function(config){
7686 Roo.bootstrap.Form.superclass.constructor.call(this, config);
7688 Roo.bootstrap.Form.popover.apply();
7692 * @event clientvalidation
7693 * If the monitorValid config option is true, this event fires repetitively to notify of valid state
7694 * @param {Form} this
7695 * @param {Boolean} valid true if the form has passed client-side validation
7697 clientvalidation: true,
7699 * @event beforeaction
7700 * Fires before any action is performed. Return false to cancel the action.
7701 * @param {Form} this
7702 * @param {Action} action The action to be performed
7706 * @event actionfailed
7707 * Fires when an action fails.
7708 * @param {Form} this
7709 * @param {Action} action The action that failed
7711 actionfailed : true,
7713 * @event actioncomplete
7714 * Fires when an action is completed.
7715 * @param {Form} this
7716 * @param {Action} action The action that completed
7718 actioncomplete : true
7722 Roo.extend(Roo.bootstrap.Form, Roo.bootstrap.Component, {
7725 * @cfg {String} method
7726 * The request method to use (GET or POST) for form actions if one isn't supplied in the action options.
7731 * The URL to use for form actions if one isn't supplied in the action options.
7734 * @cfg {Boolean} fileUpload
7735 * Set to true if this form is a file upload.
7739 * @cfg {Object} baseParams
7740 * Parameters to pass with all requests. e.g. baseParams: {id: '123', foo: 'bar'}.
7744 * @cfg {Number} timeout Timeout for form actions in seconds (default is 30 seconds).
7748 * @cfg {Sting} align (left|right) for navbar forms
7753 activeAction : null,
7756 * By default wait messages are displayed with Roo.MessageBox.wait. You can target a specific
7757 * element by passing it or its id or mask the form itself by passing in true.
7760 waitMsgTarget : false,
7765 * @cfg {Boolean} errorMask (true|false) default false
7770 * @cfg {Number} maskOffset Default 100
7775 * @cfg {Boolean} maskBody
7779 getAutoCreate : function(){
7783 method : this.method || 'POST',
7784 id : this.id || Roo.id(),
7787 if (this.parent().xtype.match(/^Nav/)) {
7788 cfg.cls = 'navbar-form navbar-' + this.align;
7792 if (this.labelAlign == 'left' ) {
7793 cfg.cls += ' form-horizontal';
7799 initEvents : function()
7801 this.el.on('submit', this.onSubmit, this);
7802 // this was added as random key presses on the form where triggering form submit.
7803 this.el.on('keypress', function(e) {
7804 if (e.getCharCode() != 13) {
7807 // we might need to allow it for textareas.. and some other items.
7808 // check e.getTarget().
7810 if(e.getTarget().nodeName.toLowerCase() === 'textarea'){
7814 Roo.log("keypress blocked");
7822 onSubmit : function(e){
7827 * Returns true if client-side validation on the form is successful.
7830 isValid : function(){
7831 var items = this.getItems();
7835 items.each(function(f){
7843 if(!target && f.el.isVisible(true)){
7849 if(this.errorMask && !valid){
7850 Roo.bootstrap.Form.popover.mask(this, target);
7857 * Returns true if any fields in this form have changed since their original load.
7860 isDirty : function(){
7862 var items = this.getItems();
7863 items.each(function(f){
7873 * Performs a predefined action (submit or load) or custom actions you define on this form.
7874 * @param {String} actionName The name of the action type
7875 * @param {Object} options (optional) The options to pass to the action. All of the config options listed
7876 * below are supported by both the submit and load actions unless otherwise noted (custom actions could also
7877 * accept other config options):
7879 Property Type Description
7880 ---------------- --------------- ----------------------------------------------------------------------------------
7881 url String The url for the action (defaults to the form's url)
7882 method String The form method to use (defaults to the form's method, or POST if not defined)
7883 params String/Object The params to pass (defaults to the form's baseParams, or none if not defined)
7884 clientValidation Boolean Applies to submit only. Pass true to call form.isValid() prior to posting to
7885 validate the form on the client (defaults to false)
7887 * @return {BasicForm} this
7889 doAction : function(action, options){
7890 if(typeof action == 'string'){
7891 action = new Roo.form.Action.ACTION_TYPES[action](this, options);
7893 if(this.fireEvent('beforeaction', this, action) !== false){
7894 this.beforeAction(action);
7895 action.run.defer(100, action);
7901 beforeAction : function(action){
7902 var o = action.options;
7907 Roo.get(document.body).mask(o.waitMsg || "Sending", 'x-mask-loading')
7909 this.el.mask(o.waitMsg || "Sending", 'x-mask-loading');
7912 // not really supported yet.. ??
7914 //if(this.waitMsgTarget === true){
7915 // this.el.mask(o.waitMsg || "Sending", 'x-mask-loading');
7916 //}else if(this.waitMsgTarget){
7917 // this.waitMsgTarget = Roo.get(this.waitMsgTarget);
7918 // this.waitMsgTarget.mask(o.waitMsg || "Sending", 'x-mask-loading');
7920 // Roo.MessageBox.wait(o.waitMsg || "Sending", o.waitTitle || this.waitTitle || 'Please Wait...');
7926 afterAction : function(action, success){
7927 this.activeAction = null;
7928 var o = action.options;
7933 Roo.get(document.body).unmask();
7939 //if(this.waitMsgTarget === true){
7940 // this.el.unmask();
7941 //}else if(this.waitMsgTarget){
7942 // this.waitMsgTarget.unmask();
7944 // Roo.MessageBox.updateProgress(1);
7945 // Roo.MessageBox.hide();
7952 Roo.callback(o.success, o.scope, [this, action]);
7953 this.fireEvent('actioncomplete', this, action);
7957 // failure condition..
7958 // we have a scenario where updates need confirming.
7959 // eg. if a locking scenario exists..
7960 // we look for { errors : { needs_confirm : true }} in the response.
7962 (typeof(action.result) != 'undefined') &&
7963 (typeof(action.result.errors) != 'undefined') &&
7964 (typeof(action.result.errors.needs_confirm) != 'undefined')
7967 Roo.log("not supported yet");
7970 Roo.MessageBox.confirm(
7971 "Change requires confirmation",
7972 action.result.errorMsg,
7977 _t.doAction('submit', { params : { _submit_confirmed : 1 } } );
7987 Roo.callback(o.failure, o.scope, [this, action]);
7988 // show an error message if no failed handler is set..
7989 if (!this.hasListener('actionfailed')) {
7990 Roo.log("need to add dialog support");
7992 Roo.MessageBox.alert("Error",
7993 (typeof(action.result) != 'undefined' && typeof(action.result.errorMsg) != 'undefined') ?
7994 action.result.errorMsg :
7995 "Saving Failed, please check your entries or try again"
8000 this.fireEvent('actionfailed', this, action);
8005 * Find a Roo.form.Field in this form by id, dataIndex, name or hiddenName
8006 * @param {String} id The value to search for
8009 findField : function(id){
8010 var items = this.getItems();
8011 var field = items.get(id);
8013 items.each(function(f){
8014 if(f.isFormField && (f.dataIndex == id || f.id == id || f.getName() == id)){
8021 return field || null;
8024 * Mark fields in this form invalid in bulk.
8025 * @param {Array/Object} errors Either an array in the form [{id:'fieldId', msg:'The message'},...] or an object hash of {id: msg, id2: msg2}
8026 * @return {BasicForm} this
8028 markInvalid : function(errors){
8029 if(errors instanceof Array){
8030 for(var i = 0, len = errors.length; i < len; i++){
8031 var fieldError = errors[i];
8032 var f = this.findField(fieldError.id);
8034 f.markInvalid(fieldError.msg);
8040 if(typeof errors[id] != 'function' && (field = this.findField(id))){
8041 field.markInvalid(errors[id]);
8045 //Roo.each(this.childForms || [], function (f) {
8046 // f.markInvalid(errors);
8053 * Set values for fields in this form in bulk.
8054 * @param {Array/Object} values Either an array in the form [{id:'fieldId', value:'foo'},...] or an object hash of {id: value, id2: value2}
8055 * @return {BasicForm} this
8057 setValues : function(values){
8058 if(values instanceof Array){ // array of objects
8059 for(var i = 0, len = values.length; i < len; i++){
8061 var f = this.findField(v.id);
8063 f.setValue(v.value);
8064 if(this.trackResetOnLoad){
8065 f.originalValue = f.getValue();
8069 }else{ // object hash
8072 if(typeof values[id] != 'function' && (field = this.findField(id))){
8074 if (field.setFromData &&
8076 field.displayField &&
8077 // combos' with local stores can
8078 // be queried via setValue()
8079 // to set their value..
8080 (field.store && !field.store.isLocal)
8084 sd[field.valueField] = typeof(values[field.hiddenName]) == 'undefined' ? '' : values[field.hiddenName];
8085 sd[field.displayField] = typeof(values[field.name]) == 'undefined' ? '' : values[field.name];
8086 field.setFromData(sd);
8088 } else if(field.setFromData && (field.store && !field.store.isLocal)) {
8090 field.setFromData(values);
8093 field.setValue(values[id]);
8097 if(this.trackResetOnLoad){
8098 field.originalValue = field.getValue();
8104 //Roo.each(this.childForms || [], function (f) {
8105 // f.setValues(values);
8112 * Returns the fields in this form as an object with key/value pairs. If multiple fields exist with the same name
8113 * they are returned as an array.
8114 * @param {Boolean} asString
8117 getValues : function(asString){
8118 //if (this.childForms) {
8119 // copy values from the child forms
8120 // Roo.each(this.childForms, function (f) {
8121 // this.setValues(f.getValues());
8127 var fs = Roo.lib.Ajax.serializeForm(this.el.dom);
8128 if(asString === true){
8131 return Roo.urlDecode(fs);
8135 * Returns the fields in this form as an object with key/value pairs.
8136 * This differs from getValues as it calls getValue on each child item, rather than using dom data.
8139 getFieldValues : function(with_hidden)
8141 var items = this.getItems();
8143 items.each(function(f){
8149 var v = f.getValue();
8151 if (f.inputType =='radio') {
8152 if (typeof(ret[f.getName()]) == 'undefined') {
8153 ret[f.getName()] = ''; // empty..
8156 if (!f.el.dom.checked) {
8164 if(f.xtype == 'MoneyField'){
8165 ret[f.currencyName] = f.getCurrency();
8168 // not sure if this supported any more..
8169 if ((typeof(v) == 'object') && f.getRawValue) {
8170 v = f.getRawValue() ; // dates..
8172 // combo boxes where name != hiddenName...
8173 if (f.name !== false && f.name != '' && f.name != f.getName()) {
8174 ret[f.name] = f.getRawValue();
8176 ret[f.getName()] = v;
8183 * Clears all invalid messages in this form.
8184 * @return {BasicForm} this
8186 clearInvalid : function(){
8187 var items = this.getItems();
8189 items.each(function(f){
8198 * @return {BasicForm} this
8201 var items = this.getItems();
8202 items.each(function(f){
8206 Roo.each(this.childForms || [], function (f) {
8214 getItems : function()
8216 var r=new Roo.util.MixedCollection(false, function(o){
8217 return o.id || (o.id = Roo.id());
8219 var iter = function(el) {
8226 Roo.each(el.items,function(e) {
8235 hideFields : function(items)
8237 Roo.each(items, function(i){
8239 var f = this.findField(i);
8245 if(f.xtype == 'DateField'){
8246 f.setVisible(false);
8255 showFields : function(items)
8257 Roo.each(items, function(i){
8259 var f = this.findField(i);
8265 if(f.xtype == 'DateField'){
8277 Roo.apply(Roo.bootstrap.Form, {
8304 top : Roo.DomHelper.append(Roo.get(document.body), { tag: "div", cls:"x-dlg-mask roo-form-top-mask" }, true),
8305 left : Roo.DomHelper.append(Roo.get(document.body), { tag: "div", cls:"x-dlg-mask roo-form-left-mask" }, true),
8306 bottom : Roo.DomHelper.append(Roo.get(document.body), { tag: "div", cls:"x-dlg-mask roo-form-bottom-mask" }, true),
8307 right : Roo.DomHelper.append(Roo.get(document.body), { tag: "div", cls:"x-dlg-mask roo-form-right-mask" }, true)
8310 this.maskEl.top.enableDisplayMode("block");
8311 this.maskEl.left.enableDisplayMode("block");
8312 this.maskEl.bottom.enableDisplayMode("block");
8313 this.maskEl.right.enableDisplayMode("block");
8315 this.toolTip = new Roo.bootstrap.Tooltip({
8316 cls : 'roo-form-error-popover',
8318 'left' : ['r-l', [-2,0], 'right'],
8319 'right' : ['l-r', [2,0], 'left'],
8320 'bottom' : ['tl-bl', [0,2], 'top'],
8321 'top' : [ 'bl-tl', [0,-2], 'bottom']
8325 this.toolTip.render(Roo.get(document.body));
8327 this.toolTip.el.enableDisplayMode("block");
8329 Roo.get(document.body).on('click', function(){
8333 Roo.get(document.body).on('touchstart', function(){
8337 this.isApplied = true
8340 mask : function(form, target)
8344 this.target = target;
8346 if(!this.form.errorMask || !target.el){
8350 var scrollable = this.target.el.findScrollableParent() || this.target.el.findParent('div.modal', 100, true) || Roo.get(document.body);
8352 Roo.log(scrollable);
8354 var ot = this.target.el.calcOffsetsTo(scrollable);
8356 var scrollTo = ot[1] - this.form.maskOffset;
8358 scrollTo = Math.min(scrollTo, scrollable.dom.scrollHeight);
8360 scrollable.scrollTo('top', scrollTo);
8362 var box = this.target.el.getBox();
8364 var zIndex = Roo.bootstrap.Modal.zIndex++;
8367 this.maskEl.top.setStyle('position', 'absolute');
8368 this.maskEl.top.setStyle('z-index', zIndex);
8369 this.maskEl.top.setSize(Roo.lib.Dom.getDocumentWidth(), box.y - this.padding);
8370 this.maskEl.top.setLeft(0);
8371 this.maskEl.top.setTop(0);
8372 this.maskEl.top.show();
8374 this.maskEl.left.setStyle('position', 'absolute');
8375 this.maskEl.left.setStyle('z-index', zIndex);
8376 this.maskEl.left.setSize(box.x - this.padding, box.height + this.padding * 2);
8377 this.maskEl.left.setLeft(0);
8378 this.maskEl.left.setTop(box.y - this.padding);
8379 this.maskEl.left.show();
8381 this.maskEl.bottom.setStyle('position', 'absolute');
8382 this.maskEl.bottom.setStyle('z-index', zIndex);
8383 this.maskEl.bottom.setSize(Roo.lib.Dom.getDocumentWidth(), Roo.lib.Dom.getDocumentHeight() - box.bottom - this.padding);
8384 this.maskEl.bottom.setLeft(0);
8385 this.maskEl.bottom.setTop(box.bottom + this.padding);
8386 this.maskEl.bottom.show();
8388 this.maskEl.right.setStyle('position', 'absolute');
8389 this.maskEl.right.setStyle('z-index', zIndex);
8390 this.maskEl.right.setSize(Roo.lib.Dom.getDocumentWidth() - box.right - this.padding, box.height + this.padding * 2);
8391 this.maskEl.right.setLeft(box.right + this.padding);
8392 this.maskEl.right.setTop(box.y - this.padding);
8393 this.maskEl.right.show();
8395 this.toolTip.bindEl = this.target.el;
8397 this.toolTip.el.setStyle('z-index', Roo.bootstrap.Modal.zIndex++);
8399 var tip = this.target.blankText;
8401 if(this.target.getValue() !== '' ) {
8403 if (this.target.invalidText.length) {
8404 tip = this.target.invalidText;
8405 } else if (this.target.regexText.length){
8406 tip = this.target.regexText;
8410 this.toolTip.show(tip);
8412 this.intervalID = window.setInterval(function() {
8413 Roo.bootstrap.Form.popover.unmask();
8416 window.onwheel = function(){ return false;};
8418 (function(){ this.isMasked = true; }).defer(500, this);
8424 if(!this.isApplied || !this.isMasked || !this.form || !this.target || !this.form.errorMask){
8428 this.maskEl.top.setStyle('position', 'absolute');
8429 this.maskEl.top.setSize(0, 0).setXY([0, 0]);
8430 this.maskEl.top.hide();
8432 this.maskEl.left.setStyle('position', 'absolute');
8433 this.maskEl.left.setSize(0, 0).setXY([0, 0]);
8434 this.maskEl.left.hide();
8436 this.maskEl.bottom.setStyle('position', 'absolute');
8437 this.maskEl.bottom.setSize(0, 0).setXY([0, 0]);
8438 this.maskEl.bottom.hide();
8440 this.maskEl.right.setStyle('position', 'absolute');
8441 this.maskEl.right.setSize(0, 0).setXY([0, 0]);
8442 this.maskEl.right.hide();
8444 this.toolTip.hide();
8446 this.toolTip.el.hide();
8448 window.onwheel = function(){ return true;};
8450 if(this.intervalID){
8451 window.clearInterval(this.intervalID);
8452 this.intervalID = false;
8455 this.isMasked = false;
8465 * Ext JS Library 1.1.1
8466 * Copyright(c) 2006-2007, Ext JS, LLC.
8468 * Originally Released Under LGPL - original licence link has changed is not relivant.
8471 * <script type="text/javascript">
8474 * @class Roo.form.VTypes
8475 * Overridable validation definitions. The validations provided are basic and intended to be easily customizable and extended.
8478 Roo.form.VTypes = function(){
8479 // closure these in so they are only created once.
8480 var alpha = /^[a-zA-Z_]+$/;
8481 var alphanum = /^[a-zA-Z0-9_]+$/;
8482 var email = /^([\w]+)(.[\w]+)*@([\w-]+\.){1,5}([A-Za-z]){2,24}$/;
8483 var url = /(((https?)|(ftp)):\/\/([\-\w]+\.)+\w{2,3}(\/[%\-\w]+(\.\w{2,})?)*(([\w\-\.\?\\\/+@&#;`~=%!]*)(\.\w{2,})?)*\/?)/i;
8485 // All these messages and functions are configurable
8488 * The function used to validate email addresses
8489 * @param {String} value The email address
8491 'email' : function(v){
8492 return email.test(v);
8495 * The error text to display when the email validation function returns false
8498 'emailText' : 'This field should be an e-mail address in the format "user@domain.com"',
8500 * The keystroke filter mask to be applied on email input
8503 'emailMask' : /[a-z0-9_\.\-@]/i,
8506 * The function used to validate URLs
8507 * @param {String} value The URL
8509 'url' : function(v){
8513 * The error text to display when the url validation function returns false
8516 'urlText' : 'This field should be a URL in the format "http:/'+'/www.domain.com"',
8519 * The function used to validate alpha values
8520 * @param {String} value The value
8522 'alpha' : function(v){
8523 return alpha.test(v);
8526 * The error text to display when the alpha validation function returns false
8529 'alphaText' : 'This field should only contain letters and _',
8531 * The keystroke filter mask to be applied on alpha input
8534 'alphaMask' : /[a-z_]/i,
8537 * The function used to validate alphanumeric values
8538 * @param {String} value The value
8540 'alphanum' : function(v){
8541 return alphanum.test(v);
8544 * The error text to display when the alphanumeric validation function returns false
8547 'alphanumText' : 'This field should only contain letters, numbers and _',
8549 * The keystroke filter mask to be applied on alphanumeric input
8552 'alphanumMask' : /[a-z0-9_]/i
8562 * @class Roo.bootstrap.Input
8563 * @extends Roo.bootstrap.Component
8564 * Bootstrap Input class
8565 * @cfg {Boolean} disabled is it disabled
8566 * @cfg {String} inputType button | checkbox | email | file | hidden | image | number | password | radio | range | reset | search | submit | text
8567 * @cfg {String} name name of the input
8568 * @cfg {string} fieldLabel - the label associated
8569 * @cfg {string} placeholder - placeholder to put in text.
8570 * @cfg {string} before - input group add on before
8571 * @cfg {string} after - input group add on after
8572 * @cfg {string} size - (lg|sm) or leave empty..
8573 * @cfg {Number} xs colspan out of 12 for mobile-sized screens
8574 * @cfg {Number} sm colspan out of 12 for tablet-sized screens
8575 * @cfg {Number} md colspan out of 12 for computer-sized screens
8576 * @cfg {Number} lg colspan out of 12 for large computer-sized screens
8577 * @cfg {string} value default value of the input
8578 * @cfg {Number} labelWidth set the width of label
8579 * @cfg {Number} labellg set the width of label (1-12)
8580 * @cfg {Number} labelmd set the width of label (1-12)
8581 * @cfg {Number} labelsm set the width of label (1-12)
8582 * @cfg {Number} labelxs set the width of label (1-12)
8583 * @cfg {String} labelAlign (top|left)
8584 * @cfg {Boolean} readOnly Specifies that the field should be read-only
8585 * @cfg {String} autocomplete - default is new-password see: https://developers.google.com/web/fundamentals/input/form/label-and-name-inputs?hl=en
8586 * @cfg {String} indicatorpos (left|right) default left
8587 * @cfg {String} capture (user|camera) use for file input only. (default empty)
8588 * @cfg {String} accept (image|video|audio) use for file input only. (default empty)
8590 * @cfg {String} align (left|center|right) Default left
8591 * @cfg {Boolean} forceFeedback (true|false) Default false
8594 * Create a new Input
8595 * @param {Object} config The config object
8598 Roo.bootstrap.Input = function(config){
8600 Roo.bootstrap.Input.superclass.constructor.call(this, config);
8605 * Fires when this field receives input focus.
8606 * @param {Roo.form.Field} this
8611 * Fires when this field loses input focus.
8612 * @param {Roo.form.Field} this
8617 * Fires when any key related to navigation (arrows, tab, enter, esc, etc.) is pressed. You can check
8618 * {@link Roo.EventObject#getKey} to determine which key was pressed.
8619 * @param {Roo.form.Field} this
8620 * @param {Roo.EventObject} e The event object
8625 * Fires just before the field blurs if the field value has changed.
8626 * @param {Roo.form.Field} this
8627 * @param {Mixed} newValue The new value
8628 * @param {Mixed} oldValue The original value
8633 * Fires after the field has been marked as invalid.
8634 * @param {Roo.form.Field} this
8635 * @param {String} msg The validation message
8640 * Fires after the field has been validated with no errors.
8641 * @param {Roo.form.Field} this
8646 * Fires after the key up
8647 * @param {Roo.form.Field} this
8648 * @param {Roo.EventObject} e The event Object
8654 Roo.extend(Roo.bootstrap.Input, Roo.bootstrap.Component, {
8656 * @cfg {String/Boolean} validationEvent The event that should initiate field validation. Set to false to disable
8657 automatic validation (defaults to "keyup").
8659 validationEvent : "keyup",
8661 * @cfg {Boolean} validateOnBlur Whether the field should validate when it loses focus (defaults to true).
8663 validateOnBlur : true,
8665 * @cfg {Number} validationDelay The length of time in milliseconds after user input begins until validation is initiated (defaults to 250)
8667 validationDelay : 250,
8669 * @cfg {String} focusClass The CSS class to use when the field receives focus (defaults to "x-form-focus")
8671 focusClass : "x-form-focus", // not needed???
8675 * @cfg {String} invalidClass The CSS class to use when marking a field invalid (defaults to "x-form-invalid")
8677 invalidClass : "has-warning",
8680 * @cfg {String} validClass The CSS class to use when marking a field valid (defaults to "x-form-invalid")
8682 validClass : "has-success",
8685 * @cfg {Boolean} hasFeedback (true|false) default true
8690 * @cfg {String} invalidFeedbackIcon The CSS class to use when create feedback icon (defaults to "x-form-invalid")
8692 invalidFeedbackClass : "glyphicon-warning-sign",
8695 * @cfg {String} validFeedbackIcon The CSS class to use when create feedback icon (defaults to "x-form-invalid")
8697 validFeedbackClass : "glyphicon-ok",
8700 * @cfg {Boolean} selectOnFocus True to automatically select any existing field text when the field receives input focus (defaults to false)
8702 selectOnFocus : false,
8705 * @cfg {String} maskRe An input mask regular expression that will be used to filter keystrokes that don't match (defaults to null)
8709 * @cfg {String} vtype A validation type name as defined in {@link Roo.form.VTypes} (defaults to null)
8714 * @cfg {Boolean} disableKeyFilter True to disable input keystroke filtering (defaults to false)
8716 disableKeyFilter : false,
8719 * @cfg {Boolean} disabled True to disable the field (defaults to false).
8723 * @cfg {Boolean} allowBlank False to validate that the value length > 0 (defaults to true)
8727 * @cfg {String} blankText Error text to display if the allow blank validation fails (defaults to "This field is required")
8729 blankText : "Please complete this mandatory field",
8732 * @cfg {Number} minLength Minimum input field length required (defaults to 0)
8736 * @cfg {Number} maxLength Maximum input field length allowed (defaults to Number.MAX_VALUE)
8738 maxLength : Number.MAX_VALUE,
8740 * @cfg {String} minLengthText Error text to display if the minimum length validation fails (defaults to "The minimum length for this field is {minLength}")
8742 minLengthText : "The minimum length for this field is {0}",
8744 * @cfg {String} maxLengthText Error text to display if the maximum length validation fails (defaults to "The maximum length for this field is {maxLength}")
8746 maxLengthText : "The maximum length for this field is {0}",
8750 * @cfg {Function} validator A custom validation function to be called during field validation (defaults to null).
8751 * If available, this function will be called only after the basic validators all return true, and will be passed the
8752 * current field value and expected to return boolean true if the value is valid or a string error message if invalid.
8756 * @cfg {RegExp} regex A JavaScript RegExp object to be tested against the field value during validation (defaults to null).
8757 * If available, this regex will be evaluated only after the basic validators all return true, and will be passed the
8758 * current field value. If the test fails, the field will be marked invalid using {@link #regexText}.
8762 * @cfg {String} regexText -- Depricated - use Invalid Text
8767 * @cfg {String} invalidText The error text to display if {@link #validator} test fails during validation (defaults to "")
8773 autocomplete: false,
8792 formatedValue : false,
8793 forceFeedback : false,
8795 indicatorpos : 'left',
8805 parentLabelAlign : function()
8808 while (parent.parent()) {
8809 parent = parent.parent();
8810 if (typeof(parent.labelAlign) !='undefined') {
8811 return parent.labelAlign;
8818 getAutoCreate : function()
8820 var align = (!this.labelAlign) ? this.parentLabelAlign() : this.labelAlign;
8826 if(this.inputType != 'hidden'){
8827 cfg.cls = 'form-group' //input-group
8833 type : this.inputType,
8835 cls : 'form-control',
8836 placeholder : this.placeholder || '',
8837 autocomplete : this.autocomplete || 'new-password'
8840 if(this.capture.length){
8841 input.capture = this.capture;
8844 if(this.accept.length){
8845 input.accept = this.accept + "/*";
8849 input.style = (typeof(input.style) == 'undefined') ? ('text-align:' + this.align) : (input.style + 'text-align:' + this.align);
8852 if(this.maxLength && this.maxLength != Number.MAX_VALUE){
8853 input.maxLength = this.maxLength;
8856 if (this.disabled) {
8857 input.disabled=true;
8860 if (this.readOnly) {
8861 input.readonly=true;
8865 input.name = this.name;
8869 input.cls += ' input-' + this.size;
8873 ['xs','sm','md','lg'].map(function(size){
8874 if (settings[size]) {
8875 cfg.cls += ' col-' + size + '-' + settings[size];
8879 var inputblock = input;
8883 cls: 'glyphicon form-control-feedback'
8886 if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank){
8889 cls : 'has-feedback',
8897 if (this.before || this.after) {
8900 cls : 'input-group',
8904 if (this.before && typeof(this.before) == 'string') {
8906 inputblock.cn.push({
8908 cls : 'roo-input-before input-group-addon',
8912 if (this.before && typeof(this.before) == 'object') {
8913 this.before = Roo.factory(this.before);
8915 inputblock.cn.push({
8917 cls : 'roo-input-before input-group-' +
8918 (this.before.xtype == 'Button' ? 'btn' : 'addon') //?? what about checkboxes - that looks like a bit of a hack thought?
8922 inputblock.cn.push(input);
8924 if (this.after && typeof(this.after) == 'string') {
8925 inputblock.cn.push({
8927 cls : 'roo-input-after input-group-addon',
8931 if (this.after && typeof(this.after) == 'object') {
8932 this.after = Roo.factory(this.after);
8934 inputblock.cn.push({
8936 cls : 'roo-input-after input-group-' +
8937 (this.after.xtype == 'Button' ? 'btn' : 'addon') //?? what about checkboxes - that looks like a bit of a hack thought?
8941 if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank){
8942 inputblock.cls += ' has-feedback';
8943 inputblock.cn.push(feedback);
8947 if (align ==='left' && this.fieldLabel.length) {
8949 cfg.cls += ' roo-form-group-label-left';
8954 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
8955 tooltip : 'This field is required'
8960 cls : 'control-label',
8961 html : this.fieldLabel
8972 var labelCfg = cfg.cn[1];
8973 var contentCfg = cfg.cn[2];
8975 if(this.indicatorpos == 'right'){
8980 cls : 'control-label',
8984 html : this.fieldLabel
8988 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
8989 tooltip : 'This field is required'
9002 labelCfg = cfg.cn[0];
9003 contentCfg = cfg.cn[1];
9007 if(this.labelWidth > 12){
9008 labelCfg.style = "width: " + this.labelWidth + 'px';
9011 if(this.labelWidth < 13 && this.labelmd == 0){
9012 this.labelmd = this.labelWidth;
9015 if(this.labellg > 0){
9016 labelCfg.cls += ' col-lg-' + this.labellg;
9017 contentCfg.cls += ' col-lg-' + (12 - this.labellg);
9020 if(this.labelmd > 0){
9021 labelCfg.cls += ' col-md-' + this.labelmd;
9022 contentCfg.cls += ' col-md-' + (12 - this.labelmd);
9025 if(this.labelsm > 0){
9026 labelCfg.cls += ' col-sm-' + this.labelsm;
9027 contentCfg.cls += ' col-sm-' + (12 - this.labelsm);
9030 if(this.labelxs > 0){
9031 labelCfg.cls += ' col-xs-' + this.labelxs;
9032 contentCfg.cls += ' col-xs-' + (12 - this.labelxs);
9036 } else if ( this.fieldLabel.length) {
9041 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
9042 tooltip : 'This field is required'
9046 //cls : 'input-group-addon',
9047 html : this.fieldLabel
9055 if(this.indicatorpos == 'right'){
9060 //cls : 'input-group-addon',
9061 html : this.fieldLabel
9066 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
9067 tooltip : 'This field is required'
9087 if (this.parentType === 'Navbar' && this.parent().bar) {
9088 cfg.cls += ' navbar-form';
9091 if (this.parentType === 'NavGroup') {
9092 cfg.cls += ' navbar-form';
9100 * return the real input element.
9102 inputEl: function ()
9104 return this.el.select('input.form-control',true).first();
9107 tooltipEl : function()
9109 return this.inputEl();
9112 indicatorEl : function()
9114 var indicator = this.el.select('i.roo-required-indicator',true).first();
9124 setDisabled : function(v)
9126 var i = this.inputEl().dom;
9128 i.removeAttribute('disabled');
9132 i.setAttribute('disabled','true');
9134 initEvents : function()
9137 this.inputEl().on("keydown" , this.fireKey, this);
9138 this.inputEl().on("focus", this.onFocus, this);
9139 this.inputEl().on("blur", this.onBlur, this);
9141 this.inputEl().relayEvent('keyup', this);
9143 this.indicator = this.indicatorEl();
9146 this.indicator.addClass(this.indicatorpos == 'right' ? 'hidden' : 'invisible'); // changed from invisible??? -
9149 // reference to original value for reset
9150 this.originalValue = this.getValue();
9151 //Roo.form.TextField.superclass.initEvents.call(this);
9152 if(this.validationEvent == 'keyup'){
9153 this.validationTask = new Roo.util.DelayedTask(this.validate, this);
9154 this.inputEl().on('keyup', this.filterValidation, this);
9156 else if(this.validationEvent !== false){
9157 this.inputEl().on(this.validationEvent, this.validate, this, {buffer: this.validationDelay});
9160 if(this.selectOnFocus){
9161 this.on("focus", this.preFocus, this);
9164 if(this.maskRe || (this.vtype && this.disableKeyFilter !== true && (this.maskRe = Roo.form.VTypes[this.vtype+'Mask']))){
9165 this.inputEl().on("keypress", this.filterKeys, this);
9167 this.inputEl().relayEvent('keypress', this);
9170 this.el.on("keyup", this.onKeyUp, this, {buffer:50});
9171 this.el.on("click", this.autoSize, this);
9174 if(this.inputEl().is('input[type=password]') && Roo.isSafari){
9175 this.inputEl().on('keydown', this.SafariOnKeyDown, this);
9178 if (typeof(this.before) == 'object') {
9179 this.before.render(this.el.select('.roo-input-before',true).first());
9181 if (typeof(this.after) == 'object') {
9182 this.after.render(this.el.select('.roo-input-after',true).first());
9185 this.inputEl().on('change', this.onChange, this);
9188 filterValidation : function(e){
9189 if(!e.isNavKeyPress()){
9190 this.validationTask.delay(this.validationDelay);
9194 * Validates the field value
9195 * @return {Boolean} True if the value is valid, else false
9197 validate : function(){
9198 //if(this.disabled || this.validateValue(this.processValue(this.getRawValue()))){
9199 if(this.disabled || this.validateValue(this.getRawValue())){
9210 * Validates a value according to the field's validation rules and marks the field as invalid
9211 * if the validation fails
9212 * @param {Mixed} value The value to validate
9213 * @return {Boolean} True if the value is valid, else false
9215 validateValue : function(value)
9217 if(this.getVisibilityEl().hasClass('hidden')){
9221 if(value.length < 1) { // if it's blank
9222 if(this.allowBlank){
9228 if(value.length < this.minLength){
9231 if(value.length > this.maxLength){
9235 var vt = Roo.form.VTypes;
9236 if(!vt[this.vtype](value, this)){
9240 if(typeof this.validator == "function"){
9241 var msg = this.validator(value);
9245 if (typeof(msg) == 'string') {
9246 this.invalidText = msg;
9250 if(this.regex && !this.regex.test(value)){
9258 fireKey : function(e){
9259 //Roo.log('field ' + e.getKey());
9260 if(e.isNavKeyPress()){
9261 this.fireEvent("specialkey", this, e);
9264 focus : function (selectText){
9266 this.inputEl().focus();
9267 if(selectText === true){
9268 this.inputEl().dom.select();
9274 onFocus : function(){
9275 if(!Roo.isOpera && this.focusClass){ // don't touch in Opera
9276 // this.el.addClass(this.focusClass);
9279 this.hasFocus = true;
9280 this.startValue = this.getValue();
9281 this.fireEvent("focus", this);
9285 beforeBlur : Roo.emptyFn,
9289 onBlur : function(){
9291 if(!Roo.isOpera && this.focusClass){ // don't touch in Opera
9292 //this.el.removeClass(this.focusClass);
9294 this.hasFocus = false;
9295 if(this.validationEvent !== false && this.validateOnBlur && this.validationEvent != "blur"){
9298 var v = this.getValue();
9299 if(String(v) !== String(this.startValue)){
9300 this.fireEvent('change', this, v, this.startValue);
9302 this.fireEvent("blur", this);
9305 onChange : function(e)
9307 var v = this.getValue();
9308 if(String(v) !== String(this.startValue)){
9309 this.fireEvent('change', this, v, this.startValue);
9315 * Resets the current field value to the originally loaded value and clears any validation messages
9318 this.setValue(this.originalValue);
9322 * Returns the name of the field
9323 * @return {Mixed} name The name field
9325 getName: function(){
9329 * Returns the normalized data value (undefined or emptyText will be returned as ''). To return the raw value see {@link #getRawValue}.
9330 * @return {Mixed} value The field value
9332 getValue : function(){
9334 var v = this.inputEl().getValue();
9339 * Returns the raw data value which may or may not be a valid, defined value. To return a normalized value see {@link #getValue}.
9340 * @return {Mixed} value The field value
9342 getRawValue : function(){
9343 var v = this.inputEl().getValue();
9349 * Sets the underlying DOM field's value directly, bypassing validation. To set the value with validation see {@link #setValue}.
9350 * @param {Mixed} value The value to set
9352 setRawValue : function(v){
9353 return this.inputEl().dom.value = (v === null || v === undefined ? '' : v);
9356 selectText : function(start, end){
9357 var v = this.getRawValue();
9359 start = start === undefined ? 0 : start;
9360 end = end === undefined ? v.length : end;
9361 var d = this.inputEl().dom;
9362 if(d.setSelectionRange){
9363 d.setSelectionRange(start, end);
9364 }else if(d.createTextRange){
9365 var range = d.createTextRange();
9366 range.moveStart("character", start);
9367 range.moveEnd("character", v.length-end);
9374 * Sets a data value into the field and validates it. To set the value directly without validation see {@link #setRawValue}.
9375 * @param {Mixed} value The value to set
9377 setValue : function(v){
9380 this.inputEl().dom.value = (v === null || v === undefined ? '' : v);
9386 processValue : function(value){
9387 if(this.stripCharsRe){
9388 var newValue = value.replace(this.stripCharsRe, '');
9389 if(newValue !== value){
9390 this.setRawValue(newValue);
9397 preFocus : function(){
9399 if(this.selectOnFocus){
9400 this.inputEl().dom.select();
9403 filterKeys : function(e){
9405 if(!Roo.isIE && (e.isNavKeyPress() || k == e.BACKSPACE || (k == e.DELETE && e.button == -1))){
9408 var c = e.getCharCode(), cc = String.fromCharCode(c);
9409 if(Roo.isIE && (e.isSpecialKey() || !cc)){
9412 if(!this.maskRe.test(cc)){
9417 * Clear any invalid styles/messages for this field
9419 clearInvalid : function(){
9421 if(!this.el || this.preventMark){ // not rendered
9426 this.el.removeClass(this.invalidClass);
9428 if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank){
9430 var feedback = this.el.select('.form-control-feedback', true).first();
9433 this.el.select('.form-control-feedback', true).first().removeClass(this.invalidFeedbackClass);
9439 this.indicator.removeClass('visible');
9440 this.indicator.addClass(this.indicatorpos == 'right' ? 'hidden' : 'invisible');
9443 this.fireEvent('valid', this);
9447 * Mark this field as valid
9449 markValid : function()
9451 if(!this.el || this.preventMark){ // not rendered...
9455 this.el.removeClass([this.invalidClass, this.validClass]);
9457 var feedback = this.el.select('.form-control-feedback', true).first();
9460 this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
9464 this.indicator.removeClass('visible');
9465 this.indicator.addClass(this.indicatorpos == 'right' ? 'hidden' : 'invisible');
9472 if(this.allowBlank && !this.getRawValue().length){
9476 this.el.addClass(this.validClass);
9478 if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank && (this.getValue().length || this.forceFeedback)){
9480 var feedback = this.el.select('.form-control-feedback', true).first();
9483 this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
9484 this.el.select('.form-control-feedback', true).first().addClass([this.validFeedbackClass]);
9489 this.fireEvent('valid', this);
9493 * Mark this field as invalid
9494 * @param {String} msg The validation message
9496 markInvalid : function(msg)
9498 if(!this.el || this.preventMark){ // not rendered
9502 this.el.removeClass([this.invalidClass, this.validClass]);
9504 var feedback = this.el.select('.form-control-feedback', true).first();
9507 this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
9514 if(this.allowBlank && !this.getRawValue().length){
9519 this.indicator.removeClass(this.indicatorpos == 'right' ? 'hidden' : 'invisible');
9520 this.indicator.addClass('visible');
9523 this.el.addClass(this.invalidClass);
9525 if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank){
9527 var feedback = this.el.select('.form-control-feedback', true).first();
9530 this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
9532 if(this.getValue().length || this.forceFeedback){
9533 this.el.select('.form-control-feedback', true).first().addClass([this.invalidFeedbackClass]);
9540 this.fireEvent('invalid', this, msg);
9543 SafariOnKeyDown : function(event)
9545 // this is a workaround for a password hang bug on chrome/ webkit.
9546 if (this.inputEl().dom.type != 'password') {
9550 var isSelectAll = false;
9552 if(this.inputEl().dom.selectionEnd > 0){
9553 isSelectAll = (this.inputEl().dom.selectionEnd - this.inputEl().dom.selectionStart - this.getValue().length == 0) ? true : false;
9555 if(((event.getKey() == 8 || event.getKey() == 46) && this.getValue().length ==1)){ // backspace and delete key
9556 event.preventDefault();
9561 if(isSelectAll && event.getCharCode() > 31 && !event.ctrlKey) { // not backspace and delete key (or ctrl-v)
9563 event.preventDefault();
9564 // this is very hacky as keydown always get's upper case.
9566 var cc = String.fromCharCode(event.getCharCode());
9567 this.setValue( event.shiftKey ? cc : cc.toLowerCase());
9571 adjustWidth : function(tag, w){
9572 tag = tag.toLowerCase();
9573 if(typeof w == 'number' && Roo.isStrict && !Roo.isSafari){
9574 if(Roo.isIE && (tag == 'input' || tag == 'textarea')){
9578 if(tag == 'textarea'){
9581 }else if(Roo.isOpera){
9585 if(tag == 'textarea'){
9593 setFieldLabel : function(v)
9600 var ar = this.el.select('label > span',true);
9602 if (ar.elements.length) {
9603 this.el.select('label > span',true).first().dom.innerHTML = (v === null || v === undefined ? '' : v);
9604 this.fieldLabel = v;
9608 var br = this.el.select('label',true);
9610 if(br.elements.length) {
9611 this.el.select('label',true).first().dom.innerHTML = (v === null || v === undefined ? '' : v);
9612 this.fieldLabel = v;
9616 Roo.log('Cannot Found any of label > span || label in input');
9620 this.el.select('label',true).first().dom.innerHTML = (v === null || v === undefined ? '' : v);
9621 this.fieldLabel = v;
9636 * @class Roo.bootstrap.TextArea
9637 * @extends Roo.bootstrap.Input
9638 * Bootstrap TextArea class
9639 * @cfg {Number} cols Specifies the visible width of a text area
9640 * @cfg {Number} rows Specifies the visible number of lines in a text area
9641 * @cfg {string} wrap (soft|hard)Specifies how the text in a text area is to be wrapped when submitted in a form
9642 * @cfg {string} resize (none|both|horizontal|vertical|inherit|initial)
9643 * @cfg {string} html text
9646 * Create a new TextArea
9647 * @param {Object} config The config object
9650 Roo.bootstrap.TextArea = function(config){
9651 Roo.bootstrap.TextArea.superclass.constructor.call(this, config);
9655 Roo.extend(Roo.bootstrap.TextArea, Roo.bootstrap.Input, {
9665 getAutoCreate : function(){
9667 var align = (!this.labelAlign) ? this.parentLabelAlign() : this.labelAlign;
9673 if(this.inputType != 'hidden'){
9674 cfg.cls = 'form-group' //input-group
9682 value : this.value || '',
9683 html: this.html || '',
9684 cls : 'form-control',
9685 placeholder : this.placeholder || ''
9689 if(this.maxLength && this.maxLength != Number.MAX_VALUE){
9690 input.maxLength = this.maxLength;
9694 input.style = (typeof(input.style) == 'undefined') ? 'resize:' + this.resize : input.style + 'resize:' + this.resize;
9698 input.cols = this.cols;
9701 if (this.readOnly) {
9702 input.readonly = true;
9706 input.name = this.name;
9710 input.cls = (typeof(input.cls) == 'undefined') ? 'input-' + this.size : input.cls + ' input-' + this.size;
9714 ['xs','sm','md','lg'].map(function(size){
9715 if (settings[size]) {
9716 cfg.cls += ' col-' + size + '-' + settings[size];
9720 var inputblock = input;
9722 if(this.hasFeedback && !this.allowBlank){
9726 cls: 'glyphicon form-control-feedback'
9730 cls : 'has-feedback',
9739 if (this.before || this.after) {
9742 cls : 'input-group',
9746 inputblock.cn.push({
9748 cls : 'input-group-addon',
9753 inputblock.cn.push(input);
9755 if(this.hasFeedback && !this.allowBlank){
9756 inputblock.cls += ' has-feedback';
9757 inputblock.cn.push(feedback);
9761 inputblock.cn.push({
9763 cls : 'input-group-addon',
9770 if (align ==='left' && this.fieldLabel.length) {
9775 cls : 'control-label',
9776 html : this.fieldLabel
9787 if(this.labelWidth > 12){
9788 cfg.cn[0].style = "width: " + this.labelWidth + 'px';
9791 if(this.labelWidth < 13 && this.labelmd == 0){
9792 this.labelmd = this.labelWidth;
9795 if(this.labellg > 0){
9796 cfg.cn[0].cls += ' col-lg-' + this.labellg;
9797 cfg.cn[1].cls += ' col-lg-' + (12 - this.labellg);
9800 if(this.labelmd > 0){
9801 cfg.cn[0].cls += ' col-md-' + this.labelmd;
9802 cfg.cn[1].cls += ' col-md-' + (12 - this.labelmd);
9805 if(this.labelsm > 0){
9806 cfg.cn[0].cls += ' col-sm-' + this.labelsm;
9807 cfg.cn[1].cls += ' col-sm-' + (12 - this.labelsm);
9810 if(this.labelxs > 0){
9811 cfg.cn[0].cls += ' col-xs-' + this.labelxs;
9812 cfg.cn[1].cls += ' col-xs-' + (12 - this.labelxs);
9815 } else if ( this.fieldLabel.length) {
9820 //cls : 'input-group-addon',
9821 html : this.fieldLabel
9839 if (this.disabled) {
9840 input.disabled=true;
9847 * return the real textarea element.
9849 inputEl: function ()
9851 return this.el.select('textarea.form-control',true).first();
9855 * Clear any invalid styles/messages for this field
9857 clearInvalid : function()
9860 if(!this.el || this.preventMark){ // not rendered
9864 var label = this.el.select('label', true).first();
9865 var icon = this.el.select('i.fa-star', true).first();
9871 this.el.removeClass(this.invalidClass);
9873 if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank){
9875 var feedback = this.el.select('.form-control-feedback', true).first();
9878 this.el.select('.form-control-feedback', true).first().removeClass(this.invalidFeedbackClass);
9883 this.fireEvent('valid', this);
9887 * Mark this field as valid
9889 markValid : function()
9891 if(!this.el || this.preventMark){ // not rendered
9895 this.el.removeClass([this.invalidClass, this.validClass]);
9897 var feedback = this.el.select('.form-control-feedback', true).first();
9900 this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
9903 if(this.disabled || this.allowBlank){
9907 var label = this.el.select('label', true).first();
9908 var icon = this.el.select('i.fa-star', true).first();
9914 this.el.addClass(this.validClass);
9916 if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank && (this.getValue().length || this.forceFeedback)){
9918 var feedback = this.el.select('.form-control-feedback', true).first();
9921 this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
9922 this.el.select('.form-control-feedback', true).first().addClass([this.validFeedbackClass]);
9927 this.fireEvent('valid', this);
9931 * Mark this field as invalid
9932 * @param {String} msg The validation message
9934 markInvalid : function(msg)
9936 if(!this.el || this.preventMark){ // not rendered
9940 this.el.removeClass([this.invalidClass, this.validClass]);
9942 var feedback = this.el.select('.form-control-feedback', true).first();
9945 this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
9948 if(this.disabled || this.allowBlank){
9952 var label = this.el.select('label', true).first();
9953 var icon = this.el.select('i.fa-star', true).first();
9955 if(!this.getValue().length && label && !icon){
9956 this.el.createChild({
9958 cls : 'text-danger fa fa-lg fa-star',
9959 tooltip : 'This field is required',
9960 style : 'margin-right:5px;'
9964 this.el.addClass(this.invalidClass);
9966 if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank){
9968 var feedback = this.el.select('.form-control-feedback', true).first();
9971 this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
9973 if(this.getValue().length || this.forceFeedback){
9974 this.el.select('.form-control-feedback', true).first().addClass([this.invalidFeedbackClass]);
9981 this.fireEvent('invalid', this, msg);
9989 * trigger field - base class for combo..
9994 * @class Roo.bootstrap.TriggerField
9995 * @extends Roo.bootstrap.Input
9996 * Provides a convenient wrapper for TextFields that adds a clickable trigger button (looks like a combobox by default).
9997 * The trigger has no default action, so you must assign a function to implement the trigger click handler by
9998 * overriding {@link #onTriggerClick}. You can create a TriggerField directly, as it renders exactly like a combobox
9999 * for which you can provide a custom implementation. For example:
10001 var trigger = new Roo.bootstrap.TriggerField();
10002 trigger.onTriggerClick = myTriggerFn;
10003 trigger.applyTo('my-field');
10006 * However, in general you will most likely want to use TriggerField as the base class for a reusable component.
10007 * {@link Roo.bootstrap.DateField} and {@link Roo.bootstrap.ComboBox} are perfect examples of this.
10008 * @cfg {String} triggerClass An additional CSS class used to style the trigger button. The trigger will always get the
10009 * class 'x-form-trigger' by default and triggerClass will be <b>appended</b> if specified.
10010 * @cfg {String} caret (search|calendar) a fontawesome for the trigger icon see http://fortawesome.github.io/Font-Awesome/icons/
10013 * Create a new TriggerField.
10014 * @param {Object} config Configuration options (valid {@Roo.bootstrap.Input} config options will also be applied
10015 * to the base TextField)
10017 Roo.bootstrap.TriggerField = function(config){
10018 this.mimicing = false;
10019 Roo.bootstrap.TriggerField.superclass.constructor.call(this, config);
10022 Roo.extend(Roo.bootstrap.TriggerField, Roo.bootstrap.Input, {
10024 * @cfg {String} triggerClass A CSS class to apply to the trigger
10027 * @cfg {Boolean} hideTrigger True to hide the trigger element and display only the base text field (defaults to false)
10032 * @cfg {Boolean} removable (true|false) special filter default false
10036 /** @cfg {Boolean} grow @hide */
10037 /** @cfg {Number} growMin @hide */
10038 /** @cfg {Number} growMax @hide */
10044 autoSize: Roo.emptyFn,
10048 deferHeight : true,
10051 actionMode : 'wrap',
10056 getAutoCreate : function(){
10058 var align = this.labelAlign || this.parentLabelAlign();
10063 cls: 'form-group' //input-group
10070 type : this.inputType,
10071 cls : 'form-control',
10072 autocomplete: 'new-password',
10073 placeholder : this.placeholder || ''
10077 input.name = this.name;
10080 input.cls += ' input-' + this.size;
10083 if (this.disabled) {
10084 input.disabled=true;
10087 var inputblock = input;
10089 if(this.hasFeedback && !this.allowBlank){
10093 cls: 'glyphicon form-control-feedback'
10096 if(this.removable && !this.editable && !this.tickable){
10098 cls : 'has-feedback',
10104 cls : 'roo-combo-removable-btn close'
10111 cls : 'has-feedback',
10120 if(this.removable && !this.editable && !this.tickable){
10122 cls : 'roo-removable',
10128 cls : 'roo-combo-removable-btn close'
10135 if (this.before || this.after) {
10138 cls : 'input-group',
10142 inputblock.cn.push({
10144 cls : 'input-group-addon',
10149 inputblock.cn.push(input);
10151 if(this.hasFeedback && !this.allowBlank){
10152 inputblock.cls += ' has-feedback';
10153 inputblock.cn.push(feedback);
10157 inputblock.cn.push({
10159 cls : 'input-group-addon',
10172 cls: 'form-hidden-field'
10186 cls: 'form-hidden-field'
10190 cls: 'roo-select2-choices',
10194 cls: 'roo-select2-search-field',
10207 cls: 'roo-select2-container input-group',
10212 // cls: 'typeahead typeahead-long dropdown-menu',
10213 // style: 'display:none'
10218 if(!this.multiple && this.showToggleBtn){
10224 if (this.caret != false) {
10227 cls: 'fa fa-' + this.caret
10234 cls : 'input-group-addon btn dropdown-toggle',
10239 cls: 'combobox-clear',
10253 combobox.cls += ' roo-select2-container-multi';
10256 if (align ==='left' && this.fieldLabel.length) {
10258 cfg.cls += ' roo-form-group-label-left';
10263 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
10264 tooltip : 'This field is required'
10269 cls : 'control-label',
10270 html : this.fieldLabel
10282 var labelCfg = cfg.cn[1];
10283 var contentCfg = cfg.cn[2];
10285 if(this.indicatorpos == 'right'){
10290 cls : 'control-label',
10294 html : this.fieldLabel
10298 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
10299 tooltip : 'This field is required'
10312 labelCfg = cfg.cn[0];
10313 contentCfg = cfg.cn[1];
10316 if(this.labelWidth > 12){
10317 labelCfg.style = "width: " + this.labelWidth + 'px';
10320 if(this.labelWidth < 13 && this.labelmd == 0){
10321 this.labelmd = this.labelWidth;
10324 if(this.labellg > 0){
10325 labelCfg.cls += ' col-lg-' + this.labellg;
10326 contentCfg.cls += ' col-lg-' + (12 - this.labellg);
10329 if(this.labelmd > 0){
10330 labelCfg.cls += ' col-md-' + this.labelmd;
10331 contentCfg.cls += ' col-md-' + (12 - this.labelmd);
10334 if(this.labelsm > 0){
10335 labelCfg.cls += ' col-sm-' + this.labelsm;
10336 contentCfg.cls += ' col-sm-' + (12 - this.labelsm);
10339 if(this.labelxs > 0){
10340 labelCfg.cls += ' col-xs-' + this.labelxs;
10341 contentCfg.cls += ' col-xs-' + (12 - this.labelxs);
10344 } else if ( this.fieldLabel.length) {
10345 // Roo.log(" label");
10349 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
10350 tooltip : 'This field is required'
10354 //cls : 'input-group-addon',
10355 html : this.fieldLabel
10363 if(this.indicatorpos == 'right'){
10371 html : this.fieldLabel
10375 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
10376 tooltip : 'This field is required'
10389 // Roo.log(" no label && no align");
10396 ['xs','sm','md','lg'].map(function(size){
10397 if (settings[size]) {
10398 cfg.cls += ' col-' + size + '-' + settings[size];
10409 onResize : function(w, h){
10410 // Roo.bootstrap.TriggerField.superclass.onResize.apply(this, arguments);
10411 // if(typeof w == 'number'){
10412 // var x = w - this.trigger.getWidth();
10413 // this.inputEl().setWidth(this.adjustWidth('input', x));
10414 // this.trigger.setStyle('left', x+'px');
10419 adjustSize : Roo.BoxComponent.prototype.adjustSize,
10422 getResizeEl : function(){
10423 return this.inputEl();
10427 getPositionEl : function(){
10428 return this.inputEl();
10432 alignErrorIcon : function(){
10433 this.errorIcon.alignTo(this.inputEl(), 'tl-tr', [2, 0]);
10437 initEvents : function(){
10441 Roo.bootstrap.TriggerField.superclass.initEvents.call(this);
10442 //this.wrap = this.el.wrap({cls: "x-form-field-wrap"});
10443 if(!this.multiple && this.showToggleBtn){
10444 this.trigger = this.el.select('span.dropdown-toggle',true).first();
10445 if(this.hideTrigger){
10446 this.trigger.setDisplayed(false);
10448 this.trigger.on("click", this.onTriggerClick, this, {preventDefault:true});
10452 this.inputEl().on("click", this.onTriggerClick, this, {preventDefault:true});
10455 if(this.removable && !this.editable && !this.tickable){
10456 var close = this.closeTriggerEl();
10459 close.setVisibilityMode(Roo.Element.DISPLAY).hide();
10460 close.on('click', this.removeBtnClick, this, close);
10464 //this.trigger.addClassOnOver('x-form-trigger-over');
10465 //this.trigger.addClassOnClick('x-form-trigger-click');
10468 // this.wrap.setWidth(this.el.getWidth()+this.trigger.getWidth());
10472 closeTriggerEl : function()
10474 var close = this.el.select('.roo-combo-removable-btn', true).first();
10475 return close ? close : false;
10478 removeBtnClick : function(e, h, el)
10480 e.preventDefault();
10482 if(this.fireEvent("remove", this) !== false){
10484 this.fireEvent("afterremove", this)
10488 createList : function()
10490 this.list = Roo.get(document.body).createChild({
10492 cls: 'typeahead typeahead-long dropdown-menu',
10493 style: 'display:none'
10496 this.list.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';;
10501 initTrigger : function(){
10506 onDestroy : function(){
10508 this.trigger.removeAllListeners();
10509 // this.trigger.remove();
10512 // this.wrap.remove();
10514 Roo.bootstrap.TriggerField.superclass.onDestroy.call(this);
10518 onFocus : function(){
10519 Roo.bootstrap.TriggerField.superclass.onFocus.call(this);
10521 if(!this.mimicing){
10522 this.wrap.addClass('x-trigger-wrap-focus');
10523 this.mimicing = true;
10524 Roo.get(Roo.isIE ? document.body : document).on("mousedown", this.mimicBlur, this);
10525 if(this.monitorTab){
10526 this.el.on("keydown", this.checkTab, this);
10533 checkTab : function(e){
10534 if(e.getKey() == e.TAB){
10535 this.triggerBlur();
10540 onBlur : function(){
10545 mimicBlur : function(e, t){
10547 if(!this.wrap.contains(t) && this.validateBlur()){
10548 this.triggerBlur();
10554 triggerBlur : function(){
10555 this.mimicing = false;
10556 Roo.get(Roo.isIE ? document.body : document).un("mousedown", this.mimicBlur);
10557 if(this.monitorTab){
10558 this.el.un("keydown", this.checkTab, this);
10560 //this.wrap.removeClass('x-trigger-wrap-focus');
10561 Roo.bootstrap.TriggerField.superclass.onBlur.call(this);
10565 // This should be overriden by any subclass that needs to check whether or not the field can be blurred.
10566 validateBlur : function(e, t){
10571 onDisable : function(){
10572 this.inputEl().dom.disabled = true;
10573 //Roo.bootstrap.TriggerField.superclass.onDisable.call(this);
10575 // this.wrap.addClass('x-item-disabled');
10580 onEnable : function(){
10581 this.inputEl().dom.disabled = false;
10582 //Roo.bootstrap.TriggerField.superclass.onEnable.call(this);
10584 // this.el.removeClass('x-item-disabled');
10589 onShow : function(){
10590 var ae = this.getActionEl();
10593 ae.dom.style.display = '';
10594 ae.dom.style.visibility = 'visible';
10600 onHide : function(){
10601 var ae = this.getActionEl();
10602 ae.dom.style.display = 'none';
10606 * The function that should handle the trigger's click event. This method does nothing by default until overridden
10607 * by an implementing function.
10609 * @param {EventObject} e
10611 onTriggerClick : Roo.emptyFn
10615 * Ext JS Library 1.1.1
10616 * Copyright(c) 2006-2007, Ext JS, LLC.
10618 * Originally Released Under LGPL - original licence link has changed is not relivant.
10621 * <script type="text/javascript">
10626 * @class Roo.data.SortTypes
10628 * Defines the default sorting (casting?) comparison functions used when sorting data.
10630 Roo.data.SortTypes = {
10632 * Default sort that does nothing
10633 * @param {Mixed} s The value being converted
10634 * @return {Mixed} The comparison value
10636 none : function(s){
10641 * The regular expression used to strip tags
10645 stripTagsRE : /<\/?[^>]+>/gi,
10648 * Strips all HTML tags to sort on text only
10649 * @param {Mixed} s The value being converted
10650 * @return {String} The comparison value
10652 asText : function(s){
10653 return String(s).replace(this.stripTagsRE, "");
10657 * Strips all HTML tags to sort on text only - Case insensitive
10658 * @param {Mixed} s The value being converted
10659 * @return {String} The comparison value
10661 asUCText : function(s){
10662 return String(s).toUpperCase().replace(this.stripTagsRE, "");
10666 * Case insensitive string
10667 * @param {Mixed} s The value being converted
10668 * @return {String} The comparison value
10670 asUCString : function(s) {
10671 return String(s).toUpperCase();
10676 * @param {Mixed} s The value being converted
10677 * @return {Number} The comparison value
10679 asDate : function(s) {
10683 if(s instanceof Date){
10684 return s.getTime();
10686 return Date.parse(String(s));
10691 * @param {Mixed} s The value being converted
10692 * @return {Float} The comparison value
10694 asFloat : function(s) {
10695 var val = parseFloat(String(s).replace(/,/g, ""));
10704 * @param {Mixed} s The value being converted
10705 * @return {Number} The comparison value
10707 asInt : function(s) {
10708 var val = parseInt(String(s).replace(/,/g, ""));
10716 * Ext JS Library 1.1.1
10717 * Copyright(c) 2006-2007, Ext JS, LLC.
10719 * Originally Released Under LGPL - original licence link has changed is not relivant.
10722 * <script type="text/javascript">
10726 * @class Roo.data.Record
10727 * Instances of this class encapsulate both record <em>definition</em> information, and record
10728 * <em>value</em> information for use in {@link Roo.data.Store} objects, or any code which needs
10729 * to access Records cached in an {@link Roo.data.Store} object.<br>
10731 * Constructors for this class are generated by passing an Array of field definition objects to {@link #create}.
10732 * Instances are usually only created by {@link Roo.data.Reader} implementations when processing unformatted data
10735 * Record objects generated by this constructor inherit all the methods of Roo.data.Record listed below.
10737 * This constructor should not be used to create Record objects. Instead, use the constructor generated by
10738 * {@link #create}. The parameters are the same.
10739 * @param {Array} data An associative Array of data values keyed by the field name.
10740 * @param {Object} id (Optional) The id of the record. This id should be unique, and is used by the
10741 * {@link Roo.data.Store} object which owns the Record to index its collection of Records. If
10742 * not specified an integer id is generated.
10744 Roo.data.Record = function(data, id){
10745 this.id = (id || id === 0) ? id : ++Roo.data.Record.AUTO_ID;
10750 * Generate a constructor for a specific record layout.
10751 * @param {Array} o An Array of field definition objects which specify field names, and optionally,
10752 * data types, and a mapping for an {@link Roo.data.Reader} to extract the field's value from a data object.
10753 * Each field definition object may contain the following properties: <ul>
10754 * <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,
10755 * for example the <em>dataIndex</em> property in column definition objects passed to {@link Roo.grid.ColumnModel}</p></li>
10756 * <li><b>mapping</b> : String<p style="margin-left:1em">(Optional) A path specification for use by the {@link Roo.data.Reader} implementation
10757 * that is creating the Record to access the data value from the data object. If an {@link Roo.data.JsonReader}
10758 * is being used, then this is a string containing the javascript expression to reference the data relative to
10759 * the record item's root. If an {@link Roo.data.XmlReader} is being used, this is an {@link Roo.DomQuery} path
10760 * to the data item relative to the record element. If the mapping expression is the same as the field name,
10761 * this may be omitted.</p></li>
10762 * <li><b>type</b> : String<p style="margin-left:1em">(Optional) The data type for conversion to displayable value. Possible values are
10763 * <ul><li>auto (Default, implies no conversion)</li>
10768 * <li>date</li></ul></p></li>
10769 * <li><b>sortType</b> : Mixed<p style="margin-left:1em">(Optional) A member of {@link Roo.data.SortTypes}.</p></li>
10770 * <li><b>sortDir</b> : String<p style="margin-left:1em">(Optional) Initial direction to sort. "ASC" or "DESC"</p></li>
10771 * <li><b>convert</b> : Function<p style="margin-left:1em">(Optional) A function which converts the value provided
10772 * by the Reader into an object that will be stored in the Record. It is passed the
10773 * following parameters:<ul>
10774 * <li><b>v</b> : Mixed<p style="margin-left:1em">The data value as read by the Reader.</p></li>
10776 * <li><b>dateFormat</b> : String<p style="margin-left:1em">(Optional) A format String for the Date.parseDate function.</p></li>
10778 * <br>usage:<br><pre><code>
10779 var TopicRecord = Roo.data.Record.create(
10780 {name: 'title', mapping: 'topic_title'},
10781 {name: 'author', mapping: 'username'},
10782 {name: 'totalPosts', mapping: 'topic_replies', type: 'int'},
10783 {name: 'lastPost', mapping: 'post_time', type: 'date'},
10784 {name: 'lastPoster', mapping: 'user2'},
10785 {name: 'excerpt', mapping: 'post_text'}
10788 var myNewRecord = new TopicRecord({
10789 title: 'Do my job please',
10792 lastPost: new Date(),
10793 lastPoster: 'Animal',
10794 excerpt: 'No way dude!'
10796 myStore.add(myNewRecord);
10801 Roo.data.Record.create = function(o){
10802 var f = function(){
10803 f.superclass.constructor.apply(this, arguments);
10805 Roo.extend(f, Roo.data.Record);
10806 var p = f.prototype;
10807 p.fields = new Roo.util.MixedCollection(false, function(field){
10810 for(var i = 0, len = o.length; i < len; i++){
10811 p.fields.add(new Roo.data.Field(o[i]));
10813 f.getField = function(name){
10814 return p.fields.get(name);
10819 Roo.data.Record.AUTO_ID = 1000;
10820 Roo.data.Record.EDIT = 'edit';
10821 Roo.data.Record.REJECT = 'reject';
10822 Roo.data.Record.COMMIT = 'commit';
10824 Roo.data.Record.prototype = {
10826 * Readonly flag - true if this record has been modified.
10835 join : function(store){
10836 this.store = store;
10840 * Set the named field to the specified value.
10841 * @param {String} name The name of the field to set.
10842 * @param {Object} value The value to set the field to.
10844 set : function(name, value){
10845 if(this.data[name] == value){
10849 if(!this.modified){
10850 this.modified = {};
10852 if(typeof this.modified[name] == 'undefined'){
10853 this.modified[name] = this.data[name];
10855 this.data[name] = value;
10856 if(!this.editing && this.store){
10857 this.store.afterEdit(this);
10862 * Get the value of the named field.
10863 * @param {String} name The name of the field to get the value of.
10864 * @return {Object} The value of the field.
10866 get : function(name){
10867 return this.data[name];
10871 beginEdit : function(){
10872 this.editing = true;
10873 this.modified = {};
10877 cancelEdit : function(){
10878 this.editing = false;
10879 delete this.modified;
10883 endEdit : function(){
10884 this.editing = false;
10885 if(this.dirty && this.store){
10886 this.store.afterEdit(this);
10891 * Usually called by the {@link Roo.data.Store} which owns the Record.
10892 * Rejects all changes made to the Record since either creation, or the last commit operation.
10893 * Modified fields are reverted to their original values.
10895 * Developers should subscribe to the {@link Roo.data.Store#update} event to have their code notified
10896 * of reject operations.
10898 reject : function(){
10899 var m = this.modified;
10901 if(typeof m[n] != "function"){
10902 this.data[n] = m[n];
10905 this.dirty = false;
10906 delete this.modified;
10907 this.editing = false;
10909 this.store.afterReject(this);
10914 * Usually called by the {@link Roo.data.Store} which owns the Record.
10915 * Commits all changes made to the Record since either creation, or the last commit operation.
10917 * Developers should subscribe to the {@link Roo.data.Store#update} event to have their code notified
10918 * of commit operations.
10920 commit : function(){
10921 this.dirty = false;
10922 delete this.modified;
10923 this.editing = false;
10925 this.store.afterCommit(this);
10930 hasError : function(){
10931 return this.error != null;
10935 clearError : function(){
10940 * Creates a copy of this record.
10941 * @param {String} id (optional) A new record id if you don't want to use this record's id
10944 copy : function(newId) {
10945 return new this.constructor(Roo.apply({}, this.data), newId || this.id);
10949 * Ext JS Library 1.1.1
10950 * Copyright(c) 2006-2007, Ext JS, LLC.
10952 * Originally Released Under LGPL - original licence link has changed is not relivant.
10955 * <script type="text/javascript">
10961 * @class Roo.data.Store
10962 * @extends Roo.util.Observable
10963 * The Store class encapsulates a client side cache of {@link Roo.data.Record} objects which provide input data
10964 * for widgets such as the Roo.grid.Grid, or the Roo.form.ComboBox.<br>
10966 * 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
10967 * has no knowledge of the format of the data returned by the Proxy.<br>
10969 * A Store object uses its configured implementation of {@link Roo.data.DataReader} to create {@link Roo.data.Record}
10970 * instances from the data object. These records are cached and made available through accessor functions.
10972 * Creates a new Store.
10973 * @param {Object} config A config object containing the objects needed for the Store to access data,
10974 * and read the data into Records.
10976 Roo.data.Store = function(config){
10977 this.data = new Roo.util.MixedCollection(false);
10978 this.data.getKey = function(o){
10981 this.baseParams = {};
10983 this.paramNames = {
10988 "multisort" : "_multisort"
10991 if(config && config.data){
10992 this.inlineData = config.data;
10993 delete config.data;
10996 Roo.apply(this, config);
10998 if(this.reader){ // reader passed
10999 this.reader = Roo.factory(this.reader, Roo.data);
11000 this.reader.xmodule = this.xmodule || false;
11001 if(!this.recordType){
11002 this.recordType = this.reader.recordType;
11004 if(this.reader.onMetaChange){
11005 this.reader.onMetaChange = this.onMetaChange.createDelegate(this);
11009 if(this.recordType){
11010 this.fields = this.recordType.prototype.fields;
11012 this.modified = [];
11016 * @event datachanged
11017 * Fires when the data cache has changed, and a widget which is using this Store
11018 * as a Record cache should refresh its view.
11019 * @param {Store} this
11021 datachanged : true,
11023 * @event metachange
11024 * Fires when this store's reader provides new metadata (fields). This is currently only support for JsonReaders.
11025 * @param {Store} this
11026 * @param {Object} meta The JSON metadata
11031 * Fires when Records have been added to the Store
11032 * @param {Store} this
11033 * @param {Roo.data.Record[]} records The array of Records added
11034 * @param {Number} index The index at which the record(s) were added
11039 * Fires when a Record has been removed from the Store
11040 * @param {Store} this
11041 * @param {Roo.data.Record} record The Record that was removed
11042 * @param {Number} index The index at which the record was removed
11047 * Fires when a Record has been updated
11048 * @param {Store} this
11049 * @param {Roo.data.Record} record The Record that was updated
11050 * @param {String} operation The update operation being performed. Value may be one of:
11052 Roo.data.Record.EDIT
11053 Roo.data.Record.REJECT
11054 Roo.data.Record.COMMIT
11060 * Fires when the data cache has been cleared.
11061 * @param {Store} this
11065 * @event beforeload
11066 * Fires before a request is made for a new data object. If the beforeload handler returns false
11067 * the load action will be canceled.
11068 * @param {Store} this
11069 * @param {Object} options The loading options that were specified (see {@link #load} for details)
11073 * @event beforeloadadd
11074 * Fires after a new set of Records has been loaded.
11075 * @param {Store} this
11076 * @param {Roo.data.Record[]} records The Records that were loaded
11077 * @param {Object} options The loading options that were specified (see {@link #load} for details)
11079 beforeloadadd : true,
11082 * Fires after a new set of Records has been loaded, before they are added to the store.
11083 * @param {Store} this
11084 * @param {Roo.data.Record[]} records The Records that were loaded
11085 * @param {Object} options The loading options that were specified (see {@link #load} for details)
11086 * @params {Object} return from reader
11090 * @event loadexception
11091 * Fires if an exception occurs in the Proxy during loading.
11092 * Called with the signature of the Proxy's "loadexception" event.
11093 * If you return Json { data: [] , success: false, .... } then this will be thrown with the following args
11096 * @param {Object} return from JsonData.reader() - success, totalRecords, records
11097 * @param {Object} load options
11098 * @param {Object} jsonData from your request (normally this contains the Exception)
11100 loadexception : true
11104 this.proxy = Roo.factory(this.proxy, Roo.data);
11105 this.proxy.xmodule = this.xmodule || false;
11106 this.relayEvents(this.proxy, ["loadexception"]);
11108 this.sortToggle = {};
11109 this.sortOrder = []; // array of order of sorting - updated by grid if multisort is enabled.
11111 Roo.data.Store.superclass.constructor.call(this);
11113 if(this.inlineData){
11114 this.loadData(this.inlineData);
11115 delete this.inlineData;
11119 Roo.extend(Roo.data.Store, Roo.util.Observable, {
11121 * @cfg {boolean} isLocal flag if data is locally available (and can be always looked up
11122 * without a remote query - used by combo/forms at present.
11126 * @cfg {Roo.data.DataProxy} proxy The Proxy object which provides access to a data object.
11129 * @cfg {Array} data Inline data to be loaded when the store is initialized.
11132 * @cfg {Roo.data.Reader} reader The Reader object which processes the data object and returns
11133 * an Array of Roo.data.record objects which are cached keyed by their <em>id</em> property.
11136 * @cfg {Object} baseParams An object containing properties which are to be sent as parameters
11137 * on any HTTP request
11140 * @cfg {Object} sortInfo A config object in the format: {field: "fieldName", direction: "ASC|DESC"}
11143 * @cfg {Boolean} multiSort enable multi column sorting (sort is based on the order of columns, remote only at present)
11147 * @cfg {boolean} remoteSort True if sorting is to be handled by requesting the Proxy to provide a refreshed
11148 * version of the data object in sorted order, as opposed to sorting the Record cache in place (defaults to false).
11150 remoteSort : false,
11153 * @cfg {boolean} pruneModifiedRecords True to clear all modified record information each time the store is
11154 * loaded or when a record is removed. (defaults to false).
11156 pruneModifiedRecords : false,
11159 lastOptions : null,
11162 * Add Records to the Store and fires the add event.
11163 * @param {Roo.data.Record[]} records An Array of Roo.data.Record objects to add to the cache.
11165 add : function(records){
11166 records = [].concat(records);
11167 for(var i = 0, len = records.length; i < len; i++){
11168 records[i].join(this);
11170 var index = this.data.length;
11171 this.data.addAll(records);
11172 this.fireEvent("add", this, records, index);
11176 * Remove a Record from the Store and fires the remove event.
11177 * @param {Ext.data.Record} record The Roo.data.Record object to remove from the cache.
11179 remove : function(record){
11180 var index = this.data.indexOf(record);
11181 this.data.removeAt(index);
11183 if(this.pruneModifiedRecords){
11184 this.modified.remove(record);
11186 this.fireEvent("remove", this, record, index);
11190 * Remove all Records from the Store and fires the clear event.
11192 removeAll : function(){
11194 if(this.pruneModifiedRecords){
11195 this.modified = [];
11197 this.fireEvent("clear", this);
11201 * Inserts Records to the Store at the given index and fires the add event.
11202 * @param {Number} index The start index at which to insert the passed Records.
11203 * @param {Roo.data.Record[]} records An Array of Roo.data.Record objects to add to the cache.
11205 insert : function(index, records){
11206 records = [].concat(records);
11207 for(var i = 0, len = records.length; i < len; i++){
11208 this.data.insert(index, records[i]);
11209 records[i].join(this);
11211 this.fireEvent("add", this, records, index);
11215 * Get the index within the cache of the passed Record.
11216 * @param {Roo.data.Record} record The Roo.data.Record object to to find.
11217 * @return {Number} The index of the passed Record. Returns -1 if not found.
11219 indexOf : function(record){
11220 return this.data.indexOf(record);
11224 * Get the index within the cache of the Record with the passed id.
11225 * @param {String} id The id of the Record to find.
11226 * @return {Number} The index of the Record. Returns -1 if not found.
11228 indexOfId : function(id){
11229 return this.data.indexOfKey(id);
11233 * Get the Record with the specified id.
11234 * @param {String} id The id of the Record to find.
11235 * @return {Roo.data.Record} The Record with the passed id. Returns undefined if not found.
11237 getById : function(id){
11238 return this.data.key(id);
11242 * Get the Record at the specified index.
11243 * @param {Number} index The index of the Record to find.
11244 * @return {Roo.data.Record} The Record at the passed index. Returns undefined if not found.
11246 getAt : function(index){
11247 return this.data.itemAt(index);
11251 * Returns a range of Records between specified indices.
11252 * @param {Number} startIndex (optional) The starting index (defaults to 0)
11253 * @param {Number} endIndex (optional) The ending index (defaults to the last Record in the Store)
11254 * @return {Roo.data.Record[]} An array of Records
11256 getRange : function(start, end){
11257 return this.data.getRange(start, end);
11261 storeOptions : function(o){
11262 o = Roo.apply({}, o);
11265 this.lastOptions = o;
11269 * Loads the Record cache from the configured Proxy using the configured Reader.
11271 * If using remote paging, then the first load call must specify the <em>start</em>
11272 * and <em>limit</em> properties in the options.params property to establish the initial
11273 * position within the dataset, and the number of Records to cache on each read from the Proxy.
11275 * <strong>It is important to note that for remote data sources, loading is asynchronous,
11276 * and this call will return before the new data has been loaded. Perform any post-processing
11277 * in a callback function, or in a "load" event handler.</strong>
11279 * @param {Object} options An object containing properties which control loading options:<ul>
11280 * <li>params {Object} An object containing properties to pass as HTTP parameters to a remote data source.</li>
11281 * <li>callback {Function} A function to be called after the Records have been loaded. The callback is
11282 * passed the following arguments:<ul>
11283 * <li>r : Roo.data.Record[]</li>
11284 * <li>options: Options object from the load call</li>
11285 * <li>success: Boolean success indicator</li></ul></li>
11286 * <li>scope {Object} Scope with which to call the callback (defaults to the Store object)</li>
11287 * <li>add {Boolean} indicator to append loaded records rather than replace the current cache.</li>
11290 load : function(options){
11291 options = options || {};
11292 if(this.fireEvent("beforeload", this, options) !== false){
11293 this.storeOptions(options);
11294 var p = Roo.apply(options.params || {}, this.baseParams);
11295 // if meta was not loaded from remote source.. try requesting it.
11296 if (!this.reader.metaFromRemote) {
11297 p._requestMeta = 1;
11299 if(this.sortInfo && this.remoteSort){
11300 var pn = this.paramNames;
11301 p[pn["sort"]] = this.sortInfo.field;
11302 p[pn["dir"]] = this.sortInfo.direction;
11304 if (this.multiSort) {
11305 var pn = this.paramNames;
11306 p[pn["multisort"]] = Roo.encode( { sort : this.sortToggle, order: this.sortOrder });
11309 this.proxy.load(p, this.reader, this.loadRecords, this, options);
11314 * Reloads the Record cache from the configured Proxy using the configured Reader and
11315 * the options from the last load operation performed.
11316 * @param {Object} options (optional) An object containing properties which may override the options
11317 * used in the last load operation. See {@link #load} for details (defaults to null, in which case
11318 * the most recently used options are reused).
11320 reload : function(options){
11321 this.load(Roo.applyIf(options||{}, this.lastOptions));
11325 // Called as a callback by the Reader during a load operation.
11326 loadRecords : function(o, options, success){
11327 if(!o || success === false){
11328 if(success !== false){
11329 this.fireEvent("load", this, [], options, o);
11331 if(options.callback){
11332 options.callback.call(options.scope || this, [], options, false);
11336 // if data returned failure - throw an exception.
11337 if (o.success === false) {
11338 // show a message if no listener is registered.
11339 if (!this.hasListener('loadexception') && typeof(o.raw.errorMsg) != 'undefined') {
11340 Roo.MessageBox.alert("Error loading",o.raw.errorMsg);
11342 // loadmask wil be hooked into this..
11343 this.fireEvent("loadexception", this, o, options, o.raw.errorMsg);
11346 var r = o.records, t = o.totalRecords || r.length;
11348 this.fireEvent("beforeloadadd", this, r, options, o);
11350 if(!options || options.add !== true){
11351 if(this.pruneModifiedRecords){
11352 this.modified = [];
11354 for(var i = 0, len = r.length; i < len; i++){
11358 this.data = this.snapshot;
11359 delete this.snapshot;
11362 this.data.addAll(r);
11363 this.totalLength = t;
11365 this.fireEvent("datachanged", this);
11367 this.totalLength = Math.max(t, this.data.length+r.length);
11371 if(this.parent && !Roo.isIOS && !this.useNativeIOS && this.parent.emptyTitle.length) {
11373 var e = new Roo.data.Record({});
11375 e.set(this.parent.displayField, this.parent.emptyTitle);
11376 e.set(this.parent.valueField, '');
11381 this.fireEvent("load", this, r, options, o);
11382 if(options.callback){
11383 options.callback.call(options.scope || this, r, options, true);
11389 * Loads data from a passed data block. A Reader which understands the format of the data
11390 * must have been configured in the constructor.
11391 * @param {Object} data The data block from which to read the Records. The format of the data expected
11392 * is dependent on the type of Reader that is configured and should correspond to that Reader's readRecords parameter.
11393 * @param {Boolean} append (Optional) True to append the new Records rather than replace the existing cache.
11395 loadData : function(o, append){
11396 var r = this.reader.readRecords(o);
11397 this.loadRecords(r, {add: append}, true);
11401 * Gets the number of cached records.
11403 * <em>If using paging, this may not be the total size of the dataset. If the data object
11404 * used by the Reader contains the dataset size, then the getTotalCount() function returns
11405 * the data set size</em>
11407 getCount : function(){
11408 return this.data.length || 0;
11412 * Gets the total number of records in the dataset as returned by the server.
11414 * <em>If using paging, for this to be accurate, the data object used by the Reader must contain
11415 * the dataset size</em>
11417 getTotalCount : function(){
11418 return this.totalLength || 0;
11422 * Returns the sort state of the Store as an object with two properties:
11424 field {String} The name of the field by which the Records are sorted
11425 direction {String} The sort order, "ASC" or "DESC"
11428 getSortState : function(){
11429 return this.sortInfo;
11433 applySort : function(){
11434 if(this.sortInfo && !this.remoteSort){
11435 var s = this.sortInfo, f = s.field;
11436 var st = this.fields.get(f).sortType;
11437 var fn = function(r1, r2){
11438 var v1 = st(r1.data[f]), v2 = st(r2.data[f]);
11439 return v1 > v2 ? 1 : (v1 < v2 ? -1 : 0);
11441 this.data.sort(s.direction, fn);
11442 if(this.snapshot && this.snapshot != this.data){
11443 this.snapshot.sort(s.direction, fn);
11449 * Sets the default sort column and order to be used by the next load operation.
11450 * @param {String} fieldName The name of the field to sort by.
11451 * @param {String} dir (optional) The sort order, "ASC" or "DESC" (defaults to "ASC")
11453 setDefaultSort : function(field, dir){
11454 this.sortInfo = {field: field, direction: dir ? dir.toUpperCase() : "ASC"};
11458 * Sort the Records.
11459 * If remote sorting is used, the sort is performed on the server, and the cache is
11460 * reloaded. If local sorting is used, the cache is sorted internally.
11461 * @param {String} fieldName The name of the field to sort by.
11462 * @param {String} dir (optional) The sort order, "ASC" or "DESC" (defaults to "ASC")
11464 sort : function(fieldName, dir){
11465 var f = this.fields.get(fieldName);
11467 this.sortToggle[f.name] = this.sortToggle[f.name] || f.sortDir;
11469 if(this.multiSort || (this.sortInfo && this.sortInfo.field == f.name) ){ // toggle sort dir
11470 dir = (this.sortToggle[f.name] || "ASC").toggle("ASC", "DESC");
11475 this.sortToggle[f.name] = dir;
11476 this.sortInfo = {field: f.name, direction: dir};
11477 if(!this.remoteSort){
11479 this.fireEvent("datachanged", this);
11481 this.load(this.lastOptions);
11486 * Calls the specified function for each of the Records in the cache.
11487 * @param {Function} fn The function to call. The Record is passed as the first parameter.
11488 * Returning <em>false</em> aborts and exits the iteration.
11489 * @param {Object} scope (optional) The scope in which to call the function (defaults to the Record).
11491 each : function(fn, scope){
11492 this.data.each(fn, scope);
11496 * Gets all records modified since the last commit. Modified records are persisted across load operations
11497 * (e.g., during paging).
11498 * @return {Roo.data.Record[]} An array of Records containing outstanding modifications.
11500 getModifiedRecords : function(){
11501 return this.modified;
11505 createFilterFn : function(property, value, anyMatch){
11506 if(!value.exec){ // not a regex
11507 value = String(value);
11508 if(value.length == 0){
11511 value = new RegExp((anyMatch === true ? '' : '^') + Roo.escapeRe(value), "i");
11513 return function(r){
11514 return value.test(r.data[property]);
11519 * Sums the value of <i>property</i> for each record between start and end and returns the result.
11520 * @param {String} property A field on your records
11521 * @param {Number} start The record index to start at (defaults to 0)
11522 * @param {Number} end The last record index to include (defaults to length - 1)
11523 * @return {Number} The sum
11525 sum : function(property, start, end){
11526 var rs = this.data.items, v = 0;
11527 start = start || 0;
11528 end = (end || end === 0) ? end : rs.length-1;
11530 for(var i = start; i <= end; i++){
11531 v += (rs[i].data[property] || 0);
11537 * Filter the records by a specified property.
11538 * @param {String} field A field on your records
11539 * @param {String/RegExp} value Either a string that the field
11540 * should start with or a RegExp to test against the field
11541 * @param {Boolean} anyMatch True to match any part not just the beginning
11543 filter : function(property, value, anyMatch){
11544 var fn = this.createFilterFn(property, value, anyMatch);
11545 return fn ? this.filterBy(fn) : this.clearFilter();
11549 * Filter by a function. The specified function will be called with each
11550 * record in this data source. If the function returns true the record is included,
11551 * otherwise it is filtered.
11552 * @param {Function} fn The function to be called, it will receive 2 args (record, id)
11553 * @param {Object} scope (optional) The scope of the function (defaults to this)
11555 filterBy : function(fn, scope){
11556 this.snapshot = this.snapshot || this.data;
11557 this.data = this.queryBy(fn, scope||this);
11558 this.fireEvent("datachanged", this);
11562 * Query the records by a specified property.
11563 * @param {String} field A field on your records
11564 * @param {String/RegExp} value Either a string that the field
11565 * should start with or a RegExp to test against the field
11566 * @param {Boolean} anyMatch True to match any part not just the beginning
11567 * @return {MixedCollection} Returns an Roo.util.MixedCollection of the matched records
11569 query : function(property, value, anyMatch){
11570 var fn = this.createFilterFn(property, value, anyMatch);
11571 return fn ? this.queryBy(fn) : this.data.clone();
11575 * Query by a function. The specified function will be called with each
11576 * record in this data source. If the function returns true the record is included
11578 * @param {Function} fn The function to be called, it will receive 2 args (record, id)
11579 * @param {Object} scope (optional) The scope of the function (defaults to this)
11580 @return {MixedCollection} Returns an Roo.util.MixedCollection of the matched records
11582 queryBy : function(fn, scope){
11583 var data = this.snapshot || this.data;
11584 return data.filterBy(fn, scope||this);
11588 * Collects unique values for a particular dataIndex from this store.
11589 * @param {String} dataIndex The property to collect
11590 * @param {Boolean} allowNull (optional) Pass true to allow null, undefined or empty string values
11591 * @param {Boolean} bypassFilter (optional) Pass true to collect from all records, even ones which are filtered
11592 * @return {Array} An array of the unique values
11594 collect : function(dataIndex, allowNull, bypassFilter){
11595 var d = (bypassFilter === true && this.snapshot) ?
11596 this.snapshot.items : this.data.items;
11597 var v, sv, r = [], l = {};
11598 for(var i = 0, len = d.length; i < len; i++){
11599 v = d[i].data[dataIndex];
11601 if((allowNull || !Roo.isEmpty(v)) && !l[sv]){
11610 * Revert to a view of the Record cache with no filtering applied.
11611 * @param {Boolean} suppressEvent If true the filter is cleared silently without notifying listeners
11613 clearFilter : function(suppressEvent){
11614 if(this.snapshot && this.snapshot != this.data){
11615 this.data = this.snapshot;
11616 delete this.snapshot;
11617 if(suppressEvent !== true){
11618 this.fireEvent("datachanged", this);
11624 afterEdit : function(record){
11625 if(this.modified.indexOf(record) == -1){
11626 this.modified.push(record);
11628 this.fireEvent("update", this, record, Roo.data.Record.EDIT);
11632 afterReject : function(record){
11633 this.modified.remove(record);
11634 this.fireEvent("update", this, record, Roo.data.Record.REJECT);
11638 afterCommit : function(record){
11639 this.modified.remove(record);
11640 this.fireEvent("update", this, record, Roo.data.Record.COMMIT);
11644 * Commit all Records with outstanding changes. To handle updates for changes, subscribe to the
11645 * Store's "update" event, and perform updating when the third parameter is Roo.data.Record.COMMIT.
11647 commitChanges : function(){
11648 var m = this.modified.slice(0);
11649 this.modified = [];
11650 for(var i = 0, len = m.length; i < len; i++){
11656 * Cancel outstanding changes on all changed records.
11658 rejectChanges : function(){
11659 var m = this.modified.slice(0);
11660 this.modified = [];
11661 for(var i = 0, len = m.length; i < len; i++){
11666 onMetaChange : function(meta, rtype, o){
11667 this.recordType = rtype;
11668 this.fields = rtype.prototype.fields;
11669 delete this.snapshot;
11670 this.sortInfo = meta.sortInfo || this.sortInfo;
11671 this.modified = [];
11672 this.fireEvent('metachange', this, this.reader.meta);
11675 moveIndex : function(data, type)
11677 var index = this.indexOf(data);
11679 var newIndex = index + type;
11683 this.insert(newIndex, data);
11688 * Ext JS Library 1.1.1
11689 * Copyright(c) 2006-2007, Ext JS, LLC.
11691 * Originally Released Under LGPL - original licence link has changed is not relivant.
11694 * <script type="text/javascript">
11698 * @class Roo.data.SimpleStore
11699 * @extends Roo.data.Store
11700 * Small helper class to make creating Stores from Array data easier.
11701 * @cfg {Number} id The array index of the record id. Leave blank to auto generate ids.
11702 * @cfg {Array} fields An array of field definition objects, or field name strings.
11703 * @cfg {Array} data The multi-dimensional array of data
11705 * @param {Object} config
11707 Roo.data.SimpleStore = function(config){
11708 Roo.data.SimpleStore.superclass.constructor.call(this, {
11710 reader: new Roo.data.ArrayReader({
11713 Roo.data.Record.create(config.fields)
11715 proxy : new Roo.data.MemoryProxy(config.data)
11719 Roo.extend(Roo.data.SimpleStore, Roo.data.Store);/*
11721 * Ext JS Library 1.1.1
11722 * Copyright(c) 2006-2007, Ext JS, LLC.
11724 * Originally Released Under LGPL - original licence link has changed is not relivant.
11727 * <script type="text/javascript">
11732 * @extends Roo.data.Store
11733 * @class Roo.data.JsonStore
11734 * Small helper class to make creating Stores for JSON data easier. <br/>
11736 var store = new Roo.data.JsonStore({
11737 url: 'get-images.php',
11739 fields: ['name', 'url', {name:'size', type: 'float'}, {name:'lastmod', type:'date'}]
11742 * <b>Note: Although they are not listed, this class inherits all of the config options of Store,
11743 * JsonReader and HttpProxy (unless inline data is provided).</b>
11744 * @cfg {Array} fields An array of field definition objects, or field name strings.
11746 * @param {Object} config
11748 Roo.data.JsonStore = function(c){
11749 Roo.data.JsonStore.superclass.constructor.call(this, Roo.apply(c, {
11750 proxy: !c.data ? new Roo.data.HttpProxy({url: c.url}) : undefined,
11751 reader: new Roo.data.JsonReader(c, c.fields)
11754 Roo.extend(Roo.data.JsonStore, Roo.data.Store);/*
11756 * Ext JS Library 1.1.1
11757 * Copyright(c) 2006-2007, Ext JS, LLC.
11759 * Originally Released Under LGPL - original licence link has changed is not relivant.
11762 * <script type="text/javascript">
11766 Roo.data.Field = function(config){
11767 if(typeof config == "string"){
11768 config = {name: config};
11770 Roo.apply(this, config);
11773 this.type = "auto";
11776 var st = Roo.data.SortTypes;
11777 // named sortTypes are supported, here we look them up
11778 if(typeof this.sortType == "string"){
11779 this.sortType = st[this.sortType];
11782 // set default sortType for strings and dates
11783 if(!this.sortType){
11786 this.sortType = st.asUCString;
11789 this.sortType = st.asDate;
11792 this.sortType = st.none;
11797 var stripRe = /[\$,%]/g;
11799 // prebuilt conversion function for this field, instead of
11800 // switching every time we're reading a value
11802 var cv, dateFormat = this.dateFormat;
11807 cv = function(v){ return v; };
11810 cv = function(v){ return (v === undefined || v === null) ? '' : String(v); };
11814 return v !== undefined && v !== null && v !== '' ?
11815 parseInt(String(v).replace(stripRe, ""), 10) : '';
11820 return v !== undefined && v !== null && v !== '' ?
11821 parseFloat(String(v).replace(stripRe, ""), 10) : '';
11826 cv = function(v){ return v === true || v === "true" || v == 1; };
11833 if(v instanceof Date){
11837 if(dateFormat == "timestamp"){
11838 return new Date(v*1000);
11840 return Date.parseDate(v, dateFormat);
11842 var parsed = Date.parse(v);
11843 return parsed ? new Date(parsed) : null;
11852 Roo.data.Field.prototype = {
11860 * Ext JS Library 1.1.1
11861 * Copyright(c) 2006-2007, Ext JS, LLC.
11863 * Originally Released Under LGPL - original licence link has changed is not relivant.
11866 * <script type="text/javascript">
11869 // Base class for reading structured data from a data source. This class is intended to be
11870 // extended (see ArrayReader, JsonReader and XmlReader) and should not be created directly.
11873 * @class Roo.data.DataReader
11874 * Base class for reading structured data from a data source. This class is intended to be
11875 * extended (see {Roo.data.ArrayReader}, {Roo.data.JsonReader} and {Roo.data.XmlReader}) and should not be created directly.
11878 Roo.data.DataReader = function(meta, recordType){
11882 this.recordType = recordType instanceof Array ?
11883 Roo.data.Record.create(recordType) : recordType;
11886 Roo.data.DataReader.prototype = {
11888 * Create an empty record
11889 * @param {Object} data (optional) - overlay some values
11890 * @return {Roo.data.Record} record created.
11892 newRow : function(d) {
11894 this.recordType.prototype.fields.each(function(c) {
11896 case 'int' : da[c.name] = 0; break;
11897 case 'date' : da[c.name] = new Date(); break;
11898 case 'float' : da[c.name] = 0.0; break;
11899 case 'boolean' : da[c.name] = false; break;
11900 default : da[c.name] = ""; break;
11904 return new this.recordType(Roo.apply(da, d));
11909 * Ext JS Library 1.1.1
11910 * Copyright(c) 2006-2007, Ext JS, LLC.
11912 * Originally Released Under LGPL - original licence link has changed is not relivant.
11915 * <script type="text/javascript">
11919 * @class Roo.data.DataProxy
11920 * @extends Roo.data.Observable
11921 * This class is an abstract base class for implementations which provide retrieval of
11922 * unformatted data objects.<br>
11924 * DataProxy implementations are usually used in conjunction with an implementation of Roo.data.DataReader
11925 * (of the appropriate type which knows how to parse the data object) to provide a block of
11926 * {@link Roo.data.Records} to an {@link Roo.data.Store}.<br>
11928 * Custom implementations must implement the load method as described in
11929 * {@link Roo.data.HttpProxy#load}.
11931 Roo.data.DataProxy = function(){
11934 * @event beforeload
11935 * Fires before a network request is made to retrieve a data object.
11936 * @param {Object} This DataProxy object.
11937 * @param {Object} params The params parameter to the load function.
11942 * Fires before the load method's callback is called.
11943 * @param {Object} This DataProxy object.
11944 * @param {Object} o The data object.
11945 * @param {Object} arg The callback argument object passed to the load function.
11949 * @event loadexception
11950 * Fires if an Exception occurs during data retrieval.
11951 * @param {Object} This DataProxy object.
11952 * @param {Object} o The data object.
11953 * @param {Object} arg The callback argument object passed to the load function.
11954 * @param {Object} e The Exception.
11956 loadexception : true
11958 Roo.data.DataProxy.superclass.constructor.call(this);
11961 Roo.extend(Roo.data.DataProxy, Roo.util.Observable);
11964 * @cfg {void} listeners (Not available) Constructor blocks listeners from being set
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 * @class Roo.data.MemoryProxy
11978 * An implementation of Roo.data.DataProxy that simply passes the data specified in its constructor
11979 * to the Reader when its load method is called.
11981 * @param {Object} data The data object which the Reader uses to construct a block of Roo.data.Records.
11983 Roo.data.MemoryProxy = function(data){
11987 Roo.data.MemoryProxy.superclass.constructor.call(this);
11991 Roo.extend(Roo.data.MemoryProxy, Roo.data.DataProxy, {
11994 * Load data from the requested source (in this case an in-memory
11995 * data object passed to the constructor), read the data object into
11996 * a block of Roo.data.Records using the passed Roo.data.DataReader implementation, and
11997 * process that block using the passed callback.
11998 * @param {Object} params This parameter is not used by the MemoryProxy class.
11999 * @param {Roo.data.DataReader} reader The Reader object which converts the data
12000 * object into a block of Roo.data.Records.
12001 * @param {Function} callback The function into which to pass the block of Roo.data.records.
12002 * The function must be passed <ul>
12003 * <li>The Record block object</li>
12004 * <li>The "arg" argument from the load function</li>
12005 * <li>A boolean success indicator</li>
12007 * @param {Object} scope The scope in which to call the callback
12008 * @param {Object} arg An optional argument which is passed to the callback as its second parameter.
12010 load : function(params, reader, callback, scope, arg){
12011 params = params || {};
12014 result = reader.readRecords(this.data);
12016 this.fireEvent("loadexception", this, arg, null, e);
12017 callback.call(scope, null, arg, false);
12020 callback.call(scope, result, arg, true);
12024 update : function(params, records){
12029 * Ext JS Library 1.1.1
12030 * Copyright(c) 2006-2007, Ext JS, LLC.
12032 * Originally Released Under LGPL - original licence link has changed is not relivant.
12035 * <script type="text/javascript">
12038 * @class Roo.data.HttpProxy
12039 * @extends Roo.data.DataProxy
12040 * An implementation of {@link Roo.data.DataProxy} that reads a data object from an {@link Roo.data.Connection} object
12041 * configured to reference a certain URL.<br><br>
12043 * <em>Note that this class cannot be used to retrieve data from a domain other than the domain
12044 * from which the running page was served.<br><br>
12046 * For cross-domain access to remote data, use an {@link Roo.data.ScriptTagProxy}.</em><br><br>
12048 * Be aware that to enable the browser to parse an XML document, the server must set
12049 * the Content-Type header in the HTTP response to "text/xml".
12051 * @param {Object} conn Connection config options to add to each request (e.g. {url: 'foo.php'} or
12052 * an {@link Roo.data.Connection} object. If a Connection config is passed, the singleton {@link Roo.Ajax} object
12053 * will be used to make the request.
12055 Roo.data.HttpProxy = function(conn){
12056 Roo.data.HttpProxy.superclass.constructor.call(this);
12057 // is conn a conn config or a real conn?
12059 this.useAjax = !conn || !conn.events;
12063 Roo.extend(Roo.data.HttpProxy, Roo.data.DataProxy, {
12064 // thse are take from connection...
12067 * @cfg {String} url (Optional) The default URL to be used for requests to the server. (defaults to undefined)
12070 * @cfg {Object} extraParams (Optional) An object containing properties which are used as
12071 * extra parameters to each request made by this object. (defaults to undefined)
12074 * @cfg {Object} defaultHeaders (Optional) An object containing request headers which are added
12075 * to each request made by this object. (defaults to undefined)
12078 * @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)
12081 * @cfg {Number} timeout (Optional) The timeout in milliseconds to be used for requests. (defaults to 30000)
12084 * @cfg {Boolean} autoAbort (Optional) Whether this request should abort any pending requests. (defaults to false)
12090 * @cfg {Boolean} disableCaching (Optional) True to add a unique cache-buster param to GET requests. (defaults to true)
12094 * Return the {@link Roo.data.Connection} object being used by this Proxy.
12095 * @return {Connection} The Connection object. This object may be used to subscribe to events on
12096 * a finer-grained basis than the DataProxy events.
12098 getConnection : function(){
12099 return this.useAjax ? Roo.Ajax : this.conn;
12103 * Load data from the configured {@link Roo.data.Connection}, read the data object into
12104 * a block of Roo.data.Records using the passed {@link Roo.data.DataReader} implementation, and
12105 * process that block using the passed callback.
12106 * @param {Object} params An object containing properties which are to be used as HTTP parameters
12107 * for the request to the remote server.
12108 * @param {Roo.data.DataReader} reader The Reader object which converts the data
12109 * object into a block of Roo.data.Records.
12110 * @param {Function} callback The function into which to pass the block of Roo.data.Records.
12111 * The function must be passed <ul>
12112 * <li>The Record block object</li>
12113 * <li>The "arg" argument from the load function</li>
12114 * <li>A boolean success indicator</li>
12116 * @param {Object} scope The scope in which to call the callback
12117 * @param {Object} arg An optional argument which is passed to the callback as its second parameter.
12119 load : function(params, reader, callback, scope, arg){
12120 if(this.fireEvent("beforeload", this, params) !== false){
12122 params : params || {},
12124 callback : callback,
12129 callback : this.loadResponse,
12133 Roo.applyIf(o, this.conn);
12134 if(this.activeRequest){
12135 Roo.Ajax.abort(this.activeRequest);
12137 this.activeRequest = Roo.Ajax.request(o);
12139 this.conn.request(o);
12142 callback.call(scope||this, null, arg, false);
12147 loadResponse : function(o, success, response){
12148 delete this.activeRequest;
12150 this.fireEvent("loadexception", this, o, response);
12151 o.request.callback.call(o.request.scope, null, o.request.arg, false);
12156 result = o.reader.read(response);
12158 this.fireEvent("loadexception", this, o, response, e);
12159 o.request.callback.call(o.request.scope, null, o.request.arg, false);
12163 this.fireEvent("load", this, o, o.request.arg);
12164 o.request.callback.call(o.request.scope, result, o.request.arg, true);
12168 update : function(dataSet){
12173 updateResponse : function(dataSet){
12178 * Ext JS Library 1.1.1
12179 * Copyright(c) 2006-2007, Ext JS, LLC.
12181 * Originally Released Under LGPL - original licence link has changed is not relivant.
12184 * <script type="text/javascript">
12188 * @class Roo.data.ScriptTagProxy
12189 * An implementation of Roo.data.DataProxy that reads a data object from a URL which may be in a domain
12190 * other than the originating domain of the running page.<br><br>
12192 * <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
12193 * of the running page, you must use this class, rather than DataProxy.</em><br><br>
12195 * The content passed back from a server resource requested by a ScriptTagProxy is executable JavaScript
12196 * source code that is used as the source inside a <script> tag.<br><br>
12198 * In order for the browser to process the returned data, the server must wrap the data object
12199 * with a call to a callback function, the name of which is passed as a parameter by the ScriptTagProxy.
12200 * Below is a Java example for a servlet which returns data for either a ScriptTagProxy, or an HttpProxy
12201 * depending on whether the callback name was passed:
12204 boolean scriptTag = false;
12205 String cb = request.getParameter("callback");
12208 response.setContentType("text/javascript");
12210 response.setContentType("application/x-json");
12212 Writer out = response.getWriter();
12214 out.write(cb + "(");
12216 out.print(dataBlock.toJsonString());
12223 * @param {Object} config A configuration object.
12225 Roo.data.ScriptTagProxy = function(config){
12226 Roo.data.ScriptTagProxy.superclass.constructor.call(this);
12227 Roo.apply(this, config);
12228 this.head = document.getElementsByTagName("head")[0];
12231 Roo.data.ScriptTagProxy.TRANS_ID = 1000;
12233 Roo.extend(Roo.data.ScriptTagProxy, Roo.data.DataProxy, {
12235 * @cfg {String} url The URL from which to request the data object.
12238 * @cfg {Number} timeout (Optional) The number of milliseconds to wait for a response. Defaults to 30 seconds.
12242 * @cfg {String} callbackParam (Optional) The name of the parameter to pass to the server which tells
12243 * the server the name of the callback function set up by the load call to process the returned data object.
12244 * Defaults to "callback".<p>The server-side processing must read this parameter value, and generate
12245 * javascript output which calls this named function passing the data object as its only parameter.
12247 callbackParam : "callback",
12249 * @cfg {Boolean} nocache (Optional) Defaults to true. Disable cacheing by adding a unique parameter
12250 * name to the request.
12255 * Load data from the configured URL, read the data object into
12256 * a block of Roo.data.Records using the passed Roo.data.DataReader implementation, and
12257 * process that block using the passed callback.
12258 * @param {Object} params An object containing properties which are to be used as HTTP parameters
12259 * for the request to the remote server.
12260 * @param {Roo.data.DataReader} reader The Reader object which converts the data
12261 * object into a block of Roo.data.Records.
12262 * @param {Function} callback The function into which to pass the block of Roo.data.Records.
12263 * The function must be passed <ul>
12264 * <li>The Record block object</li>
12265 * <li>The "arg" argument from the load function</li>
12266 * <li>A boolean success indicator</li>
12268 * @param {Object} scope The scope in which to call the callback
12269 * @param {Object} arg An optional argument which is passed to the callback as its second parameter.
12271 load : function(params, reader, callback, scope, arg){
12272 if(this.fireEvent("beforeload", this, params) !== false){
12274 var p = Roo.urlEncode(Roo.apply(params, this.extraParams));
12276 var url = this.url;
12277 url += (url.indexOf("?") != -1 ? "&" : "?") + p;
12279 url += "&_dc=" + (new Date().getTime());
12281 var transId = ++Roo.data.ScriptTagProxy.TRANS_ID;
12284 cb : "stcCallback"+transId,
12285 scriptId : "stcScript"+transId,
12289 callback : callback,
12295 window[trans.cb] = function(o){
12296 conn.handleResponse(o, trans);
12299 url += String.format("&{0}={1}", this.callbackParam, trans.cb);
12301 if(this.autoAbort !== false){
12305 trans.timeoutId = this.handleFailure.defer(this.timeout, this, [trans]);
12307 var script = document.createElement("script");
12308 script.setAttribute("src", url);
12309 script.setAttribute("type", "text/javascript");
12310 script.setAttribute("id", trans.scriptId);
12311 this.head.appendChild(script);
12313 this.trans = trans;
12315 callback.call(scope||this, null, arg, false);
12320 isLoading : function(){
12321 return this.trans ? true : false;
12325 * Abort the current server request.
12327 abort : function(){
12328 if(this.isLoading()){
12329 this.destroyTrans(this.trans);
12334 destroyTrans : function(trans, isLoaded){
12335 this.head.removeChild(document.getElementById(trans.scriptId));
12336 clearTimeout(trans.timeoutId);
12338 window[trans.cb] = undefined;
12340 delete window[trans.cb];
12343 // if hasn't been loaded, wait for load to remove it to prevent script error
12344 window[trans.cb] = function(){
12345 window[trans.cb] = undefined;
12347 delete window[trans.cb];
12354 handleResponse : function(o, trans){
12355 this.trans = false;
12356 this.destroyTrans(trans, true);
12359 result = trans.reader.readRecords(o);
12361 this.fireEvent("loadexception", this, o, trans.arg, e);
12362 trans.callback.call(trans.scope||window, null, trans.arg, false);
12365 this.fireEvent("load", this, o, trans.arg);
12366 trans.callback.call(trans.scope||window, result, trans.arg, true);
12370 handleFailure : function(trans){
12371 this.trans = false;
12372 this.destroyTrans(trans, false);
12373 this.fireEvent("loadexception", this, null, trans.arg);
12374 trans.callback.call(trans.scope||window, null, trans.arg, false);
12378 * Ext JS Library 1.1.1
12379 * Copyright(c) 2006-2007, Ext JS, LLC.
12381 * Originally Released Under LGPL - original licence link has changed is not relivant.
12384 * <script type="text/javascript">
12388 * @class Roo.data.JsonReader
12389 * @extends Roo.data.DataReader
12390 * Data reader class to create an Array of Roo.data.Record objects from a JSON response
12391 * based on mappings in a provided Roo.data.Record constructor.
12393 * The default behaviour of a store is to send ?_requestMeta=1, unless the class has recieved 'metaData' property
12394 * in the reply previously.
12399 var RecordDef = Roo.data.Record.create([
12400 {name: 'name', mapping: 'name'}, // "mapping" property not needed if it's the same as "name"
12401 {name: 'occupation'} // This field will use "occupation" as the mapping.
12403 var myReader = new Roo.data.JsonReader({
12404 totalProperty: "results", // The property which contains the total dataset size (optional)
12405 root: "rows", // The property which contains an Array of row objects
12406 id: "id" // The property within each row object that provides an ID for the record (optional)
12410 * This would consume a JSON file like this:
12412 { 'results': 2, 'rows': [
12413 { 'id': 1, 'name': 'Bill', occupation: 'Gardener' },
12414 { 'id': 2, 'name': 'Ben', occupation: 'Horticulturalist' } ]
12417 * @cfg {String} totalProperty Name of the property from which to retrieve the total number of records
12418 * in the dataset. This is only needed if the whole dataset is not passed in one go, but is being
12419 * paged from the remote server.
12420 * @cfg {String} successProperty Name of the property from which to retrieve the success attribute used by forms.
12421 * @cfg {String} root name of the property which contains the Array of row objects.
12422 * @cfg {String} id Name of the property within a row object that contains a record identifier value.
12423 * @cfg {Array} fields Array of field definition objects
12425 * Create a new JsonReader
12426 * @param {Object} meta Metadata configuration options
12427 * @param {Object} recordType Either an Array of field definition objects,
12428 * or an {@link Roo.data.Record} object created using {@link Roo.data.Record#create}.
12430 Roo.data.JsonReader = function(meta, recordType){
12433 // set some defaults:
12434 Roo.applyIf(meta, {
12435 totalProperty: 'total',
12436 successProperty : 'success',
12441 Roo.data.JsonReader.superclass.constructor.call(this, meta, recordType||meta.fields);
12443 Roo.extend(Roo.data.JsonReader, Roo.data.DataReader, {
12446 * @prop {Boolean} metaFromRemote - if the meta data was loaded from the remote source.
12447 * Used by Store query builder to append _requestMeta to params.
12450 metaFromRemote : false,
12452 * This method is only used by a DataProxy which has retrieved data from a remote server.
12453 * @param {Object} response The XHR object which contains the JSON data in its responseText.
12454 * @return {Object} data A data block which is used by an Roo.data.Store object as
12455 * a cache of Roo.data.Records.
12457 read : function(response){
12458 var json = response.responseText;
12460 var o = /* eval:var:o */ eval("("+json+")");
12462 throw {message: "JsonReader.read: Json object not found"};
12468 this.metaFromRemote = true;
12469 this.meta = o.metaData;
12470 this.recordType = Roo.data.Record.create(o.metaData.fields);
12471 this.onMetaChange(this.meta, this.recordType, o);
12473 return this.readRecords(o);
12476 // private function a store will implement
12477 onMetaChange : function(meta, recordType, o){
12484 simpleAccess: function(obj, subsc) {
12491 getJsonAccessor: function(){
12493 return function(expr) {
12495 return(re.test(expr))
12496 ? new Function("obj", "return obj." + expr)
12501 return Roo.emptyFn;
12506 * Create a data block containing Roo.data.Records from an XML document.
12507 * @param {Object} o An object which contains an Array of row objects in the property specified
12508 * in the config as 'root, and optionally a property, specified in the config as 'totalProperty'
12509 * which contains the total size of the dataset.
12510 * @return {Object} data A data block which is used by an Roo.data.Store object as
12511 * a cache of Roo.data.Records.
12513 readRecords : function(o){
12515 * After any data loads, the raw JSON data is available for further custom processing.
12519 var s = this.meta, Record = this.recordType,
12520 f = Record ? Record.prototype.fields : null, fi = f ? f.items : [], fl = f ? f.length : 0;
12522 // Generate extraction functions for the totalProperty, the root, the id, and for each field
12524 if(s.totalProperty) {
12525 this.getTotal = this.getJsonAccessor(s.totalProperty);
12527 if(s.successProperty) {
12528 this.getSuccess = this.getJsonAccessor(s.successProperty);
12530 this.getRoot = s.root ? this.getJsonAccessor(s.root) : function(p){return p;};
12532 var g = this.getJsonAccessor(s.id);
12533 this.getId = function(rec) {
12535 return (r === undefined || r === "") ? null : r;
12538 this.getId = function(){return null;};
12541 for(var jj = 0; jj < fl; jj++){
12543 var map = (f.mapping !== undefined && f.mapping !== null) ? f.mapping : f.name;
12544 this.ef[jj] = this.getJsonAccessor(map);
12548 var root = this.getRoot(o), c = root.length, totalRecords = c, success = true;
12549 if(s.totalProperty){
12550 var vt = parseInt(this.getTotal(o), 10);
12555 if(s.successProperty){
12556 var vs = this.getSuccess(o);
12557 if(vs === false || vs === 'false'){
12562 for(var i = 0; i < c; i++){
12565 var id = this.getId(n);
12566 for(var j = 0; j < fl; j++){
12568 var v = this.ef[j](n);
12570 Roo.log('missing convert for ' + f.name);
12574 values[f.name] = f.convert((v !== undefined) ? v : f.defaultValue);
12576 var record = new Record(values, id);
12578 records[i] = record;
12584 totalRecords : totalRecords
12589 * Ext JS Library 1.1.1
12590 * Copyright(c) 2006-2007, Ext JS, LLC.
12592 * Originally Released Under LGPL - original licence link has changed is not relivant.
12595 * <script type="text/javascript">
12599 * @class Roo.data.ArrayReader
12600 * @extends Roo.data.DataReader
12601 * Data reader class to create an Array of Roo.data.Record objects from an Array.
12602 * Each element of that Array represents a row of data fields. The
12603 * fields are pulled into a Record object using as a subscript, the <em>mapping</em> property
12604 * of the field definition if it exists, or the field's ordinal position in the definition.<br>
12608 var RecordDef = Roo.data.Record.create([
12609 {name: 'name', mapping: 1}, // "mapping" only needed if an "id" field is present which
12610 {name: 'occupation', mapping: 2} // precludes using the ordinal position as the index.
12612 var myReader = new Roo.data.ArrayReader({
12613 id: 0 // The subscript within row Array that provides an ID for the Record (optional)
12617 * This would consume an Array like this:
12619 [ [1, 'Bill', 'Gardener'], [2, 'Ben', 'Horticulturalist'] ]
12621 * @cfg {String} id (optional) The subscript within row Array that provides an ID for the Record
12623 * Create a new JsonReader
12624 * @param {Object} meta Metadata configuration options.
12625 * @param {Object} recordType Either an Array of field definition objects
12626 * as specified to {@link Roo.data.Record#create},
12627 * or an {@link Roo.data.Record} object
12628 * created using {@link Roo.data.Record#create}.
12630 Roo.data.ArrayReader = function(meta, recordType){
12631 Roo.data.ArrayReader.superclass.constructor.call(this, meta, recordType);
12634 Roo.extend(Roo.data.ArrayReader, Roo.data.JsonReader, {
12636 * Create a data block containing Roo.data.Records from an XML document.
12637 * @param {Object} o An Array of row objects which represents the dataset.
12638 * @return {Object} data A data block which is used by an Roo.data.Store object as
12639 * a cache of Roo.data.Records.
12641 readRecords : function(o){
12642 var sid = this.meta ? this.meta.id : null;
12643 var recordType = this.recordType, fields = recordType.prototype.fields;
12646 for(var i = 0; i < root.length; i++){
12649 var id = ((sid || sid === 0) && n[sid] !== undefined && n[sid] !== "" ? n[sid] : null);
12650 for(var j = 0, jlen = fields.length; j < jlen; j++){
12651 var f = fields.items[j];
12652 var k = f.mapping !== undefined && f.mapping !== null ? f.mapping : j;
12653 var v = n[k] !== undefined ? n[k] : f.defaultValue;
12655 values[f.name] = v;
12657 var record = new recordType(values, id);
12659 records[records.length] = record;
12663 totalRecords : records.length
12672 * @class Roo.bootstrap.ComboBox
12673 * @extends Roo.bootstrap.TriggerField
12674 * A combobox control with support for autocomplete, remote-loading, paging and many other features.
12675 * @cfg {Boolean} append (true|false) default false
12676 * @cfg {Boolean} autoFocus (true|false) auto focus the first item, default true
12677 * @cfg {Boolean} tickable ComboBox with tickable selections (true|false), default false
12678 * @cfg {Boolean} triggerList trigger show the list or not (true|false) default true
12679 * @cfg {Boolean} showToggleBtn show toggle button or not (true|false) default true
12680 * @cfg {String} btnPosition set the position of the trigger button (left | right) default right
12681 * @cfg {Boolean} animate default true
12682 * @cfg {Boolean} emptyResultText only for touch device
12683 * @cfg {String} triggerText multiple combobox trigger button text default 'Select'
12684 * @cfg {String} emptyTitle default ''
12686 * Create a new ComboBox.
12687 * @param {Object} config Configuration options
12689 Roo.bootstrap.ComboBox = function(config){
12690 Roo.bootstrap.ComboBox.superclass.constructor.call(this, config);
12694 * Fires when the dropdown list is expanded
12695 * @param {Roo.bootstrap.ComboBox} combo This combo box
12700 * Fires when the dropdown list is collapsed
12701 * @param {Roo.bootstrap.ComboBox} combo This combo box
12705 * @event beforeselect
12706 * Fires before a list item is selected. Return false to cancel the selection.
12707 * @param {Roo.bootstrap.ComboBox} combo This combo box
12708 * @param {Roo.data.Record} record The data record returned from the underlying store
12709 * @param {Number} index The index of the selected item in the dropdown list
12711 'beforeselect' : true,
12714 * Fires when a list item is selected
12715 * @param {Roo.bootstrap.ComboBox} combo This combo box
12716 * @param {Roo.data.Record} record The data record returned from the underlying store (or false on clear)
12717 * @param {Number} index The index of the selected item in the dropdown list
12721 * @event beforequery
12722 * Fires before all queries are processed. Return false to cancel the query or set cancel to true.
12723 * The event object passed has these properties:
12724 * @param {Roo.bootstrap.ComboBox} combo This combo box
12725 * @param {String} query The query
12726 * @param {Boolean} forceAll true to force "all" query
12727 * @param {Boolean} cancel true to cancel the query
12728 * @param {Object} e The query event object
12730 'beforequery': true,
12733 * Fires when the 'add' icon is pressed (add a listener to enable add button)
12734 * @param {Roo.bootstrap.ComboBox} combo This combo box
12739 * Fires when the 'edit' icon is pressed (add a listener to enable add button)
12740 * @param {Roo.bootstrap.ComboBox} combo This combo box
12741 * @param {Roo.data.Record|false} record The data record returned from the underlying store (or false on nothing selected)
12746 * Fires when the remove value from the combobox array
12747 * @param {Roo.bootstrap.ComboBox} combo This combo box
12751 * @event afterremove
12752 * Fires when the remove value from the combobox array
12753 * @param {Roo.bootstrap.ComboBox} combo This combo box
12755 'afterremove' : true,
12757 * @event specialfilter
12758 * Fires when specialfilter
12759 * @param {Roo.bootstrap.ComboBox} combo This combo box
12761 'specialfilter' : true,
12764 * Fires when tick the element
12765 * @param {Roo.bootstrap.ComboBox} combo This combo box
12769 * @event touchviewdisplay
12770 * Fires when touch view require special display (default is using displayField)
12771 * @param {Roo.bootstrap.ComboBox} combo This combo box
12772 * @param {Object} cfg set html .
12774 'touchviewdisplay' : true
12779 this.tickItems = [];
12781 this.selectedIndex = -1;
12782 if(this.mode == 'local'){
12783 if(config.queryDelay === undefined){
12784 this.queryDelay = 10;
12786 if(config.minChars === undefined){
12792 Roo.extend(Roo.bootstrap.ComboBox, Roo.bootstrap.TriggerField, {
12795 * @cfg {Boolean} lazyRender True to prevent the ComboBox from rendering until requested (should always be used when
12796 * rendering into an Roo.Editor, defaults to false)
12799 * @cfg {Boolean/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to:
12800 * {tag: "input", type: "text", size: "24", autocomplete: "off"})
12803 * @cfg {Roo.data.Store} store The data store to which this combo is bound (defaults to undefined)
12806 * @cfg {String} title If supplied, a header element is created containing this text and added into the top of
12807 * the dropdown list (defaults to undefined, with no header element)
12811 * @cfg {String/Roo.Template} tpl The template to use to render the output
12815 * @cfg {Number} listWidth The width in pixels of the dropdown list (defaults to the width of the ComboBox field)
12817 listWidth: undefined,
12819 * @cfg {String} displayField The underlying data field name to bind to this CombBox (defaults to undefined if
12820 * mode = 'remote' or 'text' if mode = 'local')
12822 displayField: undefined,
12825 * @cfg {String} valueField The underlying data value name to bind to this CombBox (defaults to undefined if
12826 * mode = 'remote' or 'value' if mode = 'local').
12827 * Note: use of a valueField requires the user make a selection
12828 * in order for a value to be mapped.
12830 valueField: undefined,
12832 * @cfg {String} modalTitle The title of the dialog that pops up on mobile views.
12837 * @cfg {String} hiddenName If specified, a hidden form field with this name is dynamically generated to store the
12838 * field's data value (defaults to the underlying DOM element's name)
12840 hiddenName: undefined,
12842 * @cfg {String} listClass CSS class to apply to the dropdown list element (defaults to '')
12846 * @cfg {String} selectedClass CSS class to apply to the selected item in the dropdown list (defaults to 'x-combo-selected')
12848 selectedClass: 'active',
12851 * @cfg {Boolean/String} shadow True or "sides" for the default effect, "frame" for 4-way shadow, and "drop" for bottom-right
12855 * @cfg {String} listAlign A valid anchor position value. See {@link Roo.Element#alignTo} for details on supported
12856 * anchor positions (defaults to 'tl-bl')
12858 listAlign: 'tl-bl?',
12860 * @cfg {Number} maxHeight The maximum height in pixels of the dropdown list before scrollbars are shown (defaults to 300)
12864 * @cfg {String} triggerAction The action to execute when the trigger field is activated. Use 'all' to run the
12865 * query specified by the allQuery config option (defaults to 'query')
12867 triggerAction: 'query',
12869 * @cfg {Number} minChars The minimum number of characters the user must type before autocomplete and typeahead activate
12870 * (defaults to 4, does not apply if editable = false)
12874 * @cfg {Boolean} typeAhead True to populate and autoselect the remainder of the text being typed after a configurable
12875 * delay (typeAheadDelay) if it matches a known value (defaults to false)
12879 * @cfg {Number} queryDelay The length of time in milliseconds to delay between the start of typing and sending the
12880 * query to filter the dropdown list (defaults to 500 if mode = 'remote' or 10 if mode = 'local')
12884 * @cfg {Number} pageSize If greater than 0, a paging toolbar is displayed in the footer of the dropdown list and the
12885 * filter queries will execute with page start and limit parameters. Only applies when mode = 'remote' (defaults to 0)
12889 * @cfg {Boolean} selectOnFocus True to select any existing text in the field immediately on focus. Only applies
12890 * when editable = true (defaults to false)
12892 selectOnFocus:false,
12894 * @cfg {String} queryParam Name of the query as it will be passed on the querystring (defaults to 'query')
12896 queryParam: 'query',
12898 * @cfg {String} loadingText The text to display in the dropdown list while data is loading. Only applies
12899 * when mode = 'remote' (defaults to 'Loading...')
12901 loadingText: 'Loading...',
12903 * @cfg {Boolean} resizable True to add a resize handle to the bottom of the dropdown list (defaults to false)
12907 * @cfg {Number} handleHeight The height in pixels of the dropdown list resize handle if resizable = true (defaults to 8)
12911 * @cfg {Boolean} editable False to prevent the user from typing text directly into the field, just like a
12912 * traditional select (defaults to true)
12916 * @cfg {String} allQuery The text query to send to the server to return all records for the list with no filtering (defaults to '')
12920 * @cfg {String} mode Set to 'local' if the ComboBox loads local data (defaults to 'remote' which loads from the server)
12924 * @cfg {Number} minListWidth The minimum width of the dropdown list in pixels (defaults to 70, will be ignored if
12925 * listWidth has a higher value)
12929 * @cfg {Boolean} forceSelection True to restrict the selected value to one of the values in the list, false to
12930 * allow the user to set arbitrary text into the field (defaults to false)
12932 forceSelection:false,
12934 * @cfg {Number} typeAheadDelay The length of time in milliseconds to wait until the typeahead text is displayed
12935 * if typeAhead = true (defaults to 250)
12937 typeAheadDelay : 250,
12939 * @cfg {String} valueNotFoundText When using a name/value combo, if the value passed to setValue is not found in
12940 * the store, valueNotFoundText will be displayed as the field text if defined (defaults to undefined)
12942 valueNotFoundText : undefined,
12944 * @cfg {Boolean} blockFocus Prevents all focus calls, so it can work with things like HTML edtor bar
12946 blockFocus : false,
12949 * @cfg {Boolean} disableClear Disable showing of clear button.
12951 disableClear : false,
12953 * @cfg {Boolean} alwaysQuery Disable caching of results, and always send query
12955 alwaysQuery : false,
12958 * @cfg {Boolean} multiple (true|false) ComboBobArray, default false
12963 * @cfg {String} invalidClass The CSS class to use when marking a field invalid (defaults to "x-form-invalid")
12965 invalidClass : "has-warning",
12968 * @cfg {String} validClass The CSS class to use when marking a field valid (defaults to "x-form-invalid")
12970 validClass : "has-success",
12973 * @cfg {Boolean} specialFilter (true|false) special filter default false
12975 specialFilter : false,
12978 * @cfg {Boolean} mobileTouchView (true|false) show mobile touch view when using a mobile default true
12980 mobileTouchView : true,
12983 * @cfg {Boolean} useNativeIOS (true|false) render it as classic select for ios, not support dynamic load data (default false)
12985 useNativeIOS : false,
12987 ios_options : false,
12999 btnPosition : 'right',
13000 triggerList : true,
13001 showToggleBtn : true,
13003 emptyResultText: 'Empty',
13004 triggerText : 'Select',
13007 // element that contains real text value.. (when hidden is used..)
13009 getAutoCreate : function()
13014 * Render classic select for iso
13017 if(Roo.isIOS && this.useNativeIOS){
13018 cfg = this.getAutoCreateNativeIOS();
13026 if(Roo.isTouch && this.mobileTouchView){
13027 cfg = this.getAutoCreateTouchView();
13034 if(!this.tickable){
13035 cfg = Roo.bootstrap.ComboBox.superclass.getAutoCreate.call(this);
13040 * ComboBox with tickable selections
13043 var align = this.labelAlign || this.parentLabelAlign();
13046 cls : 'form-group roo-combobox-tickable' //input-group
13049 var btn_text_select = '';
13050 var btn_text_done = '';
13051 var btn_text_cancel = '';
13053 if (this.btn_text_show) {
13054 btn_text_select = 'Select';
13055 btn_text_done = 'Done';
13056 btn_text_cancel = 'Cancel';
13061 cls : 'tickable-buttons',
13066 cls : 'btn btn-link btn-edit pull-' + this.btnPosition,
13067 //html : this.triggerText
13068 html: btn_text_select
13074 cls : 'btn btn-link btn-ok pull-' + this.btnPosition,
13076 html: btn_text_done
13082 cls : 'btn btn-link btn-cancel pull-' + this.btnPosition,
13084 html: btn_text_cancel
13090 buttons.cn.unshift({
13092 cls: 'roo-select2-search-field-input'
13098 Roo.each(buttons.cn, function(c){
13100 c.cls += ' btn-' + _this.size;
13103 if (_this.disabled) {
13114 cls: 'form-hidden-field'
13118 cls: 'roo-select2-choices',
13122 cls: 'roo-select2-search-field',
13133 cls: 'roo-select2-container input-group roo-select2-container-multi',
13138 // cls: 'typeahead typeahead-long dropdown-menu',
13139 // style: 'display:none; max-height:' + this.maxHeight + 'px;'
13144 if(this.hasFeedback && !this.allowBlank){
13148 cls: 'glyphicon form-control-feedback'
13151 combobox.cn.push(feedback);
13155 if (align ==='left' && this.fieldLabel.length) {
13157 cfg.cls += ' roo-form-group-label-left';
13162 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
13163 tooltip : 'This field is required'
13168 cls : 'control-label',
13169 html : this.fieldLabel
13181 var labelCfg = cfg.cn[1];
13182 var contentCfg = cfg.cn[2];
13185 if(this.indicatorpos == 'right'){
13191 cls : 'control-label',
13195 html : this.fieldLabel
13199 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
13200 tooltip : 'This field is required'
13215 labelCfg = cfg.cn[0];
13216 contentCfg = cfg.cn[1];
13220 if(this.labelWidth > 12){
13221 labelCfg.style = "width: " + this.labelWidth + 'px';
13224 if(this.labelWidth < 13 && this.labelmd == 0){
13225 this.labelmd = this.labelWidth;
13228 if(this.labellg > 0){
13229 labelCfg.cls += ' col-lg-' + this.labellg;
13230 contentCfg.cls += ' col-lg-' + (12 - this.labellg);
13233 if(this.labelmd > 0){
13234 labelCfg.cls += ' col-md-' + this.labelmd;
13235 contentCfg.cls += ' col-md-' + (12 - this.labelmd);
13238 if(this.labelsm > 0){
13239 labelCfg.cls += ' col-sm-' + this.labelsm;
13240 contentCfg.cls += ' col-sm-' + (12 - this.labelsm);
13243 if(this.labelxs > 0){
13244 labelCfg.cls += ' col-xs-' + this.labelxs;
13245 contentCfg.cls += ' col-xs-' + (12 - this.labelxs);
13249 } else if ( this.fieldLabel.length) {
13250 // Roo.log(" label");
13254 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
13255 tooltip : 'This field is required'
13259 //cls : 'input-group-addon',
13260 html : this.fieldLabel
13265 if(this.indicatorpos == 'right'){
13269 //cls : 'input-group-addon',
13270 html : this.fieldLabel
13274 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
13275 tooltip : 'This field is required'
13284 // Roo.log(" no label && no align");
13291 ['xs','sm','md','lg'].map(function(size){
13292 if (settings[size]) {
13293 cfg.cls += ' col-' + size + '-' + settings[size];
13301 _initEventsCalled : false,
13304 initEvents: function()
13306 if (this._initEventsCalled) { // as we call render... prevent looping...
13309 this._initEventsCalled = true;
13312 throw "can not find store for combo";
13315 this.indicator = this.indicatorEl();
13317 this.store = Roo.factory(this.store, Roo.data);
13318 this.store.parent = this;
13320 // if we are building from html. then this element is so complex, that we can not really
13321 // use the rendered HTML.
13322 // so we have to trash and replace the previous code.
13323 if (Roo.XComponent.build_from_html) {
13324 // remove this element....
13325 var e = this.el.dom, k=0;
13326 while (e ) { e = e.previousSibling; ++k;}
13331 this.rendered = false;
13333 this.render(this.parent().getChildContainer(true), k);
13336 if(Roo.isIOS && this.useNativeIOS){
13337 this.initIOSView();
13345 if(Roo.isTouch && this.mobileTouchView){
13346 this.initTouchView();
13351 this.initTickableEvents();
13355 Roo.bootstrap.ComboBox.superclass.initEvents.call(this);
13357 if(this.hiddenName){
13359 this.hiddenField = this.el.select('input.form-hidden-field',true).first();
13361 this.hiddenField.dom.value =
13362 this.hiddenValue !== undefined ? this.hiddenValue :
13363 this.value !== undefined ? this.value : '';
13365 // prevent input submission
13366 this.el.dom.removeAttribute('name');
13367 this.hiddenField.dom.setAttribute('name', this.hiddenName);
13372 // this.el.dom.setAttribute('autocomplete', 'off');
13375 var cls = 'x-combo-list';
13377 //this.list = new Roo.Layer({
13378 // shadow: this.shadow, cls: [cls, this.listClass].join(' '), constrain:false
13384 var lw = _this.listWidth || Math.max(_this.inputEl().getWidth(), _this.minListWidth);
13385 _this.list.setWidth(lw);
13388 this.list.on('mouseover', this.onViewOver, this);
13389 this.list.on('mousemove', this.onViewMove, this);
13390 this.list.on('scroll', this.onViewScroll, this);
13393 this.list.swallowEvent('mousewheel');
13394 this.assetHeight = 0;
13397 this.header = this.list.createChild({cls:cls+'-hd', html: this.title});
13398 this.assetHeight += this.header.getHeight();
13401 this.innerList = this.list.createChild({cls:cls+'-inner'});
13402 this.innerList.on('mouseover', this.onViewOver, this);
13403 this.innerList.on('mousemove', this.onViewMove, this);
13404 this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
13406 if(this.allowBlank && !this.pageSize && !this.disableClear){
13407 this.footer = this.list.createChild({cls:cls+'-ft'});
13408 this.pageTb = new Roo.Toolbar(this.footer);
13412 this.footer = this.list.createChild({cls:cls+'-ft'});
13413 this.pageTb = new Roo.PagingToolbar(this.footer, this.store,
13414 {pageSize: this.pageSize});
13418 if (this.pageTb && this.allowBlank && !this.disableClear) {
13420 this.pageTb.add(new Roo.Toolbar.Fill(), {
13421 cls: 'x-btn-icon x-btn-clear',
13423 handler: function()
13426 _this.clearValue();
13427 _this.onSelect(false, -1);
13432 this.assetHeight += this.footer.getHeight();
13437 this.tpl = '<li><a href="#">{' + this.displayField + '}</a></li>';
13440 this.view = new Roo.View(this.list, this.tpl, {
13441 singleSelect:true, store: this.store, selectedClass: this.selectedClass
13443 //this.view.wrapEl.setDisplayed(false);
13444 this.view.on('click', this.onViewClick, this);
13447 this.store.on('beforeload', this.onBeforeLoad, this);
13448 this.store.on('load', this.onLoad, this);
13449 this.store.on('loadexception', this.onLoadException, this);
13451 if(this.resizable){
13452 this.resizer = new Roo.Resizable(this.list, {
13453 pinned:true, handles:'se'
13455 this.resizer.on('resize', function(r, w, h){
13456 this.maxHeight = h-this.handleHeight-this.list.getFrameWidth('tb')-this.assetHeight;
13457 this.listWidth = w;
13458 this.innerList.setWidth(w - this.list.getFrameWidth('lr'));
13459 this.restrictHeight();
13461 this[this.pageSize?'footer':'innerList'].setStyle('margin-bottom', this.handleHeight+'px');
13464 if(!this.editable){
13465 this.editable = true;
13466 this.setEditable(false);
13471 if (typeof(this.events.add.listeners) != 'undefined') {
13473 this.addicon = this.wrap.createChild(
13474 {tag: 'img', src: Roo.BLANK_IMAGE_URL, cls: 'x-form-combo-add' });
13476 this.addicon.on('click', function(e) {
13477 this.fireEvent('add', this);
13480 if (typeof(this.events.edit.listeners) != 'undefined') {
13482 this.editicon = this.wrap.createChild(
13483 {tag: 'img', src: Roo.BLANK_IMAGE_URL, cls: 'x-form-combo-edit' });
13484 if (this.addicon) {
13485 this.editicon.setStyle('margin-left', '40px');
13487 this.editicon.on('click', function(e) {
13489 // we fire even if inothing is selected..
13490 this.fireEvent('edit', this, this.lastData );
13496 this.keyNav = new Roo.KeyNav(this.inputEl(), {
13497 "up" : function(e){
13498 this.inKeyMode = true;
13502 "down" : function(e){
13503 if(!this.isExpanded()){
13504 this.onTriggerClick();
13506 this.inKeyMode = true;
13511 "enter" : function(e){
13512 // this.onViewClick();
13516 if(this.fireEvent("specialkey", this, e)){
13517 this.onViewClick(false);
13523 "esc" : function(e){
13527 "tab" : function(e){
13530 if(this.fireEvent("specialkey", this, e)){
13531 this.onViewClick(false);
13539 doRelay : function(foo, bar, hname){
13540 if(hname == 'down' || this.scope.isExpanded()){
13541 return Roo.KeyNav.prototype.doRelay.apply(this, arguments);
13550 this.queryDelay = Math.max(this.queryDelay || 10,
13551 this.mode == 'local' ? 10 : 250);
13554 this.dqTask = new Roo.util.DelayedTask(this.initQuery, this);
13556 if(this.typeAhead){
13557 this.taTask = new Roo.util.DelayedTask(this.onTypeAhead, this);
13559 if(this.editable !== false){
13560 this.inputEl().on("keyup", this.onKeyUp, this);
13562 if(this.forceSelection){
13563 this.inputEl().on('blur', this.doForce, this);
13567 this.choices = this.el.select('ul.roo-select2-choices', true).first();
13568 this.searchField = this.el.select('ul li.roo-select2-search-field', true).first();
13572 initTickableEvents: function()
13576 if(this.hiddenName){
13578 this.hiddenField = this.el.select('input.form-hidden-field',true).first();
13580 this.hiddenField.dom.value =
13581 this.hiddenValue !== undefined ? this.hiddenValue :
13582 this.value !== undefined ? this.value : '';
13584 // prevent input submission
13585 this.el.dom.removeAttribute('name');
13586 this.hiddenField.dom.setAttribute('name', this.hiddenName);
13591 // this.list = this.el.select('ul.dropdown-menu',true).first();
13593 this.choices = this.el.select('ul.roo-select2-choices', true).first();
13594 this.searchField = this.el.select('ul li.roo-select2-search-field', true).first();
13595 if(this.triggerList){
13596 this.searchField.on("click", this.onSearchFieldClick, this, {preventDefault:true});
13599 this.trigger = this.el.select('.tickable-buttons > .btn-edit', true).first();
13600 this.trigger.on("click", this.onTickableTriggerClick, this, {preventDefault:true});
13602 this.okBtn = this.el.select('.tickable-buttons > .btn-ok', true).first();
13603 this.cancelBtn = this.el.select('.tickable-buttons > .btn-cancel', true).first();
13605 this.okBtn.on('click', this.onTickableFooterButtonClick, this, this.okBtn);
13606 this.cancelBtn.on('click', this.onTickableFooterButtonClick, this, this.cancelBtn);
13608 this.trigger.setVisibilityMode(Roo.Element.DISPLAY);
13609 this.okBtn.setVisibilityMode(Roo.Element.DISPLAY);
13610 this.cancelBtn.setVisibilityMode(Roo.Element.DISPLAY);
13613 this.cancelBtn.hide();
13618 var lw = _this.listWidth || Math.max(_this.inputEl().getWidth(), _this.minListWidth);
13619 _this.list.setWidth(lw);
13622 this.list.on('mouseover', this.onViewOver, this);
13623 this.list.on('mousemove', this.onViewMove, this);
13625 this.list.on('scroll', this.onViewScroll, this);
13628 this.tpl = '<li class="roo-select2-result"><div class="checkbox"><input id="{roo-id}"' +
13629 'type="checkbox" {roo-data-checked}><label for="{roo-id}"><b>{' + this.displayField + '}</b></label></div></li>';
13632 this.view = new Roo.View(this.list, this.tpl, {
13637 selectedClass: this.selectedClass
13640 //this.view.wrapEl.setDisplayed(false);
13641 this.view.on('click', this.onViewClick, this);
13645 this.store.on('beforeload', this.onBeforeLoad, this);
13646 this.store.on('load', this.onLoad, this);
13647 this.store.on('loadexception', this.onLoadException, this);
13650 this.keyNav = new Roo.KeyNav(this.tickableInputEl(), {
13651 "up" : function(e){
13652 this.inKeyMode = true;
13656 "down" : function(e){
13657 this.inKeyMode = true;
13661 "enter" : function(e){
13662 if(this.fireEvent("specialkey", this, e)){
13663 this.onViewClick(false);
13669 "esc" : function(e){
13670 this.onTickableFooterButtonClick(e, false, false);
13673 "tab" : function(e){
13674 this.fireEvent("specialkey", this, e);
13676 this.onTickableFooterButtonClick(e, false, false);
13683 doRelay : function(e, fn, key){
13684 if(this.scope.isExpanded()){
13685 return Roo.KeyNav.prototype.doRelay.apply(this, arguments);
13694 this.queryDelay = Math.max(this.queryDelay || 10,
13695 this.mode == 'local' ? 10 : 250);
13698 this.dqTask = new Roo.util.DelayedTask(this.initQuery, this);
13700 if(this.typeAhead){
13701 this.taTask = new Roo.util.DelayedTask(this.onTypeAhead, this);
13704 if(this.editable !== false){
13705 this.tickableInputEl().on("keyup", this.onKeyUp, this);
13708 this.indicator = this.indicatorEl();
13710 if(this.indicator){
13711 this.indicator.setVisibilityMode(Roo.Element.DISPLAY);
13712 this.indicator.hide();
13717 onDestroy : function(){
13719 this.view.setStore(null);
13720 this.view.el.removeAllListeners();
13721 this.view.el.remove();
13722 this.view.purgeListeners();
13725 this.list.dom.innerHTML = '';
13729 this.store.un('beforeload', this.onBeforeLoad, this);
13730 this.store.un('load', this.onLoad, this);
13731 this.store.un('loadexception', this.onLoadException, this);
13733 Roo.bootstrap.ComboBox.superclass.onDestroy.call(this);
13737 fireKey : function(e){
13738 if(e.isNavKeyPress() && !this.list.isVisible()){
13739 this.fireEvent("specialkey", this, e);
13744 onResize: function(w, h){
13745 // Roo.bootstrap.ComboBox.superclass.onResize.apply(this, arguments);
13747 // if(typeof w != 'number'){
13748 // // we do not handle it!?!?
13751 // var tw = this.trigger.getWidth();
13752 // // tw += this.addicon ? this.addicon.getWidth() : 0;
13753 // // tw += this.editicon ? this.editicon.getWidth() : 0;
13755 // this.inputEl().setWidth( this.adjustWidth('input', x));
13757 // //this.trigger.setStyle('left', x+'px');
13759 // if(this.list && this.listWidth === undefined){
13760 // var lw = Math.max(x + this.trigger.getWidth(), this.minListWidth);
13761 // this.list.setWidth(lw);
13762 // this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
13770 * Allow or prevent the user from directly editing the field text. If false is passed,
13771 * the user will only be able to select from the items defined in the dropdown list. This method
13772 * is the runtime equivalent of setting the 'editable' config option at config time.
13773 * @param {Boolean} value True to allow the user to directly edit the field text
13775 setEditable : function(value){
13776 if(value == this.editable){
13779 this.editable = value;
13781 this.inputEl().dom.setAttribute('readOnly', true);
13782 this.inputEl().on('mousedown', this.onTriggerClick, this);
13783 this.inputEl().addClass('x-combo-noedit');
13785 this.inputEl().dom.setAttribute('readOnly', false);
13786 this.inputEl().un('mousedown', this.onTriggerClick, this);
13787 this.inputEl().removeClass('x-combo-noedit');
13793 onBeforeLoad : function(combo,opts){
13794 if(!this.hasFocus){
13798 this.list.dom.innerHTML = '<li class="loading-indicator">'+(this.loadingText||'loading')+'</li>' ;
13800 this.restrictHeight();
13801 this.selectedIndex = -1;
13805 onLoad : function(){
13807 this.hasQuery = false;
13809 if(!this.hasFocus){
13813 if(typeof(this.loading) !== 'undefined' && this.loading !== null){
13814 this.loading.hide();
13817 if(this.store.getCount() > 0){
13820 this.restrictHeight();
13821 if(this.lastQuery == this.allQuery){
13822 if(this.editable && !this.tickable){
13823 this.inputEl().dom.select();
13827 !this.selectByValue(this.value, true) &&
13830 !this.store.lastOptions ||
13831 typeof(this.store.lastOptions.add) == 'undefined' ||
13832 this.store.lastOptions.add != true
13835 this.select(0, true);
13838 if(this.autoFocus){
13841 if(this.typeAhead && this.lastKey != Roo.EventObject.BACKSPACE && this.lastKey != Roo.EventObject.DELETE){
13842 this.taTask.delay(this.typeAheadDelay);
13846 this.onEmptyResults();
13852 onLoadException : function()
13854 this.hasQuery = false;
13856 if(typeof(this.loading) !== 'undefined' && this.loading !== null){
13857 this.loading.hide();
13860 if(this.tickable && this.editable){
13865 // only causes errors at present
13866 //Roo.log(this.store.reader.jsonData);
13867 //if (this.store && typeof(this.store.reader.jsonData.errorMsg) != 'undefined') {
13869 //Roo.MessageBox.alert("Error loading",this.store.reader.jsonData.errorMsg);
13875 onTypeAhead : function(){
13876 if(this.store.getCount() > 0){
13877 var r = this.store.getAt(0);
13878 var newValue = r.data[this.displayField];
13879 var len = newValue.length;
13880 var selStart = this.getRawValue().length;
13882 if(selStart != len){
13883 this.setRawValue(newValue);
13884 this.selectText(selStart, newValue.length);
13890 onSelect : function(record, index){
13892 if(this.fireEvent('beforeselect', this, record, index) !== false){
13894 this.setFromData(index > -1 ? record.data : false);
13897 this.fireEvent('select', this, record, index);
13902 * Returns the currently selected field value or empty string if no value is set.
13903 * @return {String} value The selected value
13905 getValue : function()
13907 if(Roo.isIOS && this.useNativeIOS){
13908 return this.ios_options[this.inputEl().dom.selectedIndex].data[this.valueField];
13912 return (this.hiddenField) ? this.hiddenField.dom.value : this.value;
13915 if(this.valueField){
13916 return typeof this.value != 'undefined' ? this.value : '';
13918 return Roo.bootstrap.ComboBox.superclass.getValue.call(this);
13922 getRawValue : function()
13924 if(Roo.isIOS && this.useNativeIOS){
13925 return this.ios_options[this.inputEl().dom.selectedIndex].data[this.displayField];
13928 var v = this.inputEl().getValue();
13934 * Clears any text/value currently set in the field
13936 clearValue : function(){
13938 if(this.hiddenField){
13939 this.hiddenField.dom.value = '';
13942 this.setRawValue('');
13943 this.lastSelectionText = '';
13944 this.lastData = false;
13946 var close = this.closeTriggerEl();
13957 * Sets the specified value into the field. If the value finds a match, the corresponding record text
13958 * will be displayed in the field. If the value does not match the data value of an existing item,
13959 * and the valueNotFoundText config option is defined, it will be displayed as the default field text.
13960 * Otherwise the field will be blank (although the value will still be set).
13961 * @param {String} value The value to match
13963 setValue : function(v)
13965 if(Roo.isIOS && this.useNativeIOS){
13966 this.setIOSValue(v);
13976 if(this.valueField){
13977 var r = this.findRecord(this.valueField, v);
13979 text = r.data[this.displayField];
13980 }else if(this.valueNotFoundText !== undefined){
13981 text = this.valueNotFoundText;
13984 this.lastSelectionText = text;
13985 if(this.hiddenField){
13986 this.hiddenField.dom.value = v;
13988 Roo.bootstrap.ComboBox.superclass.setValue.call(this, text);
13991 var close = this.closeTriggerEl();
13994 (v && (v.length || v * 1 > 0)) ? close.show() : close.hide();
14000 * @property {Object} the last set data for the element
14005 * Sets the value of the field based on a object which is related to the record format for the store.
14006 * @param {Object} value the value to set as. or false on reset?
14008 setFromData : function(o){
14015 var dv = ''; // display value
14016 var vv = ''; // value value..
14018 if (this.displayField) {
14019 dv = !o || typeof(o[this.displayField]) == 'undefined' ? '' : o[this.displayField];
14021 // this is an error condition!!!
14022 Roo.log('no displayField value set for '+ (this.name ? this.name : this.id));
14025 if(this.valueField){
14026 vv = !o || typeof(o[this.valueField]) == 'undefined' ? dv : o[this.valueField];
14029 var close = this.closeTriggerEl();
14032 if(dv.length || vv * 1 > 0){
14034 this.blockFocus=true;
14040 if(this.hiddenField){
14041 this.hiddenField.dom.value = vv;
14043 this.lastSelectionText = dv;
14044 Roo.bootstrap.ComboBox.superclass.setValue.call(this, dv);
14048 // no hidden field.. - we store the value in 'value', but still display
14049 // display field!!!!
14050 this.lastSelectionText = dv;
14051 Roo.bootstrap.ComboBox.superclass.setValue.call(this, dv);
14058 reset : function(){
14059 // overridden so that last data is reset..
14066 this.setValue(this.originalValue);
14067 //this.clearInvalid();
14068 this.lastData = false;
14070 this.view.clearSelections();
14076 findRecord : function(prop, value){
14078 if(this.store.getCount() > 0){
14079 this.store.each(function(r){
14080 if(r.data[prop] == value){
14090 getName: function()
14092 // returns hidden if it's set..
14093 if (!this.rendered) {return ''};
14094 return !this.hiddenName && this.inputEl().dom.name ? this.inputEl().dom.name : (this.hiddenName || '');
14098 onViewMove : function(e, t){
14099 this.inKeyMode = false;
14103 onViewOver : function(e, t){
14104 if(this.inKeyMode){ // prevent key nav and mouse over conflicts
14107 var item = this.view.findItemFromChild(t);
14110 var index = this.view.indexOf(item);
14111 this.select(index, false);
14116 onViewClick : function(view, doFocus, el, e)
14118 var index = this.view.getSelectedIndexes()[0];
14120 var r = this.store.getAt(index);
14124 if(typeof(e) != 'undefined' && e.getTarget().nodeName.toLowerCase() != 'input'){
14131 Roo.each(this.tickItems, function(v,k){
14133 if(typeof(v) != 'undefined' && v[_this.valueField] == r.data[_this.valueField]){
14135 _this.tickItems.splice(k, 1);
14137 if(typeof(e) == 'undefined' && view == false){
14138 Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked = false;
14150 if(this.fireEvent('tick', this, r, index, Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked) !== false){
14151 this.tickItems.push(r.data);
14154 if(typeof(e) == 'undefined' && view == false){
14155 Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked = true;
14162 this.onSelect(r, index);
14164 if(doFocus !== false && !this.blockFocus){
14165 this.inputEl().focus();
14170 restrictHeight : function(){
14171 //this.innerList.dom.style.height = '';
14172 //var inner = this.innerList.dom;
14173 //var h = Math.max(inner.clientHeight, inner.offsetHeight, inner.scrollHeight);
14174 //this.innerList.setHeight(h < this.maxHeight ? 'auto' : this.maxHeight);
14175 //this.list.beginUpdate();
14176 //this.list.setHeight(this.innerList.getHeight()+this.list.getFrameWidth('tb')+(this.resizable?this.handleHeight:0)+this.assetHeight);
14177 this.list.alignTo(this.inputEl(), this.listAlign);
14178 this.list.alignTo(this.inputEl(), this.listAlign);
14179 //this.list.endUpdate();
14183 onEmptyResults : function(){
14185 if(this.tickable && this.editable){
14186 this.hasFocus = false;
14187 this.restrictHeight();
14195 * Returns true if the dropdown list is expanded, else false.
14197 isExpanded : function(){
14198 return this.list.isVisible();
14202 * Select an item in the dropdown list by its data value. This function does NOT cause the select event to fire.
14203 * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
14204 * @param {String} value The data value of the item to select
14205 * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
14206 * selected item if it is not currently in view (defaults to true)
14207 * @return {Boolean} True if the value matched an item in the list, else false
14209 selectByValue : function(v, scrollIntoView){
14210 if(v !== undefined && v !== null){
14211 var r = this.findRecord(this.valueField || this.displayField, v);
14213 this.select(this.store.indexOf(r), scrollIntoView);
14221 * Select an item in the dropdown list by its numeric index in the list. This function does NOT cause the select event to fire.
14222 * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
14223 * @param {Number} index The zero-based index of the list item to select
14224 * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
14225 * selected item if it is not currently in view (defaults to true)
14227 select : function(index, scrollIntoView){
14228 this.selectedIndex = index;
14229 this.view.select(index);
14230 if(scrollIntoView !== false){
14231 var el = this.view.getNode(index);
14233 * el && !this.multiple && !this.tickable // not sure why we disable multiple before..
14236 this.list.scrollChildIntoView(el, false);
14242 selectNext : function(){
14243 var ct = this.store.getCount();
14245 if(this.selectedIndex == -1){
14247 }else if(this.selectedIndex < ct-1){
14248 this.select(this.selectedIndex+1);
14254 selectPrev : function(){
14255 var ct = this.store.getCount();
14257 if(this.selectedIndex == -1){
14259 }else if(this.selectedIndex != 0){
14260 this.select(this.selectedIndex-1);
14266 onKeyUp : function(e){
14267 if(this.editable !== false && !e.isSpecialKey()){
14268 this.lastKey = e.getKey();
14269 this.dqTask.delay(this.queryDelay);
14274 validateBlur : function(){
14275 return !this.list || !this.list.isVisible();
14279 initQuery : function(){
14281 var v = this.getRawValue();
14283 if(this.tickable && this.editable){
14284 v = this.tickableInputEl().getValue();
14291 doForce : function(){
14292 if(this.inputEl().dom.value.length > 0){
14293 this.inputEl().dom.value =
14294 this.lastSelectionText === undefined ? '' : this.lastSelectionText;
14300 * Execute a query to filter the dropdown list. Fires the beforequery event prior to performing the
14301 * query allowing the query action to be canceled if needed.
14302 * @param {String} query The SQL query to execute
14303 * @param {Boolean} forceAll True to force the query to execute even if there are currently fewer characters
14304 * in the field than the minimum specified by the minChars config option. It also clears any filter previously
14305 * saved in the current store (defaults to false)
14307 doQuery : function(q, forceAll){
14309 if(q === undefined || q === null){
14314 forceAll: forceAll,
14318 if(this.fireEvent('beforequery', qe)===false || qe.cancel){
14323 forceAll = qe.forceAll;
14324 if(forceAll === true || (q.length >= this.minChars)){
14326 this.hasQuery = true;
14328 if(this.lastQuery != q || this.alwaysQuery){
14329 this.lastQuery = q;
14330 if(this.mode == 'local'){
14331 this.selectedIndex = -1;
14333 this.store.clearFilter();
14336 if(this.specialFilter){
14337 this.fireEvent('specialfilter', this);
14342 this.store.filter(this.displayField, q);
14345 this.store.fireEvent("datachanged", this.store);
14352 this.store.baseParams[this.queryParam] = q;
14354 var options = {params : this.getParams(q)};
14357 options.add = true;
14358 options.params.start = this.page * this.pageSize;
14361 this.store.load(options);
14364 * this code will make the page width larger, at the beginning, the list not align correctly,
14365 * we should expand the list on onLoad
14366 * so command out it
14371 this.selectedIndex = -1;
14376 this.loadNext = false;
14380 getParams : function(q){
14382 //p[this.queryParam] = q;
14386 p.limit = this.pageSize;
14392 * Hides the dropdown list if it is currently expanded. Fires the 'collapse' event on completion.
14394 collapse : function(){
14395 if(!this.isExpanded()){
14401 this.hasFocus = false;
14405 this.cancelBtn.hide();
14406 this.trigger.show();
14409 this.tickableInputEl().dom.value = '';
14410 this.tickableInputEl().blur();
14415 Roo.get(document).un('mousedown', this.collapseIf, this);
14416 Roo.get(document).un('mousewheel', this.collapseIf, this);
14417 if (!this.editable) {
14418 Roo.get(document).un('keydown', this.listKeyPress, this);
14420 this.fireEvent('collapse', this);
14426 collapseIf : function(e){
14427 var in_combo = e.within(this.el);
14428 var in_list = e.within(this.list);
14429 var is_list = (Roo.get(e.getTarget()).id == this.list.id) ? true : false;
14431 if (in_combo || in_list || is_list) {
14432 //e.stopPropagation();
14437 this.onTickableFooterButtonClick(e, false, false);
14445 * Expands the dropdown list if it is currently hidden. Fires the 'expand' event on completion.
14447 expand : function(){
14449 if(this.isExpanded() || !this.hasFocus){
14453 var lw = this.listWidth || Math.max(this.inputEl().getWidth(), this.minListWidth);
14454 this.list.setWidth(lw);
14460 this.restrictHeight();
14464 this.tickItems = Roo.apply([], this.item);
14467 this.cancelBtn.show();
14468 this.trigger.hide();
14471 this.tickableInputEl().focus();
14476 Roo.get(document).on('mousedown', this.collapseIf, this);
14477 Roo.get(document).on('mousewheel', this.collapseIf, this);
14478 if (!this.editable) {
14479 Roo.get(document).on('keydown', this.listKeyPress, this);
14482 this.fireEvent('expand', this);
14486 // Implements the default empty TriggerField.onTriggerClick function
14487 onTriggerClick : function(e)
14489 Roo.log('trigger click');
14491 if(this.disabled || !this.triggerList){
14496 this.loadNext = false;
14498 if(this.isExpanded()){
14500 if (!this.blockFocus) {
14501 this.inputEl().focus();
14505 this.hasFocus = true;
14506 if(this.triggerAction == 'all') {
14507 this.doQuery(this.allQuery, true);
14509 this.doQuery(this.getRawValue());
14511 if (!this.blockFocus) {
14512 this.inputEl().focus();
14517 onTickableTriggerClick : function(e)
14524 this.loadNext = false;
14525 this.hasFocus = true;
14527 if(this.triggerAction == 'all') {
14528 this.doQuery(this.allQuery, true);
14530 this.doQuery(this.getRawValue());
14534 onSearchFieldClick : function(e)
14536 if(this.hasFocus && !this.disabled && e.getTarget().nodeName.toLowerCase() != 'button'){
14537 this.onTickableFooterButtonClick(e, false, false);
14541 if(this.hasFocus || this.disabled || e.getTarget().nodeName.toLowerCase() == 'button'){
14546 this.loadNext = false;
14547 this.hasFocus = true;
14549 if(this.triggerAction == 'all') {
14550 this.doQuery(this.allQuery, true);
14552 this.doQuery(this.getRawValue());
14556 listKeyPress : function(e)
14558 //Roo.log('listkeypress');
14559 // scroll to first matching element based on key pres..
14560 if (e.isSpecialKey()) {
14563 var k = String.fromCharCode(e.getKey()).toUpperCase();
14566 var csel = this.view.getSelectedNodes();
14567 var cselitem = false;
14569 var ix = this.view.indexOf(csel[0]);
14570 cselitem = this.store.getAt(ix);
14571 if (!cselitem.get(this.displayField) || cselitem.get(this.displayField).substring(0,1).toUpperCase() != k) {
14577 this.store.each(function(v) {
14579 // start at existing selection.
14580 if (cselitem.id == v.id) {
14586 if (v.get(this.displayField) && v.get(this.displayField).substring(0,1).toUpperCase() == k) {
14587 match = this.store.indexOf(v);
14593 if (match === false) {
14594 return true; // no more action?
14597 this.view.select(match);
14598 var sn = Roo.get(this.view.getSelectedNodes()[0]);
14599 sn.scrollIntoView(sn.dom.parentNode, false);
14602 onViewScroll : function(e, t){
14604 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){
14608 this.hasQuery = true;
14610 this.loading = this.list.select('.loading', true).first();
14612 if(this.loading === null){
14613 this.list.createChild({
14615 cls: 'loading roo-select2-more-results roo-select2-active',
14616 html: 'Loading more results...'
14619 this.loading = this.list.select('.loading', true).first();
14621 this.loading.setVisibilityMode(Roo.Element.DISPLAY);
14623 this.loading.hide();
14626 this.loading.show();
14631 this.loadNext = true;
14633 (function() { _combo.doQuery(_combo.allQuery, true); }).defer(500);
14638 addItem : function(o)
14640 var dv = ''; // display value
14642 if (this.displayField) {
14643 dv = !o || typeof(o[this.displayField]) == 'undefined' ? '' : o[this.displayField];
14645 // this is an error condition!!!
14646 Roo.log('no displayField value set for '+ (this.name ? this.name : this.id));
14653 var choice = this.choices.createChild({
14655 cls: 'roo-select2-search-choice',
14664 cls: 'roo-select2-search-choice-close fa fa-times',
14669 }, this.searchField);
14671 var close = choice.select('a.roo-select2-search-choice-close', true).first();
14673 close.on('click', this.onRemoveItem, this, { item : choice, data : o} );
14681 this.inputEl().dom.value = '';
14686 onRemoveItem : function(e, _self, o)
14688 e.preventDefault();
14690 this.lastItem = Roo.apply([], this.item);
14692 var index = this.item.indexOf(o.data) * 1;
14695 Roo.log('not this item?!');
14699 this.item.splice(index, 1);
14704 this.fireEvent('remove', this, e);
14710 syncValue : function()
14712 if(!this.item.length){
14719 Roo.each(this.item, function(i){
14720 if(_this.valueField){
14721 value.push(i[_this.valueField]);
14728 this.value = value.join(',');
14730 if(this.hiddenField){
14731 this.hiddenField.dom.value = this.value;
14734 this.store.fireEvent("datachanged", this.store);
14739 clearItem : function()
14741 if(!this.multiple){
14747 Roo.each(this.choices.select('>li.roo-select2-search-choice', true).elements, function(c){
14755 if(this.tickable && !Roo.isTouch){
14756 this.view.refresh();
14760 inputEl: function ()
14762 if(Roo.isIOS && this.useNativeIOS){
14763 return this.el.select('select.roo-ios-select', true).first();
14766 if(Roo.isTouch && this.mobileTouchView){
14767 return this.el.select('input.form-control',true).first();
14771 return this.searchField;
14774 return this.el.select('input.form-control',true).first();
14777 onTickableFooterButtonClick : function(e, btn, el)
14779 e.preventDefault();
14781 this.lastItem = Roo.apply([], this.item);
14783 if(btn && btn.name == 'cancel'){
14784 this.tickItems = Roo.apply([], this.item);
14793 Roo.each(this.tickItems, function(o){
14801 validate : function()
14803 if(this.getVisibilityEl().hasClass('hidden')){
14807 var v = this.getRawValue();
14810 v = this.getValue();
14813 if(this.disabled || this.allowBlank || v.length){
14818 this.markInvalid();
14822 tickableInputEl : function()
14824 if(!this.tickable || !this.editable){
14825 return this.inputEl();
14828 return this.inputEl().select('.roo-select2-search-field-input', true).first();
14832 getAutoCreateTouchView : function()
14837 cls: 'form-group' //input-group
14843 type : this.inputType,
14844 cls : 'form-control x-combo-noedit',
14845 autocomplete: 'new-password',
14846 placeholder : this.placeholder || '',
14851 input.name = this.name;
14855 input.cls += ' input-' + this.size;
14858 if (this.disabled) {
14859 input.disabled = true;
14870 inputblock.cls += ' input-group';
14872 inputblock.cn.unshift({
14874 cls : 'input-group-addon',
14879 if(this.removable && !this.multiple){
14880 inputblock.cls += ' roo-removable';
14882 inputblock.cn.push({
14885 cls : 'roo-combo-removable-btn close'
14889 if(this.hasFeedback && !this.allowBlank){
14891 inputblock.cls += ' has-feedback';
14893 inputblock.cn.push({
14895 cls: 'glyphicon form-control-feedback'
14902 inputblock.cls += (this.before) ? '' : ' input-group';
14904 inputblock.cn.push({
14906 cls : 'input-group-addon',
14917 cls: 'form-hidden-field'
14931 cls: 'form-hidden-field'
14935 cls: 'roo-select2-choices',
14939 cls: 'roo-select2-search-field',
14952 cls: 'roo-select2-container input-group roo-touchview-combobox ',
14958 if(!this.multiple && this.showToggleBtn){
14965 if (this.caret != false) {
14968 cls: 'fa fa-' + this.caret
14975 cls : 'input-group-addon btn dropdown-toggle',
14980 cls: 'combobox-clear',
14994 combobox.cls += ' roo-select2-container-multi';
14997 var align = this.labelAlign || this.parentLabelAlign();
14999 if (align ==='left' && this.fieldLabel.length) {
15004 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
15005 tooltip : 'This field is required'
15009 cls : 'control-label',
15010 html : this.fieldLabel
15021 var labelCfg = cfg.cn[1];
15022 var contentCfg = cfg.cn[2];
15025 if(this.indicatorpos == 'right'){
15030 cls : 'control-label',
15034 html : this.fieldLabel
15038 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
15039 tooltip : 'This field is required'
15052 labelCfg = cfg.cn[0];
15053 contentCfg = cfg.cn[1];
15058 if(this.labelWidth > 12){
15059 labelCfg.style = "width: " + this.labelWidth + 'px';
15062 if(this.labelWidth < 13 && this.labelmd == 0){
15063 this.labelmd = this.labelWidth;
15066 if(this.labellg > 0){
15067 labelCfg.cls += ' col-lg-' + this.labellg;
15068 contentCfg.cls += ' col-lg-' + (12 - this.labellg);
15071 if(this.labelmd > 0){
15072 labelCfg.cls += ' col-md-' + this.labelmd;
15073 contentCfg.cls += ' col-md-' + (12 - this.labelmd);
15076 if(this.labelsm > 0){
15077 labelCfg.cls += ' col-sm-' + this.labelsm;
15078 contentCfg.cls += ' col-sm-' + (12 - this.labelsm);
15081 if(this.labelxs > 0){
15082 labelCfg.cls += ' col-xs-' + this.labelxs;
15083 contentCfg.cls += ' col-xs-' + (12 - this.labelxs);
15087 } else if ( this.fieldLabel.length) {
15091 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
15092 tooltip : 'This field is required'
15096 cls : 'control-label',
15097 html : this.fieldLabel
15108 if(this.indicatorpos == 'right'){
15112 cls : 'control-label',
15113 html : this.fieldLabel,
15117 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
15118 tooltip : 'This field is required'
15135 var settings = this;
15137 ['xs','sm','md','lg'].map(function(size){
15138 if (settings[size]) {
15139 cfg.cls += ' col-' + size + '-' + settings[size];
15146 initTouchView : function()
15148 this.renderTouchView();
15150 this.touchViewEl.on('scroll', function(){
15151 this.el.dom.scrollTop = 0;
15154 this.originalValue = this.getValue();
15156 this.triggerEl = this.el.select('span.dropdown-toggle',true).first();
15158 this.inputEl().on("click", this.showTouchView, this);
15159 if (this.triggerEl) {
15160 this.triggerEl.on("click", this.showTouchView, this);
15164 this.touchViewFooterEl.select('.roo-touch-view-cancel', true).first().on('click', this.hideTouchView, this);
15165 this.touchViewFooterEl.select('.roo-touch-view-ok', true).first().on('click', this.setTouchViewValue, this);
15167 this.maskEl = new Roo.LoadMask(this.touchViewEl, { store : this.store, msgCls: 'roo-el-mask-msg' });
15169 this.store.on('beforeload', this.onTouchViewBeforeLoad, this);
15170 this.store.on('load', this.onTouchViewLoad, this);
15171 this.store.on('loadexception', this.onTouchViewLoadException, this);
15173 if(this.hiddenName){
15175 this.hiddenField = this.el.select('input.form-hidden-field',true).first();
15177 this.hiddenField.dom.value =
15178 this.hiddenValue !== undefined ? this.hiddenValue :
15179 this.value !== undefined ? this.value : '';
15181 this.el.dom.removeAttribute('name');
15182 this.hiddenField.dom.setAttribute('name', this.hiddenName);
15186 this.choices = this.el.select('ul.roo-select2-choices', true).first();
15187 this.searchField = this.el.select('ul li.roo-select2-search-field', true).first();
15190 if(this.removable && !this.multiple){
15191 var close = this.closeTriggerEl();
15193 close.setVisibilityMode(Roo.Element.DISPLAY).hide();
15194 close.on('click', this.removeBtnClick, this, close);
15198 * fix the bug in Safari iOS8
15200 this.inputEl().on("focus", function(e){
15201 document.activeElement.blur();
15209 renderTouchView : function()
15211 this.touchViewEl = Roo.get(document.body).createChild(Roo.bootstrap.ComboBox.touchViewTemplate);
15212 this.touchViewEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
15214 this.touchViewHeaderEl = this.touchViewEl.select('.modal-header', true).first();
15215 this.touchViewHeaderEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
15217 this.touchViewBodyEl = this.touchViewEl.select('.modal-body', true).first();
15218 this.touchViewBodyEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
15219 this.touchViewBodyEl.setStyle('overflow', 'auto');
15221 this.touchViewListGroup = this.touchViewBodyEl.select('.list-group', true).first();
15222 this.touchViewListGroup.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
15224 this.touchViewFooterEl = this.touchViewEl.select('.modal-footer', true).first();
15225 this.touchViewFooterEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
15229 showTouchView : function()
15235 this.touchViewHeaderEl.hide();
15237 if(this.modalTitle.length){
15238 this.touchViewHeaderEl.dom.innerHTML = this.modalTitle;
15239 this.touchViewHeaderEl.show();
15242 this.touchViewEl.setStyle('z-index', Roo.bootstrap.Modal.zIndex++);
15243 this.touchViewEl.show();
15245 this.touchViewEl.select('.modal-dialog', true).first().setStyle({ margin : '0px', width : '100%'});
15247 //this.touchViewEl.select('.modal-dialog > .modal-content', true).first().setSize(
15248 // Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
15250 var bodyHeight = Roo.lib.Dom.getViewHeight() - this.touchViewFooterEl.getHeight() + this.touchViewBodyEl.getPadding('tb');
15252 if(this.modalTitle.length){
15253 bodyHeight = bodyHeight - this.touchViewHeaderEl.getHeight();
15256 this.touchViewBodyEl.setHeight(bodyHeight);
15260 (function(){ _this.touchViewEl.addClass('in'); }).defer(50);
15262 this.touchViewEl.addClass('in');
15265 this.doTouchViewQuery();
15269 hideTouchView : function()
15271 this.touchViewEl.removeClass('in');
15275 (function(){ _this.touchViewEl.setStyle('display', 'none'); }).defer(150);
15277 this.touchViewEl.setStyle('display', 'none');
15282 setTouchViewValue : function()
15289 Roo.each(this.tickItems, function(o){
15294 this.hideTouchView();
15297 doTouchViewQuery : function()
15306 if(this.fireEvent('beforequery', qe) ===false || qe.cancel){
15310 if(!this.alwaysQuery || this.mode == 'local'){
15311 this.onTouchViewLoad();
15318 onTouchViewBeforeLoad : function(combo,opts)
15324 onTouchViewLoad : function()
15326 if(this.store.getCount() < 1){
15327 this.onTouchViewEmptyResults();
15331 this.clearTouchView();
15333 var rawValue = this.getRawValue();
15335 var template = (this.multiple) ? Roo.bootstrap.ComboBox.listItemCheckbox : Roo.bootstrap.ComboBox.listItemRadio;
15337 this.tickItems = [];
15339 this.store.data.each(function(d, rowIndex){
15340 var row = this.touchViewListGroup.createChild(template);
15342 if(typeof(d.data.cls) != 'undefined' && d.data.cls.length){
15343 row.addClass(d.data.cls);
15346 if(this.displayField && typeof(d.data[this.displayField]) != 'undefined'){
15349 html : d.data[this.displayField]
15352 if(this.fireEvent('touchviewdisplay', this, cfg) !== false){
15353 row.select('.roo-combobox-list-group-item-value', true).first().dom.innerHTML = cfg.html;
15356 row.removeClass('selected');
15357 if(!this.multiple && this.valueField &&
15358 typeof(d.data[this.valueField]) != 'undefined' && d.data[this.valueField] == this.getValue())
15361 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
15362 row.addClass('selected');
15365 if(this.multiple && this.valueField &&
15366 typeof(d.data[this.valueField]) != 'undefined' && this.getValue().indexOf(d.data[this.valueField]) != -1)
15370 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
15371 this.tickItems.push(d.data);
15374 row.on('click', this.onTouchViewClick, this, {row : row, rowIndex : rowIndex});
15378 var firstChecked = this.touchViewListGroup.select('.list-group-item > .roo-combobox-list-group-item-box > input:checked', true).first();
15380 var bodyHeight = Roo.lib.Dom.getViewHeight() - this.touchViewFooterEl.getHeight() + this.touchViewBodyEl.getPadding('tb');
15382 if(this.modalTitle.length){
15383 bodyHeight = bodyHeight - this.touchViewHeaderEl.getHeight();
15386 var listHeight = this.touchViewListGroup.getHeight();
15390 if(firstChecked && listHeight > bodyHeight){
15391 (function() { firstChecked.findParent('li').scrollIntoView(_this.touchViewListGroup.dom); }).defer(500);
15396 onTouchViewLoadException : function()
15398 this.hideTouchView();
15401 onTouchViewEmptyResults : function()
15403 this.clearTouchView();
15405 this.touchViewListGroup.createChild(Roo.bootstrap.ComboBox.emptyResult);
15407 this.touchViewListGroup.select('.roo-combobox-touch-view-empty-result', true).first().dom.innerHTML = this.emptyResultText;
15411 clearTouchView : function()
15413 this.touchViewListGroup.dom.innerHTML = '';
15416 onTouchViewClick : function(e, el, o)
15418 e.preventDefault();
15421 var rowIndex = o.rowIndex;
15423 var r = this.store.getAt(rowIndex);
15425 if(this.fireEvent('beforeselect', this, r, rowIndex) !== false){
15427 if(!this.multiple){
15428 Roo.each(this.touchViewListGroup.select('.list-group-item > .roo-combobox-list-group-item-box > input:checked', true).elements, function(c){
15429 c.dom.removeAttribute('checked');
15432 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
15434 this.setFromData(r.data);
15436 var close = this.closeTriggerEl();
15442 this.hideTouchView();
15444 this.fireEvent('select', this, r, rowIndex);
15449 if(this.valueField && typeof(r.data[this.valueField]) != 'undefined' && this.getValue().indexOf(r.data[this.valueField]) != -1){
15450 row.select('.roo-combobox-list-group-item-box > input', true).first().dom.removeAttribute('checked');
15451 this.tickItems.splice(this.tickItems.indexOf(r.data), 1);
15455 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
15456 this.addItem(r.data);
15457 this.tickItems.push(r.data);
15461 getAutoCreateNativeIOS : function()
15464 cls: 'form-group' //input-group,
15469 cls : 'roo-ios-select'
15473 combobox.name = this.name;
15476 if (this.disabled) {
15477 combobox.disabled = true;
15480 var settings = this;
15482 ['xs','sm','md','lg'].map(function(size){
15483 if (settings[size]) {
15484 cfg.cls += ' col-' + size + '-' + settings[size];
15494 initIOSView : function()
15496 this.store.on('load', this.onIOSViewLoad, this);
15501 onIOSViewLoad : function()
15503 if(this.store.getCount() < 1){
15507 this.clearIOSView();
15509 if(this.allowBlank) {
15511 var default_text = '-- SELECT --';
15513 if(this.placeholder.length){
15514 default_text = this.placeholder;
15517 if(this.emptyTitle.length){
15518 default_text += ' - ' + this.emptyTitle + ' -';
15521 var opt = this.inputEl().createChild({
15524 html : default_text
15528 o[this.valueField] = 0;
15529 o[this.displayField] = default_text;
15531 this.ios_options.push({
15538 this.store.data.each(function(d, rowIndex){
15542 if(this.displayField && typeof(d.data[this.displayField]) != 'undefined'){
15543 html = d.data[this.displayField];
15548 if(this.valueField && typeof(d.data[this.valueField]) != 'undefined'){
15549 value = d.data[this.valueField];
15558 if(this.value == d.data[this.valueField]){
15559 option['selected'] = true;
15562 var opt = this.inputEl().createChild(option);
15564 this.ios_options.push({
15571 this.inputEl().on('change', function(){
15572 this.fireEvent('select', this);
15577 clearIOSView: function()
15579 this.inputEl().dom.innerHTML = '';
15581 this.ios_options = [];
15584 setIOSValue: function(v)
15588 if(!this.ios_options){
15592 Roo.each(this.ios_options, function(opts){
15594 opts.el.dom.removeAttribute('selected');
15596 if(opts.data[this.valueField] != v){
15600 opts.el.dom.setAttribute('selected', true);
15606 * @cfg {Boolean} grow
15610 * @cfg {Number} growMin
15614 * @cfg {Number} growMax
15623 Roo.apply(Roo.bootstrap.ComboBox, {
15627 cls: 'modal-header',
15649 cls: 'list-group-item',
15653 cls: 'roo-combobox-list-group-item-value'
15657 cls: 'roo-combobox-list-group-item-box pull-xs-right radio-inline radio radio-info',
15671 listItemCheckbox : {
15673 cls: 'list-group-item',
15677 cls: 'roo-combobox-list-group-item-value'
15681 cls: 'roo-combobox-list-group-item-box pull-xs-right checkbox-inline checkbox checkbox-info',
15697 cls: 'alert alert-danger roo-combobox-touch-view-empty-result'
15702 cls: 'modal-footer',
15710 cls: 'col-xs-6 text-left',
15713 cls: 'btn btn-danger roo-touch-view-cancel',
15719 cls: 'col-xs-6 text-right',
15722 cls: 'btn btn-success roo-touch-view-ok',
15733 Roo.apply(Roo.bootstrap.ComboBox, {
15735 touchViewTemplate : {
15737 cls: 'modal fade roo-combobox-touch-view',
15741 cls: 'modal-dialog',
15742 style : 'position:fixed', // we have to fix position....
15746 cls: 'modal-content',
15748 Roo.bootstrap.ComboBox.header,
15749 Roo.bootstrap.ComboBox.body,
15750 Roo.bootstrap.ComboBox.footer
15759 * Ext JS Library 1.1.1
15760 * Copyright(c) 2006-2007, Ext JS, LLC.
15762 * Originally Released Under LGPL - original licence link has changed is not relivant.
15765 * <script type="text/javascript">
15770 * @extends Roo.util.Observable
15771 * Create a "View" for an element based on a data model or UpdateManager and the supplied DomHelper template.
15772 * This class also supports single and multi selection modes. <br>
15773 * Create a data model bound view:
15775 var store = new Roo.data.Store(...);
15777 var view = new Roo.View({
15779 tpl : '<div id="{0}">{2} - {1}</div>', // auto create template
15781 singleSelect: true,
15782 selectedClass: "ydataview-selected",
15786 // listen for node click?
15787 view.on("click", function(vw, index, node, e){
15788 alert('Node "' + node.id + '" at index: ' + index + " was clicked.");
15792 dataModel.load("foobar.xml");
15794 For an example of creating a JSON/UpdateManager view, see {@link Roo.JsonView}.
15796 * <b>Note: The root of your template must be a single node. Table/row implementations may work but are not supported due to
15797 * IE"s limited insertion support with tables and Opera"s faulty event bubbling.</b>
15799 * Note: old style constructor is still suported (container, template, config)
15802 * Create a new View
15803 * @param {Object} config The config object
15806 Roo.View = function(config, depreciated_tpl, depreciated_config){
15808 this.parent = false;
15810 if (typeof(depreciated_tpl) == 'undefined') {
15811 // new way.. - universal constructor.
15812 Roo.apply(this, config);
15813 this.el = Roo.get(this.el);
15816 this.el = Roo.get(config);
15817 this.tpl = depreciated_tpl;
15818 Roo.apply(this, depreciated_config);
15820 this.wrapEl = this.el.wrap().wrap();
15821 ///this.el = this.wrapEla.appendChild(document.createElement("div"));
15824 if(typeof(this.tpl) == "string"){
15825 this.tpl = new Roo.Template(this.tpl);
15827 // support xtype ctors..
15828 this.tpl = new Roo.factory(this.tpl, Roo);
15832 this.tpl.compile();
15837 * @event beforeclick
15838 * Fires before a click is processed. Returns false to cancel the default action.
15839 * @param {Roo.View} this
15840 * @param {Number} index The index of the target node
15841 * @param {HTMLElement} node The target node
15842 * @param {Roo.EventObject} e The raw event object
15844 "beforeclick" : true,
15847 * Fires when a template node is clicked.
15848 * @param {Roo.View} this
15849 * @param {Number} index The index of the target node
15850 * @param {HTMLElement} node The target node
15851 * @param {Roo.EventObject} e The raw event object
15856 * Fires when a template node is double clicked.
15857 * @param {Roo.View} this
15858 * @param {Number} index The index of the target node
15859 * @param {HTMLElement} node The target node
15860 * @param {Roo.EventObject} e The raw event object
15864 * @event contextmenu
15865 * Fires when a template node is right clicked.
15866 * @param {Roo.View} this
15867 * @param {Number} index The index of the target node
15868 * @param {HTMLElement} node The target node
15869 * @param {Roo.EventObject} e The raw event object
15871 "contextmenu" : true,
15873 * @event selectionchange
15874 * Fires when the selected nodes change.
15875 * @param {Roo.View} this
15876 * @param {Array} selections Array of the selected nodes
15878 "selectionchange" : true,
15881 * @event beforeselect
15882 * Fires before a selection is made. If any handlers return false, the selection is cancelled.
15883 * @param {Roo.View} this
15884 * @param {HTMLElement} node The node to be selected
15885 * @param {Array} selections Array of currently selected nodes
15887 "beforeselect" : true,
15889 * @event preparedata
15890 * Fires on every row to render, to allow you to change the data.
15891 * @param {Roo.View} this
15892 * @param {Object} data to be rendered (change this)
15894 "preparedata" : true
15902 "click": this.onClick,
15903 "dblclick": this.onDblClick,
15904 "contextmenu": this.onContextMenu,
15908 this.selections = [];
15910 this.cmp = new Roo.CompositeElementLite([]);
15912 this.store = Roo.factory(this.store, Roo.data);
15913 this.setStore(this.store, true);
15916 if ( this.footer && this.footer.xtype) {
15918 var fctr = this.wrapEl.appendChild(document.createElement("div"));
15920 this.footer.dataSource = this.store;
15921 this.footer.container = fctr;
15922 this.footer = Roo.factory(this.footer, Roo);
15923 fctr.insertFirst(this.el);
15925 // this is a bit insane - as the paging toolbar seems to detach the el..
15926 // dom.parentNode.parentNode.parentNode
15927 // they get detached?
15931 Roo.View.superclass.constructor.call(this);
15936 Roo.extend(Roo.View, Roo.util.Observable, {
15939 * @cfg {Roo.data.Store} store Data store to load data from.
15944 * @cfg {String|Roo.Element} el The container element.
15949 * @cfg {String|Roo.Template} tpl The template used by this View
15953 * @cfg {String} dataName the named area of the template to use as the data area
15954 * Works with domtemplates roo-name="name"
15958 * @cfg {String} selectedClass The css class to add to selected nodes
15960 selectedClass : "x-view-selected",
15962 * @cfg {String} emptyText The empty text to show when nothing is loaded.
15967 * @cfg {String} text to display on mask (default Loading)
15971 * @cfg {Boolean} multiSelect Allow multiple selection
15973 multiSelect : false,
15975 * @cfg {Boolean} singleSelect Allow single selection
15977 singleSelect: false,
15980 * @cfg {Boolean} toggleSelect - selecting
15982 toggleSelect : false,
15985 * @cfg {Boolean} tickable - selecting
15990 * Returns the element this view is bound to.
15991 * @return {Roo.Element}
15993 getEl : function(){
15994 return this.wrapEl;
16000 * Refreshes the view. - called by datachanged on the store. - do not call directly.
16002 refresh : function(){
16003 //Roo.log('refresh');
16006 // if we are using something like 'domtemplate', then
16007 // the what gets used is:
16008 // t.applySubtemplate(NAME, data, wrapping data..)
16009 // the outer template then get' applied with
16010 // the store 'extra data'
16011 // and the body get's added to the
16012 // roo-name="data" node?
16013 // <span class='roo-tpl-{name}'></span> ?????
16017 this.clearSelections();
16018 this.el.update("");
16020 var records = this.store.getRange();
16021 if(records.length < 1) {
16023 // is this valid?? = should it render a template??
16025 this.el.update(this.emptyText);
16029 if (this.dataName) {
16030 this.el.update(t.apply(this.store.meta)); //????
16031 el = this.el.child('.roo-tpl-' + this.dataName);
16034 for(var i = 0, len = records.length; i < len; i++){
16035 var data = this.prepareData(records[i].data, i, records[i]);
16036 this.fireEvent("preparedata", this, data, i, records[i]);
16038 var d = Roo.apply({}, data);
16041 Roo.apply(d, {'roo-id' : Roo.id()});
16045 Roo.each(this.parent.item, function(item){
16046 if(item[_this.parent.valueField] != data[_this.parent.valueField]){
16049 Roo.apply(d, {'roo-data-checked' : 'checked'});
16053 html[html.length] = Roo.util.Format.trim(
16055 t.applySubtemplate(this.dataName, d, this.store.meta) :
16062 el.update(html.join(""));
16063 this.nodes = el.dom.childNodes;
16064 this.updateIndexes(0);
16069 * Function to override to reformat the data that is sent to
16070 * the template for each node.
16071 * DEPRICATED - use the preparedata event handler.
16072 * @param {Array/Object} data The raw data (array of colData for a data model bound view or
16073 * a JSON object for an UpdateManager bound view).
16075 prepareData : function(data, index, record)
16077 this.fireEvent("preparedata", this, data, index, record);
16081 onUpdate : function(ds, record){
16082 // Roo.log('on update');
16083 this.clearSelections();
16084 var index = this.store.indexOf(record);
16085 var n = this.nodes[index];
16086 this.tpl.insertBefore(n, this.prepareData(record.data, index, record));
16087 n.parentNode.removeChild(n);
16088 this.updateIndexes(index, index);
16094 onAdd : function(ds, records, index)
16096 //Roo.log(['on Add', ds, records, index] );
16097 this.clearSelections();
16098 if(this.nodes.length == 0){
16102 var n = this.nodes[index];
16103 for(var i = 0, len = records.length; i < len; i++){
16104 var d = this.prepareData(records[i].data, i, records[i]);
16106 this.tpl.insertBefore(n, d);
16109 this.tpl.append(this.el, d);
16112 this.updateIndexes(index);
16115 onRemove : function(ds, record, index){
16116 // Roo.log('onRemove');
16117 this.clearSelections();
16118 var el = this.dataName ?
16119 this.el.child('.roo-tpl-' + this.dataName) :
16122 el.dom.removeChild(this.nodes[index]);
16123 this.updateIndexes(index);
16127 * Refresh an individual node.
16128 * @param {Number} index
16130 refreshNode : function(index){
16131 this.onUpdate(this.store, this.store.getAt(index));
16134 updateIndexes : function(startIndex, endIndex){
16135 var ns = this.nodes;
16136 startIndex = startIndex || 0;
16137 endIndex = endIndex || ns.length - 1;
16138 for(var i = startIndex; i <= endIndex; i++){
16139 ns[i].nodeIndex = i;
16144 * Changes the data store this view uses and refresh the view.
16145 * @param {Store} store
16147 setStore : function(store, initial){
16148 if(!initial && this.store){
16149 this.store.un("datachanged", this.refresh);
16150 this.store.un("add", this.onAdd);
16151 this.store.un("remove", this.onRemove);
16152 this.store.un("update", this.onUpdate);
16153 this.store.un("clear", this.refresh);
16154 this.store.un("beforeload", this.onBeforeLoad);
16155 this.store.un("load", this.onLoad);
16156 this.store.un("loadexception", this.onLoad);
16160 store.on("datachanged", this.refresh, this);
16161 store.on("add", this.onAdd, this);
16162 store.on("remove", this.onRemove, this);
16163 store.on("update", this.onUpdate, this);
16164 store.on("clear", this.refresh, this);
16165 store.on("beforeload", this.onBeforeLoad, this);
16166 store.on("load", this.onLoad, this);
16167 store.on("loadexception", this.onLoad, this);
16175 * onbeforeLoad - masks the loading area.
16178 onBeforeLoad : function(store,opts)
16180 //Roo.log('onBeforeLoad');
16182 this.el.update("");
16184 this.el.mask(this.mask ? this.mask : "Loading" );
16186 onLoad : function ()
16193 * Returns the template node the passed child belongs to or null if it doesn't belong to one.
16194 * @param {HTMLElement} node
16195 * @return {HTMLElement} The template node
16197 findItemFromChild : function(node){
16198 var el = this.dataName ?
16199 this.el.child('.roo-tpl-' + this.dataName,true) :
16202 if(!node || node.parentNode == el){
16205 var p = node.parentNode;
16206 while(p && p != el){
16207 if(p.parentNode == el){
16216 onClick : function(e){
16217 var item = this.findItemFromChild(e.getTarget());
16219 var index = this.indexOf(item);
16220 if(this.onItemClick(item, index, e) !== false){
16221 this.fireEvent("click", this, index, item, e);
16224 this.clearSelections();
16229 onContextMenu : function(e){
16230 var item = this.findItemFromChild(e.getTarget());
16232 this.fireEvent("contextmenu", this, this.indexOf(item), item, e);
16237 onDblClick : function(e){
16238 var item = this.findItemFromChild(e.getTarget());
16240 this.fireEvent("dblclick", this, this.indexOf(item), item, e);
16244 onItemClick : function(item, index, e)
16246 if(this.fireEvent("beforeclick", this, index, item, e) === false){
16249 if (this.toggleSelect) {
16250 var m = this.isSelected(item) ? 'unselect' : 'select';
16253 _t[m](item, true, false);
16256 if(this.multiSelect || this.singleSelect){
16257 if(this.multiSelect && e.shiftKey && this.lastSelection){
16258 this.select(this.getNodes(this.indexOf(this.lastSelection), index), false);
16260 this.select(item, this.multiSelect && e.ctrlKey);
16261 this.lastSelection = item;
16264 if(!this.tickable){
16265 e.preventDefault();
16273 * Get the number of selected nodes.
16276 getSelectionCount : function(){
16277 return this.selections.length;
16281 * Get the currently selected nodes.
16282 * @return {Array} An array of HTMLElements
16284 getSelectedNodes : function(){
16285 return this.selections;
16289 * Get the indexes of the selected nodes.
16292 getSelectedIndexes : function(){
16293 var indexes = [], s = this.selections;
16294 for(var i = 0, len = s.length; i < len; i++){
16295 indexes.push(s[i].nodeIndex);
16301 * Clear all selections
16302 * @param {Boolean} suppressEvent (optional) true to skip firing of the selectionchange event
16304 clearSelections : function(suppressEvent){
16305 if(this.nodes && (this.multiSelect || this.singleSelect) && this.selections.length > 0){
16306 this.cmp.elements = this.selections;
16307 this.cmp.removeClass(this.selectedClass);
16308 this.selections = [];
16309 if(!suppressEvent){
16310 this.fireEvent("selectionchange", this, this.selections);
16316 * Returns true if the passed node is selected
16317 * @param {HTMLElement/Number} node The node or node index
16318 * @return {Boolean}
16320 isSelected : function(node){
16321 var s = this.selections;
16325 node = this.getNode(node);
16326 return s.indexOf(node) !== -1;
16331 * @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
16332 * @param {Boolean} keepExisting (optional) true to keep existing selections
16333 * @param {Boolean} suppressEvent (optional) true to skip firing of the selectionchange vent
16335 select : function(nodeInfo, keepExisting, suppressEvent){
16336 if(nodeInfo instanceof Array){
16338 this.clearSelections(true);
16340 for(var i = 0, len = nodeInfo.length; i < len; i++){
16341 this.select(nodeInfo[i], true, true);
16345 var node = this.getNode(nodeInfo);
16346 if(!node || this.isSelected(node)){
16347 return; // already selected.
16350 this.clearSelections(true);
16353 if(this.fireEvent("beforeselect", this, node, this.selections) !== false){
16354 Roo.fly(node).addClass(this.selectedClass);
16355 this.selections.push(node);
16356 if(!suppressEvent){
16357 this.fireEvent("selectionchange", this, this.selections);
16365 * @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
16366 * @param {Boolean} keepExisting (optional) true IGNORED (for campatibility with select)
16367 * @param {Boolean} suppressEvent (optional) true to skip firing of the selectionchange vent
16369 unselect : function(nodeInfo, keepExisting, suppressEvent)
16371 if(nodeInfo instanceof Array){
16372 Roo.each(this.selections, function(s) {
16373 this.unselect(s, nodeInfo);
16377 var node = this.getNode(nodeInfo);
16378 if(!node || !this.isSelected(node)){
16379 //Roo.log("not selected");
16380 return; // not selected.
16384 Roo.each(this.selections, function(s) {
16386 Roo.fly(node).removeClass(this.selectedClass);
16393 this.selections= ns;
16394 this.fireEvent("selectionchange", this, this.selections);
16398 * Gets a template node.
16399 * @param {HTMLElement/String/Number} nodeInfo An HTMLElement template node, index of a template node or the id of a template node
16400 * @return {HTMLElement} The node or null if it wasn't found
16402 getNode : function(nodeInfo){
16403 if(typeof nodeInfo == "string"){
16404 return document.getElementById(nodeInfo);
16405 }else if(typeof nodeInfo == "number"){
16406 return this.nodes[nodeInfo];
16412 * Gets a range template nodes.
16413 * @param {Number} startIndex
16414 * @param {Number} endIndex
16415 * @return {Array} An array of nodes
16417 getNodes : function(start, end){
16418 var ns = this.nodes;
16419 start = start || 0;
16420 end = typeof end == "undefined" ? ns.length - 1 : end;
16423 for(var i = start; i <= end; i++){
16427 for(var i = start; i >= end; i--){
16435 * Finds the index of the passed node
16436 * @param {HTMLElement/String/Number} nodeInfo An HTMLElement template node, index of a template node or the id of a template node
16437 * @return {Number} The index of the node or -1
16439 indexOf : function(node){
16440 node = this.getNode(node);
16441 if(typeof node.nodeIndex == "number"){
16442 return node.nodeIndex;
16444 var ns = this.nodes;
16445 for(var i = 0, len = ns.length; i < len; i++){
16456 * based on jquery fullcalendar
16460 Roo.bootstrap = Roo.bootstrap || {};
16462 * @class Roo.bootstrap.Calendar
16463 * @extends Roo.bootstrap.Component
16464 * Bootstrap Calendar class
16465 * @cfg {Boolean} loadMask (true|false) default false
16466 * @cfg {Object} header generate the user specific header of the calendar, default false
16469 * Create a new Container
16470 * @param {Object} config The config object
16475 Roo.bootstrap.Calendar = function(config){
16476 Roo.bootstrap.Calendar.superclass.constructor.call(this, config);
16480 * Fires when a date is selected
16481 * @param {DatePicker} this
16482 * @param {Date} date The selected date
16486 * @event monthchange
16487 * Fires when the displayed month changes
16488 * @param {DatePicker} this
16489 * @param {Date} date The selected month
16491 'monthchange': true,
16493 * @event evententer
16494 * Fires when mouse over an event
16495 * @param {Calendar} this
16496 * @param {event} Event
16498 'evententer': true,
16500 * @event eventleave
16501 * Fires when the mouse leaves an
16502 * @param {Calendar} this
16505 'eventleave': true,
16507 * @event eventclick
16508 * Fires when the mouse click an
16509 * @param {Calendar} this
16518 Roo.extend(Roo.bootstrap.Calendar, Roo.bootstrap.Component, {
16521 * @cfg {Number} startDay
16522 * Day index at which the week should begin, 0-based (defaults to 0, which is Sunday)
16530 getAutoCreate : function(){
16533 var fc_button = function(name, corner, style, content ) {
16534 return Roo.apply({},{
16536 cls : 'fc-button fc-button-'+name+' fc-state-default ' +
16538 'fc-corner-' + corner.split(' ').join(' fc-corner-') :
16541 html : '<SPAN class="fc-text-'+style+ '">'+content +'</SPAN>',
16552 style : 'width:100%',
16559 cls : 'fc-header-left',
16561 fc_button('prev', 'left', 'arrow', '‹' ),
16562 fc_button('next', 'right', 'arrow', '›' ),
16563 { tag: 'span', cls: 'fc-header-space' },
16564 fc_button('today', 'left right', '', 'today' ) // neds state disabled..
16572 cls : 'fc-header-center',
16576 cls: 'fc-header-title',
16579 html : 'month / year'
16587 cls : 'fc-header-right',
16589 /* fc_button('month', 'left', '', 'month' ),
16590 fc_button('week', '', '', 'week' ),
16591 fc_button('day', 'right', '', 'day' )
16603 header = this.header;
16606 var cal_heads = function() {
16608 // fixme - handle this.
16610 for (var i =0; i < Date.dayNames.length; i++) {
16611 var d = Date.dayNames[i];
16614 cls : 'fc-day-header fc-' + d.substring(0,3).toLowerCase() + ' fc-widget-header',
16615 html : d.substring(0,3)
16619 ret[0].cls += ' fc-first';
16620 ret[6].cls += ' fc-last';
16623 var cal_cell = function(n) {
16626 cls : 'fc-day fc-'+n + ' fc-widget-content', ///fc-other-month fc-past
16631 cls: 'fc-day-number',
16635 cls: 'fc-day-content',
16639 style: 'position: relative;' // height: 17px;
16651 var cal_rows = function() {
16654 for (var r = 0; r < 6; r++) {
16661 for (var i =0; i < Date.dayNames.length; i++) {
16662 var d = Date.dayNames[i];
16663 row.cn.push(cal_cell(d.substring(0,3).toLowerCase()));
16666 row.cn[0].cls+=' fc-first';
16667 row.cn[0].cn[0].style = 'min-height:90px';
16668 row.cn[6].cls+=' fc-last';
16672 ret[0].cls += ' fc-first';
16673 ret[4].cls += ' fc-prev-last';
16674 ret[5].cls += ' fc-last';
16681 cls: 'fc-border-separate',
16682 style : 'width:100%',
16690 cls : 'fc-first fc-last',
16708 cls : 'fc-content',
16709 style : "position: relative;",
16712 cls : 'fc-view fc-view-month fc-grid',
16713 style : 'position: relative',
16714 unselectable : 'on',
16717 cls : 'fc-event-container',
16718 style : 'position:absolute;z-index:8;top:0;left:0;'
16736 initEvents : function()
16739 throw "can not find store for calendar";
16745 style: "text-align:center",
16749 style: "background-color:white;width:50%;margin:250 auto",
16753 src: Roo.rootURL + '/images/ux/lightbox/loading.gif'
16764 this.maskEl = Roo.DomHelper.append(this.el.select('.fc-content', true).first(), mark, true);
16766 var size = this.el.select('.fc-content', true).first().getSize();
16767 this.maskEl.setSize(size.width, size.height);
16768 this.maskEl.enableDisplayMode("block");
16769 if(!this.loadMask){
16770 this.maskEl.hide();
16773 this.store = Roo.factory(this.store, Roo.data);
16774 this.store.on('load', this.onLoad, this);
16775 this.store.on('beforeload', this.onBeforeLoad, this);
16779 this.cells = this.el.select('.fc-day',true);
16780 //Roo.log(this.cells);
16781 this.textNodes = this.el.query('.fc-day-number');
16782 this.cells.addClassOnOver('fc-state-hover');
16784 this.el.select('.fc-button-prev',true).on('click', this.showPrevMonth, this);
16785 this.el.select('.fc-button-next',true).on('click', this.showNextMonth, this);
16786 this.el.select('.fc-button-today',true).on('click', this.showToday, this);
16787 this.el.select('.fc-button',true).addClassOnOver('fc-state-hover');
16789 this.on('monthchange', this.onMonthChange, this);
16791 this.update(new Date().clearTime());
16794 resize : function() {
16795 var sz = this.el.getSize();
16797 this.el.select('.fc-day-header',true).setWidth(sz.width / 7);
16798 this.el.select('.fc-day-content div',true).setHeight(34);
16803 showPrevMonth : function(e){
16804 this.update(this.activeDate.add("mo", -1));
16806 showToday : function(e){
16807 this.update(new Date().clearTime());
16810 showNextMonth : function(e){
16811 this.update(this.activeDate.add("mo", 1));
16815 showPrevYear : function(){
16816 this.update(this.activeDate.add("y", -1));
16820 showNextYear : function(){
16821 this.update(this.activeDate.add("y", 1));
16826 update : function(date)
16828 var vd = this.activeDate;
16829 this.activeDate = date;
16830 // if(vd && this.el){
16831 // var t = date.getTime();
16832 // if(vd.getMonth() == date.getMonth() && vd.getFullYear() == date.getFullYear()){
16833 // Roo.log('using add remove');
16835 // this.fireEvent('monthchange', this, date);
16837 // this.cells.removeClass("fc-state-highlight");
16838 // this.cells.each(function(c){
16839 // if(c.dateValue == t){
16840 // c.addClass("fc-state-highlight");
16841 // setTimeout(function(){
16842 // try{c.dom.firstChild.focus();}catch(e){}
16852 var days = date.getDaysInMonth();
16854 var firstOfMonth = date.getFirstDateOfMonth();
16855 var startingPos = firstOfMonth.getDay()-this.startDay;
16857 if(startingPos < this.startDay){
16861 var pm = date.add(Date.MONTH, -1);
16862 var prevStart = pm.getDaysInMonth()-startingPos;
16864 this.cells = this.el.select('.fc-day',true);
16865 this.textNodes = this.el.query('.fc-day-number');
16866 this.cells.addClassOnOver('fc-state-hover');
16868 var cells = this.cells.elements;
16869 var textEls = this.textNodes;
16871 Roo.each(cells, function(cell){
16872 cell.removeClass([ 'fc-past', 'fc-other-month', 'fc-future', 'fc-state-highlight', 'fc-state-disabled']);
16875 days += startingPos;
16877 // convert everything to numbers so it's fast
16878 var day = 86400000;
16879 var d = (new Date(pm.getFullYear(), pm.getMonth(), prevStart)).clearTime();
16882 //Roo.log(prevStart);
16884 var today = new Date().clearTime().getTime();
16885 var sel = date.clearTime().getTime();
16886 var min = this.minDate ? this.minDate.clearTime() : Number.NEGATIVE_INFINITY;
16887 var max = this.maxDate ? this.maxDate.clearTime() : Number.POSITIVE_INFINITY;
16888 var ddMatch = this.disabledDatesRE;
16889 var ddText = this.disabledDatesText;
16890 var ddays = this.disabledDays ? this.disabledDays.join("") : false;
16891 var ddaysText = this.disabledDaysText;
16892 var format = this.format;
16894 var setCellClass = function(cal, cell){
16898 //Roo.log('set Cell Class');
16900 var t = d.getTime();
16904 cell.dateValue = t;
16906 cell.className += " fc-today";
16907 cell.className += " fc-state-highlight";
16908 cell.title = cal.todayText;
16911 // disable highlight in other month..
16912 //cell.className += " fc-state-highlight";
16917 cell.className = " fc-state-disabled";
16918 cell.title = cal.minText;
16922 cell.className = " fc-state-disabled";
16923 cell.title = cal.maxText;
16927 if(ddays.indexOf(d.getDay()) != -1){
16928 cell.title = ddaysText;
16929 cell.className = " fc-state-disabled";
16932 if(ddMatch && format){
16933 var fvalue = d.dateFormat(format);
16934 if(ddMatch.test(fvalue)){
16935 cell.title = ddText.replace("%0", fvalue);
16936 cell.className = " fc-state-disabled";
16940 if (!cell.initialClassName) {
16941 cell.initialClassName = cell.dom.className;
16944 cell.dom.className = cell.initialClassName + ' ' + cell.className;
16949 for(; i < startingPos; i++) {
16950 textEls[i].innerHTML = (++prevStart);
16951 d.setDate(d.getDate()+1);
16953 cells[i].className = "fc-past fc-other-month";
16954 setCellClass(this, cells[i]);
16959 for(; i < days; i++){
16960 intDay = i - startingPos + 1;
16961 textEls[i].innerHTML = (intDay);
16962 d.setDate(d.getDate()+1);
16964 cells[i].className = ''; // "x-date-active";
16965 setCellClass(this, cells[i]);
16969 for(; i < 42; i++) {
16970 textEls[i].innerHTML = (++extraDays);
16971 d.setDate(d.getDate()+1);
16973 cells[i].className = "fc-future fc-other-month";
16974 setCellClass(this, cells[i]);
16977 this.el.select('.fc-header-title h2',true).update(Date.monthNames[date.getMonth()] + " " + date.getFullYear());
16979 var totalRows = Math.ceil((date.getDaysInMonth() + date.getFirstDateOfMonth().getDay()) / 7);
16981 this.el.select('tr.fc-week.fc-prev-last',true).removeClass('fc-last');
16982 this.el.select('tr.fc-week.fc-next-last',true).addClass('fc-last').show();
16984 if(totalRows != 6){
16985 this.el.select('tr.fc-week.fc-last',true).removeClass('fc-last').addClass('fc-next-last').hide();
16986 this.el.select('tr.fc-week.fc-prev-last',true).addClass('fc-last');
16989 this.fireEvent('monthchange', this, date);
16993 if(!this.internalRender){
16994 var main = this.el.dom.firstChild;
16995 var w = main.offsetWidth;
16996 this.el.setWidth(w + this.el.getBorderWidth("lr"));
16997 Roo.fly(main).setWidth(w);
16998 this.internalRender = true;
16999 // opera does not respect the auto grow header center column
17000 // then, after it gets a width opera refuses to recalculate
17001 // without a second pass
17002 if(Roo.isOpera && !this.secondPass){
17003 main.rows[0].cells[1].style.width = (w - (main.rows[0].cells[0].offsetWidth+main.rows[0].cells[2].offsetWidth)) + "px";
17004 this.secondPass = true;
17005 this.update.defer(10, this, [date]);
17012 findCell : function(dt) {
17013 dt = dt.clearTime().getTime();
17015 this.cells.each(function(c){
17016 //Roo.log("check " +c.dateValue + '?=' + dt);
17017 if(c.dateValue == dt){
17027 findCells : function(ev) {
17028 var s = ev.start.clone().clearTime().getTime();
17030 var e= ev.end.clone().clearTime().getTime();
17033 this.cells.each(function(c){
17034 ////Roo.log("check " +c.dateValue + '<' + e + ' > ' + s);
17036 if(c.dateValue > e){
17039 if(c.dateValue < s){
17048 // findBestRow: function(cells)
17052 // for (var i =0 ; i < cells.length;i++) {
17053 // ret = Math.max(cells[i].rows || 0,ret);
17060 addItem : function(ev)
17062 // look for vertical location slot in
17063 var cells = this.findCells(ev);
17065 // ev.row = this.findBestRow(cells);
17067 // work out the location.
17071 for(var i =0; i < cells.length; i++) {
17073 cells[i].row = cells[0].row;
17076 cells[i].row = cells[i].row + 1;
17086 if (crow.start.getY() == cells[i].getY()) {
17088 crow.end = cells[i];
17105 cells[0].events.push(ev);
17107 this.calevents.push(ev);
17110 clearEvents: function() {
17112 if(!this.calevents){
17116 Roo.each(this.cells.elements, function(c){
17122 Roo.each(this.calevents, function(e) {
17123 Roo.each(e.els, function(el) {
17124 el.un('mouseenter' ,this.onEventEnter, this);
17125 el.un('mouseleave' ,this.onEventLeave, this);
17130 Roo.each(Roo.select('.fc-more-event', true).elements, function(e){
17136 renderEvents: function()
17140 this.cells.each(function(c) {
17149 if(c.row != c.events.length){
17150 r = 4 - (4 - (c.row - c.events.length));
17153 c.events = ev.slice(0, r);
17154 c.more = ev.slice(r);
17156 if(c.more.length && c.more.length == 1){
17157 c.events.push(c.more.pop());
17160 c.row = (c.row - ev.length) + c.events.length + ((c.more.length) ? 1 : 0);
17164 this.cells.each(function(c) {
17166 c.select('.fc-day-content div',true).first().setHeight(Math.max(34, c.row * 20));
17169 for (var e = 0; e < c.events.length; e++){
17170 var ev = c.events[e];
17171 var rows = ev.rows;
17173 for(var i = 0; i < rows.length; i++) {
17175 // how many rows should it span..
17178 cls : 'roo-dynamic fc-event fc-event-hori fc-event-draggable ui-draggable',
17179 style : 'position: absolute', // left: 387px; width: 121px; top: 359px;
17181 unselectable : "on",
17184 cls: 'fc-event-inner',
17188 // cls: 'fc-event-time',
17189 // html : cells.length > 1 ? '' : ev.time
17193 cls: 'fc-event-title',
17194 html : String.format('{0}', ev.title)
17201 cls: 'ui-resizable-handle ui-resizable-e',
17202 html : '  '
17209 cfg.cls += ' fc-event-start';
17211 if ((i+1) == rows.length) {
17212 cfg.cls += ' fc-event-end';
17215 var ctr = _this.el.select('.fc-event-container',true).first();
17216 var cg = ctr.createChild(cfg);
17218 var sbox = rows[i].start.select('.fc-day-content',true).first().getBox();
17219 var ebox = rows[i].end.select('.fc-day-content',true).first().getBox();
17221 var r = (c.more.length) ? 1 : 0;
17222 cg.setXY([sbox.x +2, sbox.y + ((c.row - c.events.length - r + e) * 20)]);
17223 cg.setWidth(ebox.right - sbox.x -2);
17225 cg.on('mouseenter' ,_this.onEventEnter, _this, ev);
17226 cg.on('mouseleave' ,_this.onEventLeave, _this, ev);
17227 cg.on('click', _this.onEventClick, _this, ev);
17238 cls : 'fc-more-event roo-dynamic fc-event fc-event-hori fc-event-draggable ui-draggable fc-event-start fc-event-end',
17239 style : 'position: absolute',
17240 unselectable : "on",
17243 cls: 'fc-event-inner',
17247 cls: 'fc-event-title',
17255 cls: 'ui-resizable-handle ui-resizable-e',
17256 html : '  '
17262 var ctr = _this.el.select('.fc-event-container',true).first();
17263 var cg = ctr.createChild(cfg);
17265 var sbox = c.select('.fc-day-content',true).first().getBox();
17266 var ebox = c.select('.fc-day-content',true).first().getBox();
17268 cg.setXY([sbox.x +2, sbox.y +((c.row - 1) * 20)]);
17269 cg.setWidth(ebox.right - sbox.x -2);
17271 cg.on('click', _this.onMoreEventClick, _this, c.more);
17281 onEventEnter: function (e, el,event,d) {
17282 this.fireEvent('evententer', this, el, event);
17285 onEventLeave: function (e, el,event,d) {
17286 this.fireEvent('eventleave', this, el, event);
17289 onEventClick: function (e, el,event,d) {
17290 this.fireEvent('eventclick', this, el, event);
17293 onMonthChange: function () {
17297 onMoreEventClick: function(e, el, more)
17301 this.calpopover.placement = 'right';
17302 this.calpopover.setTitle('More');
17304 this.calpopover.setContent('');
17306 var ctr = this.calpopover.el.select('.popover-content', true).first();
17308 Roo.each(more, function(m){
17310 cls : 'fc-event-hori fc-event-draggable',
17313 var cg = ctr.createChild(cfg);
17315 cg.on('click', _this.onEventClick, _this, m);
17318 this.calpopover.show(el);
17323 onLoad: function ()
17325 this.calevents = [];
17328 if(this.store.getCount() > 0){
17329 this.store.data.each(function(d){
17332 start: (typeof(d.data.start_dt) === 'string') ? new Date.parseDate(d.data.start_dt, 'Y-m-d H:i:s') : d.data.start_dt,
17333 end : (typeof(d.data.end_dt) === 'string') ? new Date.parseDate(d.data.end_dt, 'Y-m-d H:i:s') : d.data.end_dt,
17334 time : d.data.start_time,
17335 title : d.data.title,
17336 description : d.data.description,
17337 venue : d.data.venue
17342 this.renderEvents();
17344 if(this.calevents.length && this.loadMask){
17345 this.maskEl.hide();
17349 onBeforeLoad: function()
17351 this.clearEvents();
17353 this.maskEl.show();
17367 * @class Roo.bootstrap.Popover
17368 * @extends Roo.bootstrap.Component
17369 * Bootstrap Popover class
17370 * @cfg {String} html contents of the popover (or false to use children..)
17371 * @cfg {String} title of popover (or false to hide)
17372 * @cfg {String} placement how it is placed
17373 * @cfg {String} trigger click || hover (or false to trigger manually)
17374 * @cfg {String} over what (parent or false to trigger manually.)
17375 * @cfg {Number} delay - delay before showing
17378 * Create a new Popover
17379 * @param {Object} config The config object
17382 Roo.bootstrap.Popover = function(config){
17383 Roo.bootstrap.Popover.superclass.constructor.call(this, config);
17389 * After the popover show
17391 * @param {Roo.bootstrap.Popover} this
17396 * After the popover hide
17398 * @param {Roo.bootstrap.Popover} this
17404 Roo.extend(Roo.bootstrap.Popover, Roo.bootstrap.Component, {
17406 title: 'Fill in a title',
17409 placement : 'right',
17410 trigger : 'hover', // hover
17416 can_build_overlaid : false,
17418 getChildContainer : function()
17420 return this.el.select('.popover-content',true).first();
17423 getAutoCreate : function(){
17426 cls : 'popover roo-dynamic',
17427 style: 'display:block',
17433 cls : 'popover-inner',
17437 cls: 'popover-title',
17441 cls : 'popover-content',
17452 setTitle: function(str)
17455 this.el.select('.popover-title',true).first().dom.innerHTML = str;
17457 setContent: function(str)
17460 this.el.select('.popover-content',true).first().dom.innerHTML = str;
17462 // as it get's added to the bottom of the page.
17463 onRender : function(ct, position)
17465 Roo.bootstrap.Component.superclass.onRender.call(this, ct, position);
17467 var cfg = Roo.apply({}, this.getAutoCreate());
17471 cfg.cls += ' ' + this.cls;
17474 cfg.style = this.style;
17476 //Roo.log("adding to ");
17477 this.el = Roo.get(document.body).createChild(cfg, position);
17478 // Roo.log(this.el);
17483 initEvents : function()
17485 this.el.select('.popover-title',true).setVisibilityMode(Roo.Element.DISPLAY);
17486 this.el.enableDisplayMode('block');
17488 if (this.over === false) {
17491 if (this.triggers === false) {
17494 var on_el = (this.over == 'parent') ? this.parent().el : Roo.get(this.over);
17495 var triggers = this.trigger ? this.trigger.split(' ') : [];
17496 Roo.each(triggers, function(trigger) {
17498 if (trigger == 'click') {
17499 on_el.on('click', this.toggle, this);
17500 } else if (trigger != 'manual') {
17501 var eventIn = trigger == 'hover' ? 'mouseenter' : 'focusin';
17502 var eventOut = trigger == 'hover' ? 'mouseleave' : 'focusout';
17504 on_el.on(eventIn ,this.enter, this);
17505 on_el.on(eventOut, this.leave, this);
17516 toggle : function () {
17517 this.hoverState == 'in' ? this.leave() : this.enter();
17520 enter : function () {
17522 clearTimeout(this.timeout);
17524 this.hoverState = 'in';
17526 if (!this.delay || !this.delay.show) {
17531 this.timeout = setTimeout(function () {
17532 if (_t.hoverState == 'in') {
17535 }, this.delay.show)
17538 leave : function() {
17539 clearTimeout(this.timeout);
17541 this.hoverState = 'out';
17543 if (!this.delay || !this.delay.hide) {
17548 this.timeout = setTimeout(function () {
17549 if (_t.hoverState == 'out') {
17552 }, this.delay.hide)
17555 show : function (on_el)
17558 on_el= (this.over == 'parent') ? this.parent().el : Roo.get(this.over);
17562 this.el.select('.popover-title',true).first().dom.innerHtml = this.title;
17563 if (this.html !== false) {
17564 this.el.select('.popover-content',true).first().dom.innerHtml = this.html;
17566 this.el.removeClass(['fade','top','bottom', 'left', 'right','in']);
17567 if (!this.title.length) {
17568 this.el.select('.popover-title',true).hide();
17571 var placement = typeof this.placement == 'function' ?
17572 this.placement.call(this, this.el, on_el) :
17575 var autoToken = /\s?auto?\s?/i;
17576 var autoPlace = autoToken.test(placement);
17578 placement = placement.replace(autoToken, '') || 'top';
17582 //this.el.setXY([0,0]);
17584 this.el.dom.style.display='block';
17585 this.el.addClass(placement);
17587 //this.el.appendTo(on_el);
17589 var p = this.getPosition();
17590 var box = this.el.getBox();
17595 var align = Roo.bootstrap.Popover.alignment[placement];
17598 this.el.alignTo(on_el, align[0],align[1]);
17599 //var arrow = this.el.select('.arrow',true).first();
17600 //arrow.set(align[2],
17602 this.el.addClass('in');
17605 if (this.el.hasClass('fade')) {
17609 this.hoverState = 'in';
17611 this.fireEvent('show', this);
17616 this.el.setXY([0,0]);
17617 this.el.removeClass('in');
17619 this.hoverState = null;
17621 this.fireEvent('hide', this);
17626 Roo.bootstrap.Popover.alignment = {
17627 'left' : ['r-l', [-10,0], 'right'],
17628 'right' : ['l-r', [10,0], 'left'],
17629 'bottom' : ['t-b', [0,10], 'top'],
17630 'top' : [ 'b-t', [0,-10], 'bottom']
17641 * @class Roo.bootstrap.Progress
17642 * @extends Roo.bootstrap.Component
17643 * Bootstrap Progress class
17644 * @cfg {Boolean} striped striped of the progress bar
17645 * @cfg {Boolean} active animated of the progress bar
17649 * Create a new Progress
17650 * @param {Object} config The config object
17653 Roo.bootstrap.Progress = function(config){
17654 Roo.bootstrap.Progress.superclass.constructor.call(this, config);
17657 Roo.extend(Roo.bootstrap.Progress, Roo.bootstrap.Component, {
17662 getAutoCreate : function(){
17670 cfg.cls += ' progress-striped';
17674 cfg.cls += ' active';
17693 * @class Roo.bootstrap.ProgressBar
17694 * @extends Roo.bootstrap.Component
17695 * Bootstrap ProgressBar class
17696 * @cfg {Number} aria_valuenow aria-value now
17697 * @cfg {Number} aria_valuemin aria-value min
17698 * @cfg {Number} aria_valuemax aria-value max
17699 * @cfg {String} label label for the progress bar
17700 * @cfg {String} panel (success | info | warning | danger )
17701 * @cfg {String} role role of the progress bar
17702 * @cfg {String} sr_only text
17706 * Create a new ProgressBar
17707 * @param {Object} config The config object
17710 Roo.bootstrap.ProgressBar = function(config){
17711 Roo.bootstrap.ProgressBar.superclass.constructor.call(this, config);
17714 Roo.extend(Roo.bootstrap.ProgressBar, Roo.bootstrap.Component, {
17718 aria_valuemax : 100,
17724 getAutoCreate : function()
17729 cls: 'progress-bar',
17730 style: 'width:' + Math.ceil((this.aria_valuenow / this.aria_valuemax) * 100) + '%'
17742 cfg.role = this.role;
17745 if(this.aria_valuenow){
17746 cfg['aria-valuenow'] = this.aria_valuenow;
17749 if(this.aria_valuemin){
17750 cfg['aria-valuemin'] = this.aria_valuemin;
17753 if(this.aria_valuemax){
17754 cfg['aria-valuemax'] = this.aria_valuemax;
17757 if(this.label && !this.sr_only){
17758 cfg.html = this.label;
17762 cfg.cls += ' progress-bar-' + this.panel;
17768 update : function(aria_valuenow)
17770 this.aria_valuenow = aria_valuenow;
17772 this.el.setStyle('width', Math.ceil((this.aria_valuenow / this.aria_valuemax) * 100) + '%');
17787 * @class Roo.bootstrap.TabGroup
17788 * @extends Roo.bootstrap.Column
17789 * Bootstrap Column class
17790 * @cfg {String} navId the navigation id (for use with navbars) - will be auto generated if it does not exist..
17791 * @cfg {Boolean} carousel true to make the group behave like a carousel
17792 * @cfg {Boolean} bullets show bullets for the panels
17793 * @cfg {Boolean} autoslide (true|false) auto slide .. default false
17794 * @cfg {Number} timer auto slide timer .. default 0 millisecond
17795 * @cfg {Boolean} showarrow (true|false) show arrow default true
17798 * Create a new TabGroup
17799 * @param {Object} config The config object
17802 Roo.bootstrap.TabGroup = function(config){
17803 Roo.bootstrap.TabGroup.superclass.constructor.call(this, config);
17805 this.navId = Roo.id();
17808 Roo.bootstrap.TabGroup.register(this);
17812 Roo.extend(Roo.bootstrap.TabGroup, Roo.bootstrap.Column, {
17815 transition : false,
17820 slideOnTouch : false,
17823 getAutoCreate : function()
17825 var cfg = Roo.apply({}, Roo.bootstrap.TabGroup.superclass.getAutoCreate.call(this));
17827 cfg.cls += ' tab-content';
17829 if (this.carousel) {
17830 cfg.cls += ' carousel slide';
17833 cls : 'carousel-inner',
17837 if(this.bullets && !Roo.isTouch){
17840 cls : 'carousel-bullets',
17844 if(this.bullets_cls){
17845 bullets.cls = bullets.cls + ' ' + this.bullets_cls;
17852 cfg.cn[0].cn.push(bullets);
17855 if(this.showarrow){
17856 cfg.cn[0].cn.push({
17858 class : 'carousel-arrow',
17862 class : 'carousel-prev',
17866 class : 'fa fa-chevron-left'
17872 class : 'carousel-next',
17876 class : 'fa fa-chevron-right'
17889 initEvents: function()
17891 // if(Roo.isTouch && this.slideOnTouch && !this.showarrow){
17892 // this.el.on("touchstart", this.onTouchStart, this);
17895 if(this.autoslide){
17898 this.slideFn = window.setInterval(function() {
17899 _this.showPanelNext();
17903 if(this.showarrow){
17904 this.el.select('.carousel-prev', true).first().on('click', this.showPanelPrev, this);
17905 this.el.select('.carousel-next', true).first().on('click', this.showPanelNext, this);
17911 // onTouchStart : function(e, el, o)
17913 // if(!this.slideOnTouch || !Roo.isTouch || Roo.get(e.getTarget()).hasClass('roo-button-text')){
17917 // this.showPanelNext();
17921 getChildContainer : function()
17923 return this.carousel ? this.el.select('.carousel-inner', true).first() : this.el;
17927 * register a Navigation item
17928 * @param {Roo.bootstrap.NavItem} the navitem to add
17930 register : function(item)
17932 this.tabs.push( item);
17933 item.navId = this.navId; // not really needed..
17938 getActivePanel : function()
17941 Roo.each(this.tabs, function(t) {
17951 getPanelByName : function(n)
17954 Roo.each(this.tabs, function(t) {
17955 if (t.tabId == n) {
17963 indexOfPanel : function(p)
17966 Roo.each(this.tabs, function(t,i) {
17967 if (t.tabId == p.tabId) {
17976 * show a specific panel
17977 * @param {Roo.bootstrap.TabPanel|number|string} panel to change to (use the tabId to specify a specific one)
17978 * @return {boolean} false if panel was not shown (invalid entry or beforedeactivate fails.)
17980 showPanel : function (pan)
17982 if(this.transition || typeof(pan) == 'undefined'){
17983 Roo.log("waiting for the transitionend");
17987 if (typeof(pan) == 'number') {
17988 pan = this.tabs[pan];
17991 if (typeof(pan) == 'string') {
17992 pan = this.getPanelByName(pan);
17995 var cur = this.getActivePanel();
17998 Roo.log('pan or acitve pan is undefined');
18002 if (pan.tabId == this.getActivePanel().tabId) {
18006 if (false === cur.fireEvent('beforedeactivate')) {
18010 if(this.bullets > 0 && !Roo.isTouch){
18011 this.setActiveBullet(this.indexOfPanel(pan));
18014 if (this.carousel && typeof(Roo.get(document.body).dom.style.transition) != 'undefined') {
18016 this.transition = true;
18017 var dir = this.indexOfPanel(pan) > this.indexOfPanel(cur) ? 'next' : 'prev';
18018 var lr = dir == 'next' ? 'left' : 'right';
18019 pan.el.addClass(dir); // or prev
18020 pan.el.dom.offsetWidth; // find the offset with - causing a reflow?
18021 cur.el.addClass(lr); // or right
18022 pan.el.addClass(lr);
18025 cur.el.on('transitionend', function() {
18026 Roo.log("trans end?");
18028 pan.el.removeClass([lr,dir]);
18029 pan.setActive(true);
18031 cur.el.removeClass([lr]);
18032 cur.setActive(false);
18034 _this.transition = false;
18036 }, this, { single: true } );
18041 cur.setActive(false);
18042 pan.setActive(true);
18047 showPanelNext : function()
18049 var i = this.indexOfPanel(this.getActivePanel());
18051 if (i >= this.tabs.length - 1 && !this.autoslide) {
18055 if (i >= this.tabs.length - 1 && this.autoslide) {
18059 this.showPanel(this.tabs[i+1]);
18062 showPanelPrev : function()
18064 var i = this.indexOfPanel(this.getActivePanel());
18066 if (i < 1 && !this.autoslide) {
18070 if (i < 1 && this.autoslide) {
18071 i = this.tabs.length;
18074 this.showPanel(this.tabs[i-1]);
18078 addBullet: function()
18080 if(!this.bullets || Roo.isTouch){
18083 var ctr = this.el.select('.carousel-bullets',true).first();
18084 var i = this.el.select('.carousel-bullets .bullet',true).getCount() ;
18085 var bullet = ctr.createChild({
18086 cls : 'bullet bullet-' + i
18087 },ctr.dom.lastChild);
18092 bullet.on('click', (function(e, el, o, ii, t){
18094 e.preventDefault();
18096 this.showPanel(ii);
18098 if(this.autoslide && this.slideFn){
18099 clearInterval(this.slideFn);
18100 this.slideFn = window.setInterval(function() {
18101 _this.showPanelNext();
18105 }).createDelegate(this, [i, bullet], true));
18110 setActiveBullet : function(i)
18116 Roo.each(this.el.select('.bullet', true).elements, function(el){
18117 el.removeClass('selected');
18120 var bullet = this.el.select('.bullet-' + i, true).first();
18126 bullet.addClass('selected');
18137 Roo.apply(Roo.bootstrap.TabGroup, {
18141 * register a Navigation Group
18142 * @param {Roo.bootstrap.NavGroup} the navgroup to add
18144 register : function(navgrp)
18146 this.groups[navgrp.navId] = navgrp;
18150 * fetch a Navigation Group based on the navigation ID
18151 * if one does not exist , it will get created.
18152 * @param {string} the navgroup to add
18153 * @returns {Roo.bootstrap.NavGroup} the navgroup
18155 get: function(navId) {
18156 if (typeof(this.groups[navId]) == 'undefined') {
18157 this.register(new Roo.bootstrap.TabGroup({ navId : navId }));
18159 return this.groups[navId] ;
18174 * @class Roo.bootstrap.TabPanel
18175 * @extends Roo.bootstrap.Component
18176 * Bootstrap TabPanel class
18177 * @cfg {Boolean} active panel active
18178 * @cfg {String} html panel content
18179 * @cfg {String} tabId unique tab ID (will be autogenerated if not set. - used to match TabItem to Panel)
18180 * @cfg {String} navId The Roo.bootstrap.NavGroup which triggers show hide ()
18181 * @cfg {String} href click to link..
18185 * Create a new TabPanel
18186 * @param {Object} config The config object
18189 Roo.bootstrap.TabPanel = function(config){
18190 Roo.bootstrap.TabPanel.superclass.constructor.call(this, config);
18194 * Fires when the active status changes
18195 * @param {Roo.bootstrap.TabPanel} this
18196 * @param {Boolean} state the new state
18201 * @event beforedeactivate
18202 * Fires before a tab is de-activated - can be used to do validation on a form.
18203 * @param {Roo.bootstrap.TabPanel} this
18204 * @return {Boolean} false if there is an error
18207 'beforedeactivate': true
18210 this.tabId = this.tabId || Roo.id();
18214 Roo.extend(Roo.bootstrap.TabPanel, Roo.bootstrap.Component, {
18222 getAutoCreate : function(){
18225 // item is needed for carousel - not sure if it has any effect otherwise
18226 cls: 'tab-pane item' + ((this.href.length) ? ' clickable ' : ''),
18227 html: this.html || ''
18231 cfg.cls += ' active';
18235 cfg.tabId = this.tabId;
18242 initEvents: function()
18244 var p = this.parent();
18246 this.navId = this.navId || p.navId;
18248 if (typeof(this.navId) != 'undefined') {
18249 // not really needed.. but just in case.. parent should be a NavGroup.
18250 var tg = Roo.bootstrap.TabGroup.get(this.navId);
18254 var i = tg.tabs.length - 1;
18256 if(this.active && tg.bullets > 0 && i < tg.bullets){
18257 tg.setActiveBullet(i);
18261 this.el.on('click', this.onClick, this);
18264 this.el.on("touchstart", this.onTouchStart, this);
18265 this.el.on("touchmove", this.onTouchMove, this);
18266 this.el.on("touchend", this.onTouchEnd, this);
18271 onRender : function(ct, position)
18273 Roo.bootstrap.TabPanel.superclass.onRender.call(this, ct, position);
18276 setActive : function(state)
18278 Roo.log("panel - set active " + this.tabId + "=" + state);
18280 this.active = state;
18282 this.el.removeClass('active');
18284 } else if (!this.el.hasClass('active')) {
18285 this.el.addClass('active');
18288 this.fireEvent('changed', this, state);
18291 onClick : function(e)
18293 e.preventDefault();
18295 if(!this.href.length){
18299 window.location.href = this.href;
18308 onTouchStart : function(e)
18310 this.swiping = false;
18312 this.startX = e.browserEvent.touches[0].clientX;
18313 this.startY = e.browserEvent.touches[0].clientY;
18316 onTouchMove : function(e)
18318 this.swiping = true;
18320 this.endX = e.browserEvent.touches[0].clientX;
18321 this.endY = e.browserEvent.touches[0].clientY;
18324 onTouchEnd : function(e)
18331 var tabGroup = this.parent();
18333 if(this.endX > this.startX){ // swiping right
18334 tabGroup.showPanelPrev();
18338 if(this.startX > this.endX){ // swiping left
18339 tabGroup.showPanelNext();
18358 * @class Roo.bootstrap.DateField
18359 * @extends Roo.bootstrap.Input
18360 * Bootstrap DateField class
18361 * @cfg {Number} weekStart default 0
18362 * @cfg {String} viewMode default empty, (months|years)
18363 * @cfg {String} minViewMode default empty, (months|years)
18364 * @cfg {Number} startDate default -Infinity
18365 * @cfg {Number} endDate default Infinity
18366 * @cfg {Boolean} todayHighlight default false
18367 * @cfg {Boolean} todayBtn default false
18368 * @cfg {Boolean} calendarWeeks default false
18369 * @cfg {Object} daysOfWeekDisabled default empty
18370 * @cfg {Boolean} singleMode default false (true | false)
18372 * @cfg {Boolean} keyboardNavigation default true
18373 * @cfg {String} language default en
18376 * Create a new DateField
18377 * @param {Object} config The config object
18380 Roo.bootstrap.DateField = function(config){
18381 Roo.bootstrap.DateField.superclass.constructor.call(this, config);
18385 * Fires when this field show.
18386 * @param {Roo.bootstrap.DateField} this
18387 * @param {Mixed} date The date value
18392 * Fires when this field hide.
18393 * @param {Roo.bootstrap.DateField} this
18394 * @param {Mixed} date The date value
18399 * Fires when select a date.
18400 * @param {Roo.bootstrap.DateField} this
18401 * @param {Mixed} date The date value
18405 * @event beforeselect
18406 * Fires when before select a date.
18407 * @param {Roo.bootstrap.DateField} this
18408 * @param {Mixed} date The date value
18410 beforeselect : true
18414 Roo.extend(Roo.bootstrap.DateField, Roo.bootstrap.Input, {
18417 * @cfg {String} format
18418 * The default date format string which can be overriden for localization support. The format must be
18419 * valid according to {@link Date#parseDate} (defaults to 'm/d/y').
18423 * @cfg {String} altFormats
18424 * Multiple date formats separated by "|" to try when parsing a user input value and it doesn't match the defined
18425 * format (defaults to 'm/d/Y|m-d-y|m-d-Y|m/d|m-d|d').
18427 altFormats : "m/d/Y|m-d-y|m-d-Y|m/d|m-d|md|mdy|mdY|d",
18435 todayHighlight : false,
18441 keyboardNavigation: true,
18443 calendarWeeks: false,
18445 startDate: -Infinity,
18449 daysOfWeekDisabled: [],
18453 singleMode : false,
18455 UTCDate: function()
18457 return new Date(Date.UTC.apply(Date, arguments));
18460 UTCToday: function()
18462 var today = new Date();
18463 return this.UTCDate(today.getUTCFullYear(), today.getUTCMonth(), today.getUTCDate());
18466 getDate: function() {
18467 var d = this.getUTCDate();
18468 return new Date(d.getTime() + (d.getTimezoneOffset()*60000));
18471 getUTCDate: function() {
18475 setDate: function(d) {
18476 this.setUTCDate(new Date(d.getTime() - (d.getTimezoneOffset()*60000)));
18479 setUTCDate: function(d) {
18481 this.setValue(this.formatDate(this.date));
18484 onRender: function(ct, position)
18487 Roo.bootstrap.DateField.superclass.onRender.call(this, ct, position);
18489 this.language = this.language || 'en';
18490 this.language = this.language in Roo.bootstrap.DateField.dates ? this.language : this.language.split('-')[0];
18491 this.language = this.language in Roo.bootstrap.DateField.dates ? this.language : "en";
18493 this.isRTL = Roo.bootstrap.DateField.dates[this.language].rtl || false;
18494 this.format = this.format || 'm/d/y';
18495 this.isInline = false;
18496 this.isInput = true;
18497 this.component = this.el.select('.add-on', true).first() || false;
18498 this.component = (this.component && this.component.length === 0) ? false : this.component;
18499 this.hasInput = this.component && this.inputEl().length;
18501 if (typeof(this.minViewMode === 'string')) {
18502 switch (this.minViewMode) {
18504 this.minViewMode = 1;
18507 this.minViewMode = 2;
18510 this.minViewMode = 0;
18515 if (typeof(this.viewMode === 'string')) {
18516 switch (this.viewMode) {
18529 this.pickerEl = Roo.get(document.body).createChild(Roo.bootstrap.DateField.template);
18531 // this.el.select('>.input-group', true).first().createChild(Roo.bootstrap.DateField.template);
18533 this.picker().setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
18535 this.picker().on('mousedown', this.onMousedown, this);
18536 this.picker().on('click', this.onClick, this);
18538 this.picker().addClass('datepicker-dropdown');
18540 this.startViewMode = this.viewMode;
18542 if(this.singleMode){
18543 Roo.each(this.picker().select('thead > tr > th', true).elements, function(v){
18544 v.setVisibilityMode(Roo.Element.DISPLAY);
18548 Roo.each(this.picker().select('tbody > tr > td', true).elements, function(v){
18549 v.setStyle('width', '189px');
18553 Roo.each(this.picker().select('tfoot th.today', true).elements, function(v){
18554 if(!this.calendarWeeks){
18559 v.dom.innerHTML = Roo.bootstrap.DateField.dates[this.language].today;
18560 v.attr('colspan', function(i, val){
18561 return parseInt(val) + 1;
18566 this.weekEnd = this.weekStart === 0 ? 6 : this.weekStart - 1;
18568 this.setStartDate(this.startDate);
18569 this.setEndDate(this.endDate);
18571 this.setDaysOfWeekDisabled(this.daysOfWeekDisabled);
18578 if(this.isInline) {
18583 picker : function()
18585 return this.pickerEl;
18586 // return this.el.select('.datepicker', true).first();
18589 fillDow: function()
18591 var dowCnt = this.weekStart;
18600 if(this.calendarWeeks){
18608 while (dowCnt < this.weekStart + 7) {
18612 html: Roo.bootstrap.DateField.dates[this.language].daysMin[(dowCnt++)%7]
18616 this.picker().select('>.datepicker-days thead', true).first().createChild(dow);
18619 fillMonths: function()
18622 var months = this.picker().select('>.datepicker-months td', true).first();
18624 months.dom.innerHTML = '';
18630 html: Roo.bootstrap.DateField.dates[this.language].monthsShort[i++]
18633 months.createChild(month);
18640 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;
18642 if (this.date < this.startDate) {
18643 this.viewDate = new Date(this.startDate);
18644 } else if (this.date > this.endDate) {
18645 this.viewDate = new Date(this.endDate);
18647 this.viewDate = new Date(this.date);
18655 var d = new Date(this.viewDate),
18656 year = d.getUTCFullYear(),
18657 month = d.getUTCMonth(),
18658 startYear = this.startDate !== -Infinity ? this.startDate.getUTCFullYear() : -Infinity,
18659 startMonth = this.startDate !== -Infinity ? this.startDate.getUTCMonth() : -Infinity,
18660 endYear = this.endDate !== Infinity ? this.endDate.getUTCFullYear() : Infinity,
18661 endMonth = this.endDate !== Infinity ? this.endDate.getUTCMonth() : Infinity,
18662 currentDate = this.date && this.date.valueOf(),
18663 today = this.UTCToday();
18665 this.picker().select('>.datepicker-days thead th.switch', true).first().dom.innerHTML = Roo.bootstrap.DateField.dates[this.language].months[month]+' '+year;
18667 // this.picker().select('>tfoot th.today', true).first().dom.innerHTML = Roo.bootstrap.DateField.dates[this.language].today;
18669 // this.picker.select('>tfoot th.today').
18670 // .text(dates[this.language].today)
18671 // .toggle(this.todayBtn !== false);
18673 this.updateNavArrows();
18676 var prevMonth = this.UTCDate(year, month-1, 28,0,0,0,0),
18678 day = prevMonth.getDaysInMonth(prevMonth.getUTCFullYear(), prevMonth.getUTCMonth());
18680 prevMonth.setUTCDate(day);
18682 prevMonth.setUTCDate(day - (prevMonth.getUTCDay() - this.weekStart + 7)%7);
18684 var nextMonth = new Date(prevMonth);
18686 nextMonth.setUTCDate(nextMonth.getUTCDate() + 42);
18688 nextMonth = nextMonth.valueOf();
18690 var fillMonths = false;
18692 this.picker().select('>.datepicker-days tbody',true).first().dom.innerHTML = '';
18694 while(prevMonth.valueOf() <= nextMonth) {
18697 if (prevMonth.getUTCDay() === this.weekStart) {
18699 this.picker().select('>.datepicker-days tbody',true).first().createChild(fillMonths);
18707 if(this.calendarWeeks){
18708 // ISO 8601: First week contains first thursday.
18709 // ISO also states week starts on Monday, but we can be more abstract here.
18711 // Start of current week: based on weekstart/current date
18712 ws = new Date(+prevMonth + (this.weekStart - prevMonth.getUTCDay() - 7) % 7 * 864e5),
18713 // Thursday of this week
18714 th = new Date(+ws + (7 + 4 - ws.getUTCDay()) % 7 * 864e5),
18715 // First Thursday of year, year from thursday
18716 yth = new Date(+(yth = this.UTCDate(th.getUTCFullYear(), 0, 1)) + (7 + 4 - yth.getUTCDay())%7*864e5),
18717 // Calendar week: ms between thursdays, div ms per day, div 7 days
18718 calWeek = (th - yth) / 864e5 / 7 + 1;
18720 fillMonths.cn.push({
18728 if (prevMonth.getUTCFullYear() < year || (prevMonth.getUTCFullYear() == year && prevMonth.getUTCMonth() < month)) {
18730 } else if (prevMonth.getUTCFullYear() > year || (prevMonth.getUTCFullYear() == year && prevMonth.getUTCMonth() > month)) {
18733 if (this.todayHighlight &&
18734 prevMonth.getUTCFullYear() == today.getFullYear() &&
18735 prevMonth.getUTCMonth() == today.getMonth() &&
18736 prevMonth.getUTCDate() == today.getDate()) {
18737 clsName += ' today';
18740 if (currentDate && prevMonth.valueOf() === currentDate) {
18741 clsName += ' active';
18744 if (prevMonth.valueOf() < this.startDate || prevMonth.valueOf() > this.endDate ||
18745 this.daysOfWeekDisabled.indexOf(prevMonth.getUTCDay()) !== -1) {
18746 clsName += ' disabled';
18749 fillMonths.cn.push({
18751 cls: 'day ' + clsName,
18752 html: prevMonth.getDate()
18755 prevMonth.setDate(prevMonth.getDate()+1);
18758 var currentYear = this.date && this.date.getUTCFullYear();
18759 var currentMonth = this.date && this.date.getUTCMonth();
18761 this.picker().select('>.datepicker-months th.switch',true).first().dom.innerHTML = year;
18763 Roo.each(this.picker().select('>.datepicker-months tbody span',true).elements, function(v,k){
18764 v.removeClass('active');
18766 if(currentYear === year && k === currentMonth){
18767 v.addClass('active');
18770 if (year < startYear || year > endYear || (year == startYear && k < startMonth) || (year == endYear && k > endMonth)) {
18771 v.addClass('disabled');
18777 year = parseInt(year/10, 10) * 10;
18779 this.picker().select('>.datepicker-years th.switch', true).first().dom.innerHTML = year + '-' + (year + 9);
18781 this.picker().select('>.datepicker-years tbody td',true).first().dom.innerHTML = '';
18784 for (var i = -1; i < 11; i++) {
18785 this.picker().select('>.datepicker-years tbody td',true).first().createChild({
18787 cls: 'year' + (i === -1 || i === 10 ? ' old' : '') + (currentYear === year ? ' active' : '') + (year < startYear || year > endYear ? ' disabled' : ''),
18795 showMode: function(dir)
18798 this.viewMode = Math.max(this.minViewMode, Math.min(2, this.viewMode + dir));
18801 Roo.each(this.picker().select('>div',true).elements, function(v){
18802 v.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
18805 this.picker().select('>.datepicker-'+Roo.bootstrap.DateField.modes[this.viewMode].clsName, true).first().show();
18810 if(this.isInline) {
18814 this.picker().removeClass(['bottom', 'top']);
18816 if((Roo.lib.Dom.getViewHeight() + Roo.get(document.body).getScroll().top) - (this.inputEl().getBottom() + this.picker().getHeight()) < 0){
18818 * place to the top of element!
18822 this.picker().addClass('top');
18823 this.picker().setTop(this.inputEl().getTop() - this.picker().getHeight()).setLeft(this.inputEl().getLeft());
18828 this.picker().addClass('bottom');
18830 this.picker().setTop(this.inputEl().getBottom()).setLeft(this.inputEl().getLeft());
18833 parseDate : function(value)
18835 if(!value || value instanceof Date){
18838 var v = Date.parseDate(value, this.format);
18839 if (!v && (this.useIso || value.match(/^(\d{4})-0?(\d+)-0?(\d+)/))) {
18840 v = Date.parseDate(value, 'Y-m-d');
18842 if(!v && this.altFormats){
18843 if(!this.altFormatsArray){
18844 this.altFormatsArray = this.altFormats.split("|");
18846 for(var i = 0, len = this.altFormatsArray.length; i < len && !v; i++){
18847 v = Date.parseDate(value, this.altFormatsArray[i]);
18853 formatDate : function(date, fmt)
18855 return (!date || !(date instanceof Date)) ?
18856 date : date.dateFormat(fmt || this.format);
18859 onFocus : function()
18861 Roo.bootstrap.DateField.superclass.onFocus.call(this);
18865 onBlur : function()
18867 Roo.bootstrap.DateField.superclass.onBlur.call(this);
18869 var d = this.inputEl().getValue();
18876 showPopup : function()
18878 this.picker().show();
18882 this.fireEvent('showpopup', this, this.date);
18885 hidePopup : function()
18887 if(this.isInline) {
18890 this.picker().hide();
18891 this.viewMode = this.startViewMode;
18894 this.fireEvent('hidepopup', this, this.date);
18898 onMousedown: function(e)
18900 e.stopPropagation();
18901 e.preventDefault();
18906 Roo.bootstrap.DateField.superclass.keyup.call(this);
18910 setValue: function(v)
18912 if(this.fireEvent('beforeselect', this, v) !== false){
18913 var d = new Date(this.parseDate(v) ).clearTime();
18915 if(isNaN(d.getTime())){
18916 this.date = this.viewDate = '';
18917 Roo.bootstrap.DateField.superclass.setValue.call(this, '');
18921 v = this.formatDate(d);
18923 Roo.bootstrap.DateField.superclass.setValue.call(this, v);
18925 this.date = new Date(d.getTime() - d.getTimezoneOffset()*60000);
18929 this.fireEvent('select', this, this.date);
18933 getValue: function()
18935 return this.formatDate(this.date);
18938 fireKey: function(e)
18940 if (!this.picker().isVisible()){
18941 if (e.keyCode == 27) { // allow escape to hide and re-show picker
18947 var dateChanged = false,
18949 newDate, newViewDate;
18954 e.preventDefault();
18958 if (!this.keyboardNavigation) {
18961 dir = e.keyCode == 37 ? -1 : 1;
18964 newDate = this.moveYear(this.date, dir);
18965 newViewDate = this.moveYear(this.viewDate, dir);
18966 } else if (e.shiftKey){
18967 newDate = this.moveMonth(this.date, dir);
18968 newViewDate = this.moveMonth(this.viewDate, dir);
18970 newDate = new Date(this.date);
18971 newDate.setUTCDate(this.date.getUTCDate() + dir);
18972 newViewDate = new Date(this.viewDate);
18973 newViewDate.setUTCDate(this.viewDate.getUTCDate() + dir);
18975 if (this.dateWithinRange(newDate)){
18976 this.date = newDate;
18977 this.viewDate = newViewDate;
18978 this.setValue(this.formatDate(this.date));
18980 e.preventDefault();
18981 dateChanged = true;
18986 if (!this.keyboardNavigation) {
18989 dir = e.keyCode == 38 ? -1 : 1;
18991 newDate = this.moveYear(this.date, dir);
18992 newViewDate = this.moveYear(this.viewDate, dir);
18993 } else if (e.shiftKey){
18994 newDate = this.moveMonth(this.date, dir);
18995 newViewDate = this.moveMonth(this.viewDate, dir);
18997 newDate = new Date(this.date);
18998 newDate.setUTCDate(this.date.getUTCDate() + dir * 7);
18999 newViewDate = new Date(this.viewDate);
19000 newViewDate.setUTCDate(this.viewDate.getUTCDate() + dir * 7);
19002 if (this.dateWithinRange(newDate)){
19003 this.date = newDate;
19004 this.viewDate = newViewDate;
19005 this.setValue(this.formatDate(this.date));
19007 e.preventDefault();
19008 dateChanged = true;
19012 this.setValue(this.formatDate(this.date));
19014 e.preventDefault();
19017 this.setValue(this.formatDate(this.date));
19031 onClick: function(e)
19033 e.stopPropagation();
19034 e.preventDefault();
19036 var target = e.getTarget();
19038 if(target.nodeName.toLowerCase() === 'i'){
19039 target = Roo.get(target).dom.parentNode;
19042 var nodeName = target.nodeName;
19043 var className = target.className;
19044 var html = target.innerHTML;
19045 //Roo.log(nodeName);
19047 switch(nodeName.toLowerCase()) {
19049 switch(className) {
19055 var dir = Roo.bootstrap.DateField.modes[this.viewMode].navStep * (className == 'prev' ? -1 : 1);
19056 switch(this.viewMode){
19058 this.viewDate = this.moveMonth(this.viewDate, dir);
19062 this.viewDate = this.moveYear(this.viewDate, dir);
19068 var date = new Date();
19069 this.date = this.UTCDate(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0);
19071 this.setValue(this.formatDate(this.date));
19078 if (className.indexOf('disabled') < 0) {
19079 this.viewDate.setUTCDate(1);
19080 if (className.indexOf('month') > -1) {
19081 this.viewDate.setUTCMonth(Roo.bootstrap.DateField.dates[this.language].monthsShort.indexOf(html));
19083 var year = parseInt(html, 10) || 0;
19084 this.viewDate.setUTCFullYear(year);
19088 if(this.singleMode){
19089 this.setValue(this.formatDate(this.viewDate));
19100 //Roo.log(className);
19101 if (className.indexOf('day') > -1 && className.indexOf('disabled') < 0 ){
19102 var day = parseInt(html, 10) || 1;
19103 var year = this.viewDate.getUTCFullYear(),
19104 month = this.viewDate.getUTCMonth();
19106 if (className.indexOf('old') > -1) {
19113 } else if (className.indexOf('new') > -1) {
19121 //Roo.log([year,month,day]);
19122 this.date = this.UTCDate(year, month, day,0,0,0,0);
19123 this.viewDate = this.UTCDate(year, month, Math.min(28, day),0,0,0,0);
19125 //Roo.log(this.formatDate(this.date));
19126 this.setValue(this.formatDate(this.date));
19133 setStartDate: function(startDate)
19135 this.startDate = startDate || -Infinity;
19136 if (this.startDate !== -Infinity) {
19137 this.startDate = this.parseDate(this.startDate);
19140 this.updateNavArrows();
19143 setEndDate: function(endDate)
19145 this.endDate = endDate || Infinity;
19146 if (this.endDate !== Infinity) {
19147 this.endDate = this.parseDate(this.endDate);
19150 this.updateNavArrows();
19153 setDaysOfWeekDisabled: function(daysOfWeekDisabled)
19155 this.daysOfWeekDisabled = daysOfWeekDisabled || [];
19156 if (typeof(this.daysOfWeekDisabled) !== 'object') {
19157 this.daysOfWeekDisabled = this.daysOfWeekDisabled.split(/,\s*/);
19159 this.daysOfWeekDisabled = this.daysOfWeekDisabled.map(function (d) {
19160 return parseInt(d, 10);
19163 this.updateNavArrows();
19166 updateNavArrows: function()
19168 if(this.singleMode){
19172 var d = new Date(this.viewDate),
19173 year = d.getUTCFullYear(),
19174 month = d.getUTCMonth();
19176 Roo.each(this.picker().select('.prev', true).elements, function(v){
19178 switch (this.viewMode) {
19181 if (this.startDate !== -Infinity && year <= this.startDate.getUTCFullYear() && month <= this.startDate.getUTCMonth()) {
19187 if (this.startDate !== -Infinity && year <= this.startDate.getUTCFullYear()) {
19194 Roo.each(this.picker().select('.next', true).elements, function(v){
19196 switch (this.viewMode) {
19199 if (this.endDate !== Infinity && year >= this.endDate.getUTCFullYear() && month >= this.endDate.getUTCMonth()) {
19205 if (this.endDate !== Infinity && year >= this.endDate.getUTCFullYear()) {
19213 moveMonth: function(date, dir)
19218 var new_date = new Date(date.valueOf()),
19219 day = new_date.getUTCDate(),
19220 month = new_date.getUTCMonth(),
19221 mag = Math.abs(dir),
19223 dir = dir > 0 ? 1 : -1;
19226 // If going back one month, make sure month is not current month
19227 // (eg, Mar 31 -> Feb 31 == Feb 28, not Mar 02)
19229 return new_date.getUTCMonth() == month;
19231 // If going forward one month, make sure month is as expected
19232 // (eg, Jan 31 -> Feb 31 == Feb 28, not Mar 02)
19234 return new_date.getUTCMonth() != new_month;
19236 new_month = month + dir;
19237 new_date.setUTCMonth(new_month);
19238 // Dec -> Jan (12) or Jan -> Dec (-1) -- limit expected date to 0-11
19239 if (new_month < 0 || new_month > 11) {
19240 new_month = (new_month + 12) % 12;
19243 // For magnitudes >1, move one month at a time...
19244 for (var i=0; i<mag; i++) {
19245 // ...which might decrease the day (eg, Jan 31 to Feb 28, etc)...
19246 new_date = this.moveMonth(new_date, dir);
19248 // ...then reset the day, keeping it in the new month
19249 new_month = new_date.getUTCMonth();
19250 new_date.setUTCDate(day);
19252 return new_month != new_date.getUTCMonth();
19255 // Common date-resetting loop -- if date is beyond end of month, make it
19258 new_date.setUTCDate(--day);
19259 new_date.setUTCMonth(new_month);
19264 moveYear: function(date, dir)
19266 return this.moveMonth(date, dir*12);
19269 dateWithinRange: function(date)
19271 return date >= this.startDate && date <= this.endDate;
19277 this.picker().remove();
19280 validateValue : function(value)
19282 if(this.getVisibilityEl().hasClass('hidden')){
19286 if(value.length < 1) {
19287 if(this.allowBlank){
19293 if(value.length < this.minLength){
19296 if(value.length > this.maxLength){
19300 var vt = Roo.form.VTypes;
19301 if(!vt[this.vtype](value, this)){
19305 if(typeof this.validator == "function"){
19306 var msg = this.validator(value);
19312 if(this.regex && !this.regex.test(value)){
19316 if(typeof(this.parseDate(value)) == 'undefined'){
19320 if (this.endDate !== Infinity && this.parseDate(value).getTime() > this.endDate.getTime()) {
19324 if (this.startDate !== -Infinity && this.parseDate(value).getTime() < this.startDate.getTime()) {
19334 this.date = this.viewDate = '';
19336 Roo.bootstrap.DateField.superclass.setValue.call(this, '');
19341 Roo.apply(Roo.bootstrap.DateField, {
19352 html: '<i class="fa fa-arrow-left"/>'
19362 html: '<i class="fa fa-arrow-right"/>'
19404 days: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"],
19405 daysShort: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
19406 daysMin: ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"],
19407 months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
19408 monthsShort: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
19421 navFnc: 'FullYear',
19426 navFnc: 'FullYear',
19431 Roo.apply(Roo.bootstrap.DateField, {
19435 cls: 'datepicker dropdown-menu roo-dynamic',
19439 cls: 'datepicker-days',
19443 cls: 'table-condensed',
19445 Roo.bootstrap.DateField.head,
19449 Roo.bootstrap.DateField.footer
19456 cls: 'datepicker-months',
19460 cls: 'table-condensed',
19462 Roo.bootstrap.DateField.head,
19463 Roo.bootstrap.DateField.content,
19464 Roo.bootstrap.DateField.footer
19471 cls: 'datepicker-years',
19475 cls: 'table-condensed',
19477 Roo.bootstrap.DateField.head,
19478 Roo.bootstrap.DateField.content,
19479 Roo.bootstrap.DateField.footer
19498 * @class Roo.bootstrap.TimeField
19499 * @extends Roo.bootstrap.Input
19500 * Bootstrap DateField class
19504 * Create a new TimeField
19505 * @param {Object} config The config object
19508 Roo.bootstrap.TimeField = function(config){
19509 Roo.bootstrap.TimeField.superclass.constructor.call(this, config);
19513 * Fires when this field show.
19514 * @param {Roo.bootstrap.DateField} thisthis
19515 * @param {Mixed} date The date value
19520 * Fires when this field hide.
19521 * @param {Roo.bootstrap.DateField} this
19522 * @param {Mixed} date The date value
19527 * Fires when select a date.
19528 * @param {Roo.bootstrap.DateField} this
19529 * @param {Mixed} date The date value
19535 Roo.extend(Roo.bootstrap.TimeField, Roo.bootstrap.Input, {
19538 * @cfg {String} format
19539 * The default time format string which can be overriden for localization support. The format must be
19540 * valid according to {@link Date#parseDate} (defaults to 'H:i').
19544 onRender: function(ct, position)
19547 Roo.bootstrap.TimeField.superclass.onRender.call(this, ct, position);
19549 this.el.select('>.input-group', true).first().createChild(Roo.bootstrap.TimeField.template);
19551 this.picker().setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
19553 this.pop = this.picker().select('>.datepicker-time',true).first();
19554 this.pop.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
19556 this.picker().on('mousedown', this.onMousedown, this);
19557 this.picker().on('click', this.onClick, this);
19559 this.picker().addClass('datepicker-dropdown');
19564 this.pop.select('span.hours-up', true).first().on('click', this.onIncrementHours, this);
19565 this.pop.select('span.hours-down', true).first().on('click', this.onDecrementHours, this);
19566 this.pop.select('span.minutes-up', true).first().on('click', this.onIncrementMinutes, this);
19567 this.pop.select('span.minutes-down', true).first().on('click', this.onDecrementMinutes, this);
19568 this.pop.select('button.period', true).first().on('click', this.onTogglePeriod, this);
19569 this.pop.select('button.ok', true).first().on('click', this.setTime, this);
19573 fireKey: function(e){
19574 if (!this.picker().isVisible()){
19575 if (e.keyCode == 27) { // allow escape to hide and re-show picker
19581 e.preventDefault();
19589 this.onTogglePeriod();
19592 this.onIncrementMinutes();
19595 this.onDecrementMinutes();
19604 onClick: function(e) {
19605 e.stopPropagation();
19606 e.preventDefault();
19609 picker : function()
19611 return this.el.select('.datepicker', true).first();
19614 fillTime: function()
19616 var time = this.pop.select('tbody', true).first();
19618 time.dom.innerHTML = '';
19633 cls: 'hours-up glyphicon glyphicon-chevron-up'
19653 cls: 'minutes-up glyphicon glyphicon-chevron-up'
19674 cls: 'timepicker-hour',
19689 cls: 'timepicker-minute',
19704 cls: 'btn btn-primary period',
19726 cls: 'hours-down glyphicon glyphicon-chevron-down'
19746 cls: 'minutes-down glyphicon glyphicon-chevron-down'
19764 this.time = (typeof(this.time) === 'undefined') ? new Date() : this.time;
19771 var hours = this.time.getHours();
19772 var minutes = this.time.getMinutes();
19785 hours = hours - 12;
19789 hours = '0' + hours;
19793 minutes = '0' + minutes;
19796 this.pop.select('.timepicker-hour', true).first().dom.innerHTML = hours;
19797 this.pop.select('.timepicker-minute', true).first().dom.innerHTML = minutes;
19798 this.pop.select('button', true).first().dom.innerHTML = period;
19804 this.picker().removeClass(['bottom-left', 'bottom-right', 'top-left', 'top-right']);
19806 var cls = ['bottom'];
19808 if((Roo.lib.Dom.getViewHeight() + Roo.get(document.body).getScroll().top) - (this.inputEl().getBottom() + this.picker().getHeight()) < 0){ // top
19815 if((Roo.lib.Dom.getViewWidth() + Roo.get(document.body).getScroll().left) - (this.inputEl().getLeft() + this.picker().getWidth()) < 0){ // left
19820 this.picker().addClass(cls.join('-'));
19824 Roo.each(cls, function(c){
19826 _this.picker().setTop(_this.inputEl().getHeight());
19830 _this.picker().setTop(0 - _this.picker().getHeight());
19835 _this.picker().setLeft(_this.inputEl().getLeft() + _this.inputEl().getWidth() - _this.el.getLeft() - _this.picker().getWidth());
19839 _this.picker().setLeft(_this.inputEl().getLeft() - _this.el.getLeft());
19846 onFocus : function()
19848 Roo.bootstrap.TimeField.superclass.onFocus.call(this);
19852 onBlur : function()
19854 Roo.bootstrap.TimeField.superclass.onBlur.call(this);
19860 this.picker().show();
19865 this.fireEvent('show', this, this.date);
19870 this.picker().hide();
19873 this.fireEvent('hide', this, this.date);
19876 setTime : function()
19879 this.setValue(this.time.format(this.format));
19881 this.fireEvent('select', this, this.date);
19886 onMousedown: function(e){
19887 e.stopPropagation();
19888 e.preventDefault();
19891 onIncrementHours: function()
19893 Roo.log('onIncrementHours');
19894 this.time = this.time.add(Date.HOUR, 1);
19899 onDecrementHours: function()
19901 Roo.log('onDecrementHours');
19902 this.time = this.time.add(Date.HOUR, -1);
19906 onIncrementMinutes: function()
19908 Roo.log('onIncrementMinutes');
19909 this.time = this.time.add(Date.MINUTE, 1);
19913 onDecrementMinutes: function()
19915 Roo.log('onDecrementMinutes');
19916 this.time = this.time.add(Date.MINUTE, -1);
19920 onTogglePeriod: function()
19922 Roo.log('onTogglePeriod');
19923 this.time = this.time.add(Date.HOUR, 12);
19930 Roo.apply(Roo.bootstrap.TimeField, {
19960 cls: 'btn btn-info ok',
19972 Roo.apply(Roo.bootstrap.TimeField, {
19976 cls: 'datepicker dropdown-menu',
19980 cls: 'datepicker-time',
19984 cls: 'table-condensed',
19986 Roo.bootstrap.TimeField.content,
19987 Roo.bootstrap.TimeField.footer
20006 * @class Roo.bootstrap.MonthField
20007 * @extends Roo.bootstrap.Input
20008 * Bootstrap MonthField class
20010 * @cfg {String} language default en
20013 * Create a new MonthField
20014 * @param {Object} config The config object
20017 Roo.bootstrap.MonthField = function(config){
20018 Roo.bootstrap.MonthField.superclass.constructor.call(this, config);
20023 * Fires when this field show.
20024 * @param {Roo.bootstrap.MonthField} this
20025 * @param {Mixed} date The date value
20030 * Fires when this field hide.
20031 * @param {Roo.bootstrap.MonthField} this
20032 * @param {Mixed} date The date value
20037 * Fires when select a date.
20038 * @param {Roo.bootstrap.MonthField} this
20039 * @param {String} oldvalue The old value
20040 * @param {String} newvalue The new value
20046 Roo.extend(Roo.bootstrap.MonthField, Roo.bootstrap.Input, {
20048 onRender: function(ct, position)
20051 Roo.bootstrap.MonthField.superclass.onRender.call(this, ct, position);
20053 this.language = this.language || 'en';
20054 this.language = this.language in Roo.bootstrap.MonthField.dates ? this.language : this.language.split('-')[0];
20055 this.language = this.language in Roo.bootstrap.MonthField.dates ? this.language : "en";
20057 this.isRTL = Roo.bootstrap.MonthField.dates[this.language].rtl || false;
20058 this.isInline = false;
20059 this.isInput = true;
20060 this.component = this.el.select('.add-on', true).first() || false;
20061 this.component = (this.component && this.component.length === 0) ? false : this.component;
20062 this.hasInput = this.component && this.inputEL().length;
20064 this.pickerEl = Roo.get(document.body).createChild(Roo.bootstrap.MonthField.template);
20066 this.picker().setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
20068 this.picker().on('mousedown', this.onMousedown, this);
20069 this.picker().on('click', this.onClick, this);
20071 this.picker().addClass('datepicker-dropdown');
20073 Roo.each(this.picker().select('tbody > tr > td', true).elements, function(v){
20074 v.setStyle('width', '189px');
20081 if(this.isInline) {
20087 setValue: function(v, suppressEvent)
20089 var o = this.getValue();
20091 Roo.bootstrap.MonthField.superclass.setValue.call(this, v);
20095 if(suppressEvent !== true){
20096 this.fireEvent('select', this, o, v);
20101 getValue: function()
20106 onClick: function(e)
20108 e.stopPropagation();
20109 e.preventDefault();
20111 var target = e.getTarget();
20113 if(target.nodeName.toLowerCase() === 'i'){
20114 target = Roo.get(target).dom.parentNode;
20117 var nodeName = target.nodeName;
20118 var className = target.className;
20119 var html = target.innerHTML;
20121 if(nodeName.toLowerCase() != 'span' || className.indexOf('disabled') > -1 || className.indexOf('month') == -1){
20125 this.vIndex = Roo.bootstrap.MonthField.dates[this.language].monthsShort.indexOf(html);
20127 this.setValue(Roo.bootstrap.MonthField.dates[this.language].months[this.vIndex]);
20133 picker : function()
20135 return this.pickerEl;
20138 fillMonths: function()
20141 var months = this.picker().select('>.datepicker-months td', true).first();
20143 months.dom.innerHTML = '';
20149 html: Roo.bootstrap.MonthField.dates[this.language].monthsShort[i++]
20152 months.createChild(month);
20161 if(typeof(this.vIndex) == 'undefined' && this.value.length){
20162 this.vIndex = Roo.bootstrap.MonthField.dates[this.language].months.indexOf(this.value);
20165 Roo.each(this.pickerEl.select('> .datepicker-months tbody > tr > td > span', true).elements, function(e, k){
20166 e.removeClass('active');
20168 if(typeof(_this.vIndex) != 'undefined' && k == _this.vIndex){
20169 e.addClass('active');
20176 if(this.isInline) {
20180 this.picker().removeClass(['bottom', 'top']);
20182 if((Roo.lib.Dom.getViewHeight() + Roo.get(document.body).getScroll().top) - (this.inputEl().getBottom() + this.picker().getHeight()) < 0){
20184 * place to the top of element!
20188 this.picker().addClass('top');
20189 this.picker().setTop(this.inputEl().getTop() - this.picker().getHeight()).setLeft(this.inputEl().getLeft());
20194 this.picker().addClass('bottom');
20196 this.picker().setTop(this.inputEl().getBottom()).setLeft(this.inputEl().getLeft());
20199 onFocus : function()
20201 Roo.bootstrap.MonthField.superclass.onFocus.call(this);
20205 onBlur : function()
20207 Roo.bootstrap.MonthField.superclass.onBlur.call(this);
20209 var d = this.inputEl().getValue();
20218 this.picker().show();
20219 this.picker().select('>.datepicker-months', true).first().show();
20223 this.fireEvent('show', this, this.date);
20228 if(this.isInline) {
20231 this.picker().hide();
20232 this.fireEvent('hide', this, this.date);
20236 onMousedown: function(e)
20238 e.stopPropagation();
20239 e.preventDefault();
20244 Roo.bootstrap.MonthField.superclass.keyup.call(this);
20248 fireKey: function(e)
20250 if (!this.picker().isVisible()){
20251 if (e.keyCode == 27) {// allow escape to hide and re-show picker
20262 e.preventDefault();
20266 dir = e.keyCode == 37 ? -1 : 1;
20268 this.vIndex = this.vIndex + dir;
20270 if(this.vIndex < 0){
20274 if(this.vIndex > 11){
20278 if(isNaN(this.vIndex)){
20282 this.setValue(Roo.bootstrap.MonthField.dates[this.language].months[this.vIndex]);
20288 dir = e.keyCode == 38 ? -1 : 1;
20290 this.vIndex = this.vIndex + dir * 4;
20292 if(this.vIndex < 0){
20296 if(this.vIndex > 11){
20300 if(isNaN(this.vIndex)){
20304 this.setValue(Roo.bootstrap.MonthField.dates[this.language].months[this.vIndex]);
20309 if(typeof(this.vIndex) != 'undefined' && !isNaN(this.vIndex)){
20310 this.setValue(Roo.bootstrap.MonthField.dates[this.language].months[this.vIndex]);
20314 e.preventDefault();
20317 if(typeof(this.vIndex) != 'undefined' && !isNaN(this.vIndex)){
20318 this.setValue(Roo.bootstrap.MonthField.dates[this.language].months[this.vIndex]);
20334 this.picker().remove();
20339 Roo.apply(Roo.bootstrap.MonthField, {
20358 months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
20359 monthsShort: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
20364 Roo.apply(Roo.bootstrap.MonthField, {
20368 cls: 'datepicker dropdown-menu roo-dynamic',
20372 cls: 'datepicker-months',
20376 cls: 'table-condensed',
20378 Roo.bootstrap.DateField.content
20398 * @class Roo.bootstrap.CheckBox
20399 * @extends Roo.bootstrap.Input
20400 * Bootstrap CheckBox class
20402 * @cfg {String} valueOff The value that should go into the generated input element's value when unchecked.
20403 * @cfg {String} inputValue The value that should go into the generated input element's value when checked.
20404 * @cfg {String} boxLabel The text that appears beside the checkbox
20405 * @cfg {String} weight (primary|warning|info|danger|success) The text that appears beside the checkbox
20406 * @cfg {Boolean} checked initnal the element
20407 * @cfg {Boolean} inline inline the element (default false)
20408 * @cfg {String} groupId the checkbox group id // normal just use for checkbox
20409 * @cfg {String} tooltip label tooltip
20412 * Create a new CheckBox
20413 * @param {Object} config The config object
20416 Roo.bootstrap.CheckBox = function(config){
20417 Roo.bootstrap.CheckBox.superclass.constructor.call(this, config);
20422 * Fires when the element is checked or unchecked.
20423 * @param {Roo.bootstrap.CheckBox} this This input
20424 * @param {Boolean} checked The new checked value
20429 * Fires when the element is click.
20430 * @param {Roo.bootstrap.CheckBox} this This input
20437 Roo.extend(Roo.bootstrap.CheckBox, Roo.bootstrap.Input, {
20439 inputType: 'checkbox',
20448 getAutoCreate : function()
20450 var align = (!this.labelAlign) ? this.parentLabelAlign() : this.labelAlign;
20456 cfg.cls = 'form-group ' + this.inputType; //input-group
20459 cfg.cls += ' ' + this.inputType + '-inline';
20465 type : this.inputType,
20466 value : this.inputValue,
20467 cls : 'roo-' + this.inputType, //'form-box',
20468 placeholder : this.placeholder || ''
20472 if(this.inputType != 'radio'){
20476 cls : 'roo-hidden-value',
20477 value : this.checked ? this.inputValue : this.valueOff
20482 if (this.weight) { // Validity check?
20483 cfg.cls += " " + this.inputType + "-" + this.weight;
20486 if (this.disabled) {
20487 input.disabled=true;
20491 input.checked = this.checked;
20496 input.name = this.name;
20498 if(this.inputType != 'radio'){
20499 hidden.name = this.name;
20500 input.name = '_hidden_' + this.name;
20505 input.cls += ' input-' + this.size;
20510 ['xs','sm','md','lg'].map(function(size){
20511 if (settings[size]) {
20512 cfg.cls += ' col-' + size + '-' + settings[size];
20516 var inputblock = input;
20518 if (this.before || this.after) {
20521 cls : 'input-group',
20526 inputblock.cn.push({
20528 cls : 'input-group-addon',
20533 inputblock.cn.push(input);
20535 if(this.inputType != 'radio'){
20536 inputblock.cn.push(hidden);
20540 inputblock.cn.push({
20542 cls : 'input-group-addon',
20549 if (align ==='left' && this.fieldLabel.length) {
20550 // Roo.log("left and has label");
20555 cls : 'control-label',
20556 html : this.fieldLabel
20566 if(this.labelWidth > 12){
20567 cfg.cn[0].style = "width: " + this.labelWidth + 'px';
20570 if(this.labelWidth < 13 && this.labelmd == 0){
20571 this.labelmd = this.labelWidth;
20574 if(this.labellg > 0){
20575 cfg.cn[0].cls += ' col-lg-' + this.labellg;
20576 cfg.cn[1].cls += ' col-lg-' + (12 - this.labellg);
20579 if(this.labelmd > 0){
20580 cfg.cn[0].cls += ' col-md-' + this.labelmd;
20581 cfg.cn[1].cls += ' col-md-' + (12 - this.labelmd);
20584 if(this.labelsm > 0){
20585 cfg.cn[0].cls += ' col-sm-' + this.labelsm;
20586 cfg.cn[1].cls += ' col-sm-' + (12 - this.labelsm);
20589 if(this.labelxs > 0){
20590 cfg.cn[0].cls += ' col-xs-' + this.labelxs;
20591 cfg.cn[1].cls += ' col-xs-' + (12 - this.labelxs);
20594 } else if ( this.fieldLabel.length) {
20595 // Roo.log(" label");
20599 tag: this.boxLabel ? 'span' : 'label',
20601 cls: 'control-label box-input-label',
20602 //cls : 'input-group-addon',
20603 html : this.fieldLabel
20612 // Roo.log(" no label && no align");
20613 cfg.cn = [ inputblock ] ;
20619 var boxLabelCfg = {
20621 //'for': id, // box label is handled by onclick - so no for...
20623 html: this.boxLabel
20627 boxLabelCfg.tooltip = this.tooltip;
20630 cfg.cn.push(boxLabelCfg);
20633 if(this.inputType != 'radio'){
20634 cfg.cn.push(hidden);
20642 * return the real input element.
20644 inputEl: function ()
20646 return this.el.select('input.roo-' + this.inputType,true).first();
20648 hiddenEl: function ()
20650 return this.el.select('input.roo-hidden-value',true).first();
20653 labelEl: function()
20655 return this.el.select('label.control-label',true).first();
20657 /* depricated... */
20661 return this.labelEl();
20664 boxLabelEl: function()
20666 return this.el.select('label.box-label',true).first();
20669 initEvents : function()
20671 // Roo.bootstrap.CheckBox.superclass.initEvents.call(this);
20673 this.inputEl().on('click', this.onClick, this);
20675 if (this.boxLabel) {
20676 this.el.select('label.box-label',true).first().on('click', this.onClick, this);
20679 this.startValue = this.getValue();
20682 Roo.bootstrap.CheckBox.register(this);
20686 onClick : function(e)
20688 if(this.fireEvent('click', this, e) !== false){
20689 this.setChecked(!this.checked);
20694 setChecked : function(state,suppressEvent)
20696 this.startValue = this.getValue();
20698 if(this.inputType == 'radio'){
20700 Roo.each(this.el.up('form').select('input[name='+this.name+']', true).elements, function(e){
20701 e.dom.checked = false;
20704 this.inputEl().dom.checked = true;
20706 this.inputEl().dom.value = this.inputValue;
20708 if(suppressEvent !== true){
20709 this.fireEvent('check', this, true);
20717 this.checked = state;
20719 this.inputEl().dom.checked = state;
20722 this.hiddenEl().dom.value = state ? this.inputValue : this.valueOff;
20724 if(suppressEvent !== true){
20725 this.fireEvent('check', this, state);
20731 getValue : function()
20733 if(this.inputType == 'radio'){
20734 return this.getGroupValue();
20737 return this.hiddenEl().dom.value;
20741 getGroupValue : function()
20743 if(typeof(this.el.up('form').child('input[name='+this.name+']:checked', true)) == 'undefined'){
20747 return this.el.up('form').child('input[name='+this.name+']:checked', true).value;
20750 setValue : function(v,suppressEvent)
20752 if(this.inputType == 'radio'){
20753 this.setGroupValue(v, suppressEvent);
20757 this.setChecked(((typeof(v) == 'undefined') ? this.checked : (String(v) === String(this.inputValue))), suppressEvent);
20762 setGroupValue : function(v, suppressEvent)
20764 this.startValue = this.getValue();
20766 Roo.each(this.el.up('form').select('input[name='+this.name+']', true).elements, function(e){
20767 e.dom.checked = false;
20769 if(e.dom.value == v){
20770 e.dom.checked = true;
20774 if(suppressEvent !== true){
20775 this.fireEvent('check', this, true);
20783 validate : function()
20785 if(this.getVisibilityEl().hasClass('hidden')){
20791 (this.inputType == 'radio' && this.validateRadio()) ||
20792 (this.inputType == 'checkbox' && this.validateCheckbox())
20798 this.markInvalid();
20802 validateRadio : function()
20804 if(this.getVisibilityEl().hasClass('hidden')){
20808 if(this.allowBlank){
20814 Roo.each(this.el.up('form').select('input[name='+this.name+']', true).elements, function(e){
20815 if(!e.dom.checked){
20827 validateCheckbox : function()
20830 return (this.getValue() == this.inputValue || this.allowBlank) ? true : false;
20831 //return (this.getValue() == this.inputValue) ? true : false;
20834 var group = Roo.bootstrap.CheckBox.get(this.groupId);
20842 for(var i in group){
20843 if(group[i].el.isVisible(true)){
20851 for(var i in group){
20856 r = (group[i].getValue() == group[i].inputValue) ? true : false;
20863 * Mark this field as valid
20865 markValid : function()
20869 this.fireEvent('valid', this);
20871 var label = Roo.bootstrap.FieldLabel.get(this.name + '-group');
20874 label = Roo.bootstrap.FieldLabel.get(this.groupId + '-group');
20881 if(this.inputType == 'radio'){
20882 Roo.each(this.el.up('form').select('input[name='+this.name+']', true).elements, function(e){
20883 e.findParent('.form-group', false, true).removeClass([_this.invalidClass, _this.validClass]);
20884 e.findParent('.form-group', false, true).addClass(_this.validClass);
20891 this.el.findParent('.form-group', false, true).removeClass([this.invalidClass, this.validClass]);
20892 this.el.findParent('.form-group', false, true).addClass(this.validClass);
20896 var group = Roo.bootstrap.CheckBox.get(this.groupId);
20902 for(var i in group){
20903 group[i].el.findParent('.form-group', false, true).removeClass([this.invalidClass, this.validClass]);
20904 group[i].el.findParent('.form-group', false, true).addClass(this.validClass);
20909 * Mark this field as invalid
20910 * @param {String} msg The validation message
20912 markInvalid : function(msg)
20914 if(this.allowBlank){
20920 this.fireEvent('invalid', this, msg);
20922 var label = Roo.bootstrap.FieldLabel.get(this.name + '-group');
20925 label = Roo.bootstrap.FieldLabel.get(this.groupId + '-group');
20929 label.markInvalid();
20932 if(this.inputType == 'radio'){
20933 Roo.each(this.el.up('form').select('input[name='+this.name+']', true).elements, function(e){
20934 e.findParent('.form-group', false, true).removeClass([_this.invalidClass, _this.validClass]);
20935 e.findParent('.form-group', false, true).addClass(_this.invalidClass);
20942 this.el.findParent('.form-group', false, true).removeClass([this.invalidClass, this.validClass]);
20943 this.el.findParent('.form-group', false, true).addClass(this.invalidClass);
20947 var group = Roo.bootstrap.CheckBox.get(this.groupId);
20953 for(var i in group){
20954 group[i].el.findParent('.form-group', false, true).removeClass([this.invalidClass, this.validClass]);
20955 group[i].el.findParent('.form-group', false, true).addClass(this.invalidClass);
20960 clearInvalid : function()
20962 Roo.bootstrap.Input.prototype.clearInvalid.call(this);
20964 // this.el.findParent('.form-group', false, true).removeClass([this.invalidClass, this.validClass]);
20966 var label = Roo.bootstrap.FieldLabel.get(this.name + '-group');
20968 if (label && label.iconEl) {
20969 label.iconEl.removeClass(label.validClass);
20970 label.iconEl.removeClass(label.invalidClass);
20974 disable : function()
20976 if(this.inputType != 'radio'){
20977 Roo.bootstrap.CheckBox.superclass.disable.call(this);
20984 Roo.each(this.el.up('form').select('input[name='+this.name+']', true).elements, function(e){
20985 _this.getActionEl().addClass(this.disabledClass);
20986 e.dom.disabled = true;
20990 this.disabled = true;
20991 this.fireEvent("disable", this);
20995 enable : function()
20997 if(this.inputType != 'radio'){
20998 Roo.bootstrap.CheckBox.superclass.enable.call(this);
21005 Roo.each(this.el.up('form').select('input[name='+this.name+']', true).elements, function(e){
21006 _this.getActionEl().removeClass(this.disabledClass);
21007 e.dom.disabled = false;
21011 this.disabled = false;
21012 this.fireEvent("enable", this);
21016 setBoxLabel : function(v)
21021 this.el.select('label.box-label',true).first().dom.innerHTML = (v === null || v === undefined ? '' : v);
21027 Roo.apply(Roo.bootstrap.CheckBox, {
21032 * register a CheckBox Group
21033 * @param {Roo.bootstrap.CheckBox} the CheckBox to add
21035 register : function(checkbox)
21037 if(typeof(this.groups[checkbox.groupId]) == 'undefined'){
21038 this.groups[checkbox.groupId] = {};
21041 if(this.groups[checkbox.groupId].hasOwnProperty(checkbox.name)){
21045 this.groups[checkbox.groupId][checkbox.name] = checkbox;
21049 * fetch a CheckBox Group based on the group ID
21050 * @param {string} the group ID
21051 * @returns {Roo.bootstrap.CheckBox} the CheckBox group
21053 get: function(groupId) {
21054 if (typeof(this.groups[groupId]) == 'undefined') {
21058 return this.groups[groupId] ;
21071 * @class Roo.bootstrap.Radio
21072 * @extends Roo.bootstrap.Component
21073 * Bootstrap Radio class
21074 * @cfg {String} boxLabel - the label associated
21075 * @cfg {String} value - the value of radio
21078 * Create a new Radio
21079 * @param {Object} config The config object
21081 Roo.bootstrap.Radio = function(config){
21082 Roo.bootstrap.Radio.superclass.constructor.call(this, config);
21086 Roo.extend(Roo.bootstrap.Radio, Roo.bootstrap.Component, {
21092 getAutoCreate : function()
21096 cls : 'form-group radio',
21101 html : this.boxLabel
21109 initEvents : function()
21111 this.parent().register(this);
21113 this.el.on('click', this.onClick, this);
21117 onClick : function(e)
21119 if(this.parent().fireEvent('click', this.parent(), this, e) !== false){
21120 this.setChecked(true);
21124 setChecked : function(state, suppressEvent)
21126 this.parent().setValue(this.value, suppressEvent);
21130 setBoxLabel : function(v)
21135 this.el.select('label.box-label',true).first().dom.innerHTML = (v === null || v === undefined ? '' : v);
21150 * @class Roo.bootstrap.SecurePass
21151 * @extends Roo.bootstrap.Input
21152 * Bootstrap SecurePass class
21156 * Create a new SecurePass
21157 * @param {Object} config The config object
21160 Roo.bootstrap.SecurePass = function (config) {
21161 // these go here, so the translation tool can replace them..
21163 PwdEmpty: "Please type a password, and then retype it to confirm.",
21164 PwdShort: "Your password must be at least 6 characters long. Please type a different password.",
21165 PwdLong: "Your password can't contain more than 16 characters. Please type a different password.",
21166 PwdBadChar: "The password contains characters that aren't allowed. Please type a different password.",
21167 IDInPwd: "Your password can't include the part of your ID. Please type a different password.",
21168 FNInPwd: "Your password can't contain your first name. Please type a different password.",
21169 LNInPwd: "Your password can't contain your last name. Please type a different password.",
21170 TooWeak: "Your password is Too Weak."
21172 this.meterLabel = "Password strength:";
21173 this.pwdStrengths = ["Too Weak", "Weak", "Medium", "Strong"];
21174 this.meterClass = [
21175 "roo-password-meter-tooweak",
21176 "roo-password-meter-weak",
21177 "roo-password-meter-medium",
21178 "roo-password-meter-strong",
21179 "roo-password-meter-grey"
21184 Roo.bootstrap.SecurePass.superclass.constructor.call(this, config);
21187 Roo.extend(Roo.bootstrap.SecurePass, Roo.bootstrap.Input, {
21189 * @cfg {String/Object} errors A Error spec, or true for a default spec (defaults to
21191 * PwdEmpty: "Please type a password, and then retype it to confirm.",
21192 * PwdShort: "Your password must be at least 6 characters long. Please type a different password.",
21193 * PwdLong: "Your password can't contain more than 16 characters. Please type a different password.",
21194 * PwdBadChar: "The password contains characters that aren't allowed. Please type a different password.",
21195 * IDInPwd: "Your password can't include the part of your ID. Please type a different password.",
21196 * FNInPwd: "Your password can't contain your first name. Please type a different password.",
21197 * LNInPwd: "Your password can't contain your last name. Please type a different password."
21207 * @cfg {String/Object} Label for the strength meter (defaults to
21208 * 'Password strength:')
21213 * @cfg {String/Object} pwdStrengths A pwdStrengths spec, or true for a default spec (defaults to
21214 * ['Weak', 'Medium', 'Strong'])
21217 pwdStrengths: false,
21230 initEvents: function ()
21232 Roo.bootstrap.SecurePass.superclass.initEvents.call(this);
21234 if (this.el.is('input[type=password]') && Roo.isSafari) {
21235 this.el.on('keydown', this.SafariOnKeyDown, this);
21238 this.el.on('keyup', this.checkStrength, this, {buffer: 50});
21241 onRender: function (ct, position)
21243 Roo.bootstrap.SecurePass.superclass.onRender.call(this, ct, position);
21244 this.wrap = this.el.wrap({cls: 'x-form-field-wrap'});
21245 this.trigger = this.wrap.createChild({tag: 'div', cls: 'StrengthMeter ' + this.triggerClass});
21247 this.trigger.createChild({
21252 cls: 'roo-password-meter-grey col-xs-12',
21255 //width: this.meterWidth + 'px'
21259 cls: 'roo-password-meter-text'
21265 if (this.hideTrigger) {
21266 this.trigger.setDisplayed(false);
21268 this.setSize(this.width || '', this.height || '');
21271 onDestroy: function ()
21273 if (this.trigger) {
21274 this.trigger.removeAllListeners();
21275 this.trigger.remove();
21278 this.wrap.remove();
21280 Roo.bootstrap.TriggerField.superclass.onDestroy.call(this);
21283 checkStrength: function ()
21285 var pwd = this.inputEl().getValue();
21286 if (pwd == this._lastPwd) {
21291 if (this.ClientSideStrongPassword(pwd)) {
21293 } else if (this.ClientSideMediumPassword(pwd)) {
21295 } else if (this.ClientSideWeakPassword(pwd)) {
21301 Roo.log('strength1: ' + strength);
21303 //var pm = this.trigger.child('div/div/div').dom;
21304 var pm = this.trigger.child('div/div');
21305 pm.removeClass(this.meterClass);
21306 pm.addClass(this.meterClass[strength]);
21309 var pt = this.trigger.child('/div').child('>*[class=roo-password-meter-text]').dom;
21311 pt.innerHTML = this.meterLabel + ' ' + this.pwdStrengths[strength];
21313 this._lastPwd = pwd;
21317 Roo.bootstrap.SecurePass.superclass.reset.call(this);
21319 this._lastPwd = '';
21321 var pm = this.trigger.child('div/div');
21322 pm.removeClass(this.meterClass);
21323 pm.addClass('roo-password-meter-grey');
21326 var pt = this.trigger.child('/div').child('>*[class=roo-password-meter-text]').dom;
21329 this.inputEl().dom.type='password';
21332 validateValue: function (value)
21335 if (!Roo.bootstrap.SecurePass.superclass.validateValue.call(this, value)) {
21338 if (value.length == 0) {
21339 if (this.allowBlank) {
21340 this.clearInvalid();
21344 this.markInvalid(this.errors.PwdEmpty);
21345 this.errorMsg = this.errors.PwdEmpty;
21353 if ('[\x21-\x7e]*'.match(value)) {
21354 this.markInvalid(this.errors.PwdBadChar);
21355 this.errorMsg = this.errors.PwdBadChar;
21358 if (value.length < 6) {
21359 this.markInvalid(this.errors.PwdShort);
21360 this.errorMsg = this.errors.PwdShort;
21363 if (value.length > 16) {
21364 this.markInvalid(this.errors.PwdLong);
21365 this.errorMsg = this.errors.PwdLong;
21369 if (this.ClientSideStrongPassword(value)) {
21371 } else if (this.ClientSideMediumPassword(value)) {
21373 } else if (this.ClientSideWeakPassword(value)) {
21380 if (strength < 2) {
21381 //this.markInvalid(this.errors.TooWeak);
21382 this.errorMsg = this.errors.TooWeak;
21387 console.log('strength2: ' + strength);
21389 //var pm = this.trigger.child('div/div/div').dom;
21391 var pm = this.trigger.child('div/div');
21392 pm.removeClass(this.meterClass);
21393 pm.addClass(this.meterClass[strength]);
21395 var pt = this.trigger.child('/div').child('>*[class=roo-password-meter-text]').dom;
21397 pt.innerHTML = this.meterLabel + ' ' + this.pwdStrengths[strength];
21399 this.errorMsg = '';
21403 CharacterSetChecks: function (type)
21406 this.fResult = false;
21409 isctype: function (character, type)
21412 case this.kCapitalLetter:
21413 if (character >= 'A' && character <= 'Z') {
21418 case this.kSmallLetter:
21419 if (character >= 'a' && character <= 'z') {
21425 if (character >= '0' && character <= '9') {
21430 case this.kPunctuation:
21431 if ('!@#$%^&*()_+-=\'";:[{]}|.>,</?`~'.indexOf(character) >= 0) {
21442 IsLongEnough: function (pwd, size)
21444 return !(pwd == null || isNaN(size) || pwd.length < size);
21447 SpansEnoughCharacterSets: function (word, nb)
21449 if (!this.IsLongEnough(word, nb))
21454 var characterSetChecks = new Array(
21455 new this.CharacterSetChecks(this.kCapitalLetter), new this.CharacterSetChecks(this.kSmallLetter),
21456 new this.CharacterSetChecks(this.kDigit), new this.CharacterSetChecks(this.kPunctuation)
21459 for (var index = 0; index < word.length; ++index) {
21460 for (var nCharSet = 0; nCharSet < characterSetChecks.length; ++nCharSet) {
21461 if (!characterSetChecks[nCharSet].fResult && this.isctype(word.charAt(index), characterSetChecks[nCharSet].type)) {
21462 characterSetChecks[nCharSet].fResult = true;
21469 for (var nCharSet = 0; nCharSet < characterSetChecks.length; ++nCharSet) {
21470 if (characterSetChecks[nCharSet].fResult) {
21475 if (nCharSets < nb) {
21481 ClientSideStrongPassword: function (pwd)
21483 return this.IsLongEnough(pwd, 8) && this.SpansEnoughCharacterSets(pwd, 3);
21486 ClientSideMediumPassword: function (pwd)
21488 return this.IsLongEnough(pwd, 7) && this.SpansEnoughCharacterSets(pwd, 2);
21491 ClientSideWeakPassword: function (pwd)
21493 return this.IsLongEnough(pwd, 6) || !this.IsLongEnough(pwd, 0);
21496 })//<script type="text/javascript">
21499 * Based Ext JS Library 1.1.1
21500 * Copyright(c) 2006-2007, Ext JS, LLC.
21506 * @class Roo.HtmlEditorCore
21507 * @extends Roo.Component
21508 * Provides a the editing component for the HTML editors in Roo. (bootstrap and Roo.form)
21510 * any element that has display set to 'none' can cause problems in Safari and Firefox.<br/><br/>
21513 Roo.HtmlEditorCore = function(config){
21516 Roo.HtmlEditorCore.superclass.constructor.call(this, config);
21521 * @event initialize
21522 * Fires when the editor is fully initialized (including the iframe)
21523 * @param {Roo.HtmlEditorCore} this
21528 * Fires when the editor is first receives the focus. Any insertion must wait
21529 * until after this event.
21530 * @param {Roo.HtmlEditorCore} this
21534 * @event beforesync
21535 * Fires before the textarea is updated with content from the editor iframe. Return false
21536 * to cancel the sync.
21537 * @param {Roo.HtmlEditorCore} this
21538 * @param {String} html
21542 * @event beforepush
21543 * Fires before the iframe editor is updated with content from the textarea. Return false
21544 * to cancel the push.
21545 * @param {Roo.HtmlEditorCore} this
21546 * @param {String} html
21551 * Fires when the textarea is updated with content from the editor iframe.
21552 * @param {Roo.HtmlEditorCore} this
21553 * @param {String} html
21558 * Fires when the iframe editor is updated with content from the textarea.
21559 * @param {Roo.HtmlEditorCore} this
21560 * @param {String} html
21565 * @event editorevent
21566 * Fires when on any editor (mouse up/down cursor movement etc.) - used for toolbar hooks.
21567 * @param {Roo.HtmlEditorCore} this
21573 // at this point this.owner is set, so we can start working out the whitelisted / blacklisted elements
21575 // defaults : white / black...
21576 this.applyBlacklists();
21583 Roo.extend(Roo.HtmlEditorCore, Roo.Component, {
21587 * @cfg {Roo.form.HtmlEditor|Roo.bootstrap.HtmlEditor} the owner field
21593 * @cfg {String} resizable 's' or 'se' or 'e' - wrapps the element in a
21598 * @cfg {Number} height (in pixels)
21602 * @cfg {Number} width (in pixels)
21607 * @cfg {Array} stylesheets url of stylesheets. set to [] to disable stylesheets.
21610 stylesheets: false,
21615 // private properties
21616 validationEvent : false,
21618 initialized : false,
21620 sourceEditMode : false,
21621 onFocus : Roo.emptyFn,
21623 hideMode:'offsets',
21627 // blacklist + whitelisted elements..
21634 * Protected method that will not generally be called directly. It
21635 * is called when the editor initializes the iframe with HTML contents. Override this method if you
21636 * want to change the initialization markup of the iframe (e.g. to add stylesheets).
21638 getDocMarkup : function(){
21642 // inherit styels from page...??
21643 if (this.stylesheets === false) {
21645 Roo.get(document.head).select('style').each(function(node) {
21646 st += node.dom.outerHTML || new XMLSerializer().serializeToString(node.dom);
21649 Roo.get(document.head).select('link').each(function(node) {
21650 st += node.dom.outerHTML || new XMLSerializer().serializeToString(node.dom);
21653 } else if (!this.stylesheets.length) {
21655 st = '<style type="text/css">' +
21656 'body{border:0;margin:0;padding:3px;height:98%;cursor:text;}' +
21659 st = '<style type="text/css">' +
21664 st += '<style type="text/css">' +
21665 'IMG { cursor: pointer } ' +
21668 var cls = 'roo-htmleditor-body';
21670 if(this.bodyCls.length){
21671 cls += ' ' + this.bodyCls;
21674 return '<html><head>' + st +
21675 //<style type="text/css">' +
21676 //'body{border:0;margin:0;padding:3px;height:98%;cursor:text;}' +
21678 ' </head><body class="' + cls + '"></body></html>';
21682 onRender : function(ct, position)
21685 //Roo.HtmlEditorCore.superclass.onRender.call(this, ct, position);
21686 this.el = this.owner.inputEl ? this.owner.inputEl() : this.owner.el;
21689 this.el.dom.style.border = '0 none';
21690 this.el.dom.setAttribute('tabIndex', -1);
21691 this.el.addClass('x-hidden hide');
21695 if(Roo.isIE){ // fix IE 1px bogus margin
21696 this.el.applyStyles('margin-top:-1px;margin-bottom:-1px;')
21700 this.frameId = Roo.id();
21704 var iframe = this.owner.wrap.createChild({
21706 cls: 'form-control', // bootstrap..
21708 name: this.frameId,
21709 frameBorder : 'no',
21710 'src' : Roo.SSL_SECURE_URL ? Roo.SSL_SECURE_URL : "javascript:false"
21715 this.iframe = iframe.dom;
21717 this.assignDocWin();
21719 this.doc.designMode = 'on';
21722 this.doc.write(this.getDocMarkup());
21726 var task = { // must defer to wait for browser to be ready
21728 //console.log("run task?" + this.doc.readyState);
21729 this.assignDocWin();
21730 if(this.doc.body || this.doc.readyState == 'complete'){
21732 this.doc.designMode="on";
21736 Roo.TaskMgr.stop(task);
21737 this.initEditor.defer(10, this);
21744 Roo.TaskMgr.start(task);
21749 onResize : function(w, h)
21751 Roo.log('resize: ' +w + ',' + h );
21752 //Roo.HtmlEditorCore.superclass.onResize.apply(this, arguments);
21756 if(typeof w == 'number'){
21758 this.iframe.style.width = w + 'px';
21760 if(typeof h == 'number'){
21762 this.iframe.style.height = h + 'px';
21764 (this.doc.body || this.doc.documentElement).style.height = (h - (this.iframePad*2)) + 'px';
21771 * Toggles the editor between standard and source edit mode.
21772 * @param {Boolean} sourceEdit (optional) True for source edit, false for standard
21774 toggleSourceEdit : function(sourceEditMode){
21776 this.sourceEditMode = sourceEditMode === true;
21778 if(this.sourceEditMode){
21780 Roo.get(this.iframe).addClass(['x-hidden','hide']); //FIXME - what's the BS styles for these
21783 Roo.get(this.iframe).removeClass(['x-hidden','hide']);
21784 //this.iframe.className = '';
21787 //this.setSize(this.owner.wrap.getSize());
21788 //this.fireEvent('editmodechange', this, this.sourceEditMode);
21795 * Protected method that will not generally be called directly. If you need/want
21796 * custom HTML cleanup, this is the method you should override.
21797 * @param {String} html The HTML to be cleaned
21798 * return {String} The cleaned HTML
21800 cleanHtml : function(html){
21801 html = String(html);
21802 if(html.length > 5){
21803 if(Roo.isSafari){ // strip safari nonsense
21804 html = html.replace(/\sclass="(?:Apple-style-span|khtml-block-placeholder)"/gi, '');
21807 if(html == ' '){
21814 * HTML Editor -> Textarea
21815 * Protected method that will not generally be called directly. Syncs the contents
21816 * of the editor iframe with the textarea.
21818 syncValue : function(){
21819 if(this.initialized){
21820 var bd = (this.doc.body || this.doc.documentElement);
21821 //this.cleanUpPaste(); -- this is done else where and causes havoc..
21822 var html = bd.innerHTML;
21824 var bs = bd.getAttribute('style'); // Safari puts text-align styles on the body element!
21825 var m = bs ? bs.match(/text-align:(.*?);/i) : false;
21827 html = '<div style="'+m[0]+'">' + html + '</div>';
21830 html = this.cleanHtml(html);
21831 // fix up the special chars.. normaly like back quotes in word...
21832 // however we do not want to do this with chinese..
21833 html = html.replace(/([\x80-\uffff])/g, function (a, b) {
21834 var cc = b.charCodeAt();
21836 (cc >= 0x4E00 && cc < 0xA000 ) ||
21837 (cc >= 0x3400 && cc < 0x4E00 ) ||
21838 (cc >= 0xf900 && cc < 0xfb00 )
21844 if(this.owner.fireEvent('beforesync', this, html) !== false){
21845 this.el.dom.value = html;
21846 this.owner.fireEvent('sync', this, html);
21852 * Protected method that will not generally be called directly. Pushes the value of the textarea
21853 * into the iframe editor.
21855 pushValue : function(){
21856 if(this.initialized){
21857 var v = this.el.dom.value.trim();
21859 // if(v.length < 1){
21863 if(this.owner.fireEvent('beforepush', this, v) !== false){
21864 var d = (this.doc.body || this.doc.documentElement);
21866 this.cleanUpPaste();
21867 this.el.dom.value = d.innerHTML;
21868 this.owner.fireEvent('push', this, v);
21874 deferFocus : function(){
21875 this.focus.defer(10, this);
21879 focus : function(){
21880 if(this.win && !this.sourceEditMode){
21887 assignDocWin: function()
21889 var iframe = this.iframe;
21892 this.doc = iframe.contentWindow.document;
21893 this.win = iframe.contentWindow;
21895 // if (!Roo.get(this.frameId)) {
21898 // this.doc = (iframe.contentDocument || Roo.get(this.frameId).dom.document);
21899 // this.win = Roo.get(this.frameId).dom.contentWindow;
21901 if (!Roo.get(this.frameId) && !iframe.contentDocument) {
21905 this.doc = (iframe.contentDocument || Roo.get(this.frameId).dom.document);
21906 this.win = (iframe.contentWindow || Roo.get(this.frameId).dom.contentWindow);
21911 initEditor : function(){
21912 //console.log("INIT EDITOR");
21913 this.assignDocWin();
21917 this.doc.designMode="on";
21919 this.doc.write(this.getDocMarkup());
21922 var dbody = (this.doc.body || this.doc.documentElement);
21923 //var ss = this.el.getStyles('font-size', 'font-family', 'background-image', 'background-repeat');
21924 // this copies styles from the containing element into thsi one..
21925 // not sure why we need all of this..
21926 //var ss = this.el.getStyles('font-size', 'background-image', 'background-repeat');
21928 //var ss = this.el.getStyles( 'background-image', 'background-repeat');
21929 //ss['background-attachment'] = 'fixed'; // w3c
21930 dbody.bgProperties = 'fixed'; // ie
21931 //Roo.DomHelper.applyStyles(dbody, ss);
21932 Roo.EventManager.on(this.doc, {
21933 //'mousedown': this.onEditorEvent,
21934 'mouseup': this.onEditorEvent,
21935 'dblclick': this.onEditorEvent,
21936 'click': this.onEditorEvent,
21937 'keyup': this.onEditorEvent,
21942 Roo.EventManager.on(this.doc, 'keypress', this.mozKeyPress, this);
21944 if(Roo.isIE || Roo.isSafari || Roo.isOpera){
21945 Roo.EventManager.on(this.doc, 'keydown', this.fixKeys, this);
21947 this.initialized = true;
21949 this.owner.fireEvent('initialize', this);
21954 onDestroy : function(){
21960 //for (var i =0; i < this.toolbars.length;i++) {
21961 // // fixme - ask toolbars for heights?
21962 // this.toolbars[i].onDestroy();
21965 //this.wrap.dom.innerHTML = '';
21966 //this.wrap.remove();
21971 onFirstFocus : function(){
21973 this.assignDocWin();
21976 this.activated = true;
21979 if(Roo.isGecko){ // prevent silly gecko errors
21981 var s = this.win.getSelection();
21982 if(!s.focusNode || s.focusNode.nodeType != 3){
21983 var r = s.getRangeAt(0);
21984 r.selectNodeContents((this.doc.body || this.doc.documentElement));
21989 this.execCmd('useCSS', true);
21990 this.execCmd('styleWithCSS', false);
21993 this.owner.fireEvent('activate', this);
21997 adjustFont: function(btn){
21998 var adjust = btn.cmd == 'increasefontsize' ? 1 : -1;
21999 //if(Roo.isSafari){ // safari
22002 var v = parseInt(this.doc.queryCommandValue('FontSize')|| 3, 10);
22003 if(Roo.isSafari){ // safari
22004 var sm = { 10 : 1, 13: 2, 16:3, 18:4, 24: 5, 32:6, 48: 7 };
22005 v = (v < 10) ? 10 : v;
22006 v = (v > 48) ? 48 : v;
22007 v = typeof(sm[v]) == 'undefined' ? 1 : sm[v];
22012 v = Math.max(1, v+adjust);
22014 this.execCmd('FontSize', v );
22017 onEditorEvent : function(e)
22019 this.owner.fireEvent('editorevent', this, e);
22020 // this.updateToolbar();
22021 this.syncValue(); //we can not sync so often.. sync cleans, so this breaks stuff
22024 insertTag : function(tg)
22026 // could be a bit smarter... -> wrap the current selected tRoo..
22027 if (tg.toLowerCase() == 'span' || tg.toLowerCase() == 'code') {
22029 range = this.createRange(this.getSelection());
22030 var wrappingNode = this.doc.createElement(tg.toLowerCase());
22031 wrappingNode.appendChild(range.extractContents());
22032 range.insertNode(wrappingNode);
22039 this.execCmd("formatblock", tg);
22043 insertText : function(txt)
22047 var range = this.createRange();
22048 range.deleteContents();
22049 //alert(Sender.getAttribute('label'));
22051 range.insertNode(this.doc.createTextNode(txt));
22057 * Executes a Midas editor command on the editor document and performs necessary focus and
22058 * toolbar updates. <b>This should only be called after the editor is initialized.</b>
22059 * @param {String} cmd The Midas command
22060 * @param {String/Boolean} value (optional) The value to pass to the command (defaults to null)
22062 relayCmd : function(cmd, value){
22064 this.execCmd(cmd, value);
22065 this.owner.fireEvent('editorevent', this);
22066 //this.updateToolbar();
22067 this.owner.deferFocus();
22071 * Executes a Midas editor command directly on the editor document.
22072 * For visual commands, you should use {@link #relayCmd} instead.
22073 * <b>This should only be called after the editor is initialized.</b>
22074 * @param {String} cmd The Midas command
22075 * @param {String/Boolean} value (optional) The value to pass to the command (defaults to null)
22077 execCmd : function(cmd, value){
22078 this.doc.execCommand(cmd, false, value === undefined ? null : value);
22085 * Inserts the passed text at the current cursor position. Note: the editor must be initialized and activated
22087 * @param {String} text | dom node..
22089 insertAtCursor : function(text)
22092 if(!this.activated){
22098 var r = this.doc.selection.createRange();
22109 if(Roo.isGecko || Roo.isOpera || Roo.isSafari){
22113 // from jquery ui (MIT licenced)
22115 var win = this.win;
22117 if (win.getSelection && win.getSelection().getRangeAt) {
22118 range = win.getSelection().getRangeAt(0);
22119 node = typeof(text) == 'string' ? range.createContextualFragment(text) : text;
22120 range.insertNode(node);
22121 } else if (win.document.selection && win.document.selection.createRange) {
22122 // no firefox support
22123 var txt = typeof(text) == 'string' ? text : text.outerHTML;
22124 win.document.selection.createRange().pasteHTML(txt);
22126 // no firefox support
22127 var txt = typeof(text) == 'string' ? text : text.outerHTML;
22128 this.execCmd('InsertHTML', txt);
22137 mozKeyPress : function(e){
22139 var c = e.getCharCode(), cmd;
22142 c = String.fromCharCode(c).toLowerCase();
22156 this.cleanUpPaste.defer(100, this);
22164 e.preventDefault();
22172 fixKeys : function(){ // load time branching for fastest keydown performance
22174 return function(e){
22175 var k = e.getKey(), r;
22178 r = this.doc.selection.createRange();
22181 r.pasteHTML('    ');
22188 r = this.doc.selection.createRange();
22190 var target = r.parentElement();
22191 if(!target || target.tagName.toLowerCase() != 'li'){
22193 r.pasteHTML('<br />');
22199 if (String.fromCharCode(k).toLowerCase() == 'v') { // paste
22200 this.cleanUpPaste.defer(100, this);
22206 }else if(Roo.isOpera){
22207 return function(e){
22208 var k = e.getKey();
22212 this.execCmd('InsertHTML','    ');
22215 if (String.fromCharCode(k).toLowerCase() == 'v') { // paste
22216 this.cleanUpPaste.defer(100, this);
22221 }else if(Roo.isSafari){
22222 return function(e){
22223 var k = e.getKey();
22227 this.execCmd('InsertText','\t');
22231 if (String.fromCharCode(k).toLowerCase() == 'v') { // paste
22232 this.cleanUpPaste.defer(100, this);
22240 getAllAncestors: function()
22242 var p = this.getSelectedNode();
22245 a.push(p); // push blank onto stack..
22246 p = this.getParentElement();
22250 while (p && (p.nodeType == 1) && (p.tagName.toLowerCase() != 'body')) {
22254 a.push(this.doc.body);
22258 lastSelNode : false,
22261 getSelection : function()
22263 this.assignDocWin();
22264 return Roo.isIE ? this.doc.selection : this.win.getSelection();
22267 getSelectedNode: function()
22269 // this may only work on Gecko!!!
22271 // should we cache this!!!!
22276 var range = this.createRange(this.getSelection()).cloneRange();
22279 var parent = range.parentElement();
22281 var testRange = range.duplicate();
22282 testRange.moveToElementText(parent);
22283 if (testRange.inRange(range)) {
22286 if ((parent.nodeType != 1) || (parent.tagName.toLowerCase() == 'body')) {
22289 parent = parent.parentElement;
22294 // is ancestor a text element.
22295 var ac = range.commonAncestorContainer;
22296 if (ac.nodeType == 3) {
22297 ac = ac.parentNode;
22300 var ar = ac.childNodes;
22303 var other_nodes = [];
22304 var has_other_nodes = false;
22305 for (var i=0;i<ar.length;i++) {
22306 if ((ar[i].nodeType == 3) && (!ar[i].data.length)) { // empty text ?
22309 // fullly contained node.
22311 if (this.rangeIntersectsNode(range,ar[i]) && this.rangeCompareNode(range,ar[i]) == 3) {
22316 // probably selected..
22317 if ((ar[i].nodeType == 1) && this.rangeIntersectsNode(range,ar[i]) && (this.rangeCompareNode(range,ar[i]) > 0)) {
22318 other_nodes.push(ar[i]);
22322 if (!this.rangeIntersectsNode(range,ar[i])|| (this.rangeCompareNode(range,ar[i]) == 0)) {
22327 has_other_nodes = true;
22329 if (!nodes.length && other_nodes.length) {
22330 nodes= other_nodes;
22332 if (has_other_nodes || !nodes.length || (nodes.length > 1)) {
22338 createRange: function(sel)
22340 // this has strange effects when using with
22341 // top toolbar - not sure if it's a great idea.
22342 //this.editor.contentWindow.focus();
22343 if (typeof sel != "undefined") {
22345 return sel.getRangeAt ? sel.getRangeAt(0) : sel.createRange();
22347 return this.doc.createRange();
22350 return this.doc.createRange();
22353 getParentElement: function()
22356 this.assignDocWin();
22357 var sel = Roo.isIE ? this.doc.selection : this.win.getSelection();
22359 var range = this.createRange(sel);
22362 var p = range.commonAncestorContainer;
22363 while (p.nodeType == 3) { // text node
22374 * Range intersection.. the hard stuff...
22378 * [ -- selected range --- ]
22382 * if end is before start or hits it. fail.
22383 * if start is after end or hits it fail.
22385 * if either hits (but other is outside. - then it's not
22391 // @see http://www.thismuchiknow.co.uk/?p=64.
22392 rangeIntersectsNode : function(range, node)
22394 var nodeRange = node.ownerDocument.createRange();
22396 nodeRange.selectNode(node);
22398 nodeRange.selectNodeContents(node);
22401 var rangeStartRange = range.cloneRange();
22402 rangeStartRange.collapse(true);
22404 var rangeEndRange = range.cloneRange();
22405 rangeEndRange.collapse(false);
22407 var nodeStartRange = nodeRange.cloneRange();
22408 nodeStartRange.collapse(true);
22410 var nodeEndRange = nodeRange.cloneRange();
22411 nodeEndRange.collapse(false);
22413 return rangeStartRange.compareBoundaryPoints(
22414 Range.START_TO_START, nodeEndRange) == -1 &&
22415 rangeEndRange.compareBoundaryPoints(
22416 Range.START_TO_START, nodeStartRange) == 1;
22420 rangeCompareNode : function(range, node)
22422 var nodeRange = node.ownerDocument.createRange();
22424 nodeRange.selectNode(node);
22426 nodeRange.selectNodeContents(node);
22430 range.collapse(true);
22432 nodeRange.collapse(true);
22434 var ss = range.compareBoundaryPoints( Range.START_TO_START, nodeRange);
22435 var ee = range.compareBoundaryPoints( Range.END_TO_END, nodeRange);
22437 //Roo.log(node.tagName + ': ss='+ss +', ee='+ee)
22439 var nodeIsBefore = ss == 1;
22440 var nodeIsAfter = ee == -1;
22442 if (nodeIsBefore && nodeIsAfter) {
22445 if (!nodeIsBefore && nodeIsAfter) {
22446 return 1; //right trailed.
22449 if (nodeIsBefore && !nodeIsAfter) {
22450 return 2; // left trailed.
22456 // private? - in a new class?
22457 cleanUpPaste : function()
22459 // cleans up the whole document..
22460 Roo.log('cleanuppaste');
22462 this.cleanUpChildren(this.doc.body);
22463 var clean = this.cleanWordChars(this.doc.body.innerHTML);
22464 if (clean != this.doc.body.innerHTML) {
22465 this.doc.body.innerHTML = clean;
22470 cleanWordChars : function(input) {// change the chars to hex code
22471 var he = Roo.HtmlEditorCore;
22473 var output = input;
22474 Roo.each(he.swapCodes, function(sw) {
22475 var swapper = new RegExp("\\u" + sw[0].toString(16), "g"); // hex codes
22477 output = output.replace(swapper, sw[1]);
22484 cleanUpChildren : function (n)
22486 if (!n.childNodes.length) {
22489 for (var i = n.childNodes.length-1; i > -1 ; i--) {
22490 this.cleanUpChild(n.childNodes[i]);
22497 cleanUpChild : function (node)
22500 //console.log(node);
22501 if (node.nodeName == "#text") {
22502 // clean up silly Windows -- stuff?
22505 if (node.nodeName == "#comment") {
22506 node.parentNode.removeChild(node);
22507 // clean up silly Windows -- stuff?
22510 var lcname = node.tagName.toLowerCase();
22511 // we ignore whitelists... ?? = not really the way to go, but we probably have not got a full
22512 // whitelist of tags..
22514 if (this.black.indexOf(lcname) > -1 && this.clearUp ) {
22516 node.parentNode.removeChild(node);
22521 var remove_keep_children= Roo.HtmlEditorCore.remove.indexOf(node.tagName.toLowerCase()) > -1;
22523 // remove <a name=....> as rendering on yahoo mailer is borked with this.
22524 // this will have to be flaged elsewhere - perhaps ablack=name... on the mailer..
22526 //if (node.tagName.toLowerCase() == 'a' && !node.hasAttribute('href')) {
22527 // remove_keep_children = true;
22530 if (remove_keep_children) {
22531 this.cleanUpChildren(node);
22532 // inserts everything just before this node...
22533 while (node.childNodes.length) {
22534 var cn = node.childNodes[0];
22535 node.removeChild(cn);
22536 node.parentNode.insertBefore(cn, node);
22538 node.parentNode.removeChild(node);
22542 if (!node.attributes || !node.attributes.length) {
22543 this.cleanUpChildren(node);
22547 function cleanAttr(n,v)
22550 if (v.match(/^\./) || v.match(/^\//)) {
22553 if (v.match(/^(http|https):\/\//) || v.match(/^mailto:/) || v.match(/^ftp:/)) {
22556 if (v.match(/^#/)) {
22559 // Roo.log("(REMOVE TAG)"+ node.tagName +'.' + n + '=' + v);
22560 node.removeAttribute(n);
22564 var cwhite = this.cwhite;
22565 var cblack = this.cblack;
22567 function cleanStyle(n,v)
22569 if (v.match(/expression/)) { //XSS?? should we even bother..
22570 node.removeAttribute(n);
22574 var parts = v.split(/;/);
22577 Roo.each(parts, function(p) {
22578 p = p.replace(/^\s+/g,'').replace(/\s+$/g,'');
22582 var l = p.split(':').shift().replace(/\s+/g,'');
22583 l = l.replace(/^\s+/g,'').replace(/\s+$/g,'');
22585 if ( cwhite.length && cblack.indexOf(l) > -1) {
22586 // Roo.log('(REMOVE CSS)' + node.tagName +'.' + n + ':'+l + '=' + v);
22587 //node.removeAttribute(n);
22591 // only allow 'c whitelisted system attributes'
22592 if ( cwhite.length && cwhite.indexOf(l) < 0) {
22593 // Roo.log('(REMOVE CSS)' + node.tagName +'.' + n + ':'+l + '=' + v);
22594 //node.removeAttribute(n);
22604 if (clean.length) {
22605 node.setAttribute(n, clean.join(';'));
22607 node.removeAttribute(n);
22613 for (var i = node.attributes.length-1; i > -1 ; i--) {
22614 var a = node.attributes[i];
22617 if (a.name.toLowerCase().substr(0,2)=='on') {
22618 node.removeAttribute(a.name);
22621 if (Roo.HtmlEditorCore.ablack.indexOf(a.name.toLowerCase()) > -1) {
22622 node.removeAttribute(a.name);
22625 if (Roo.HtmlEditorCore.aclean.indexOf(a.name.toLowerCase()) > -1) {
22626 cleanAttr(a.name,a.value); // fixme..
22629 if (a.name == 'style') {
22630 cleanStyle(a.name,a.value);
22633 /// clean up MS crap..
22634 // tecnically this should be a list of valid class'es..
22637 if (a.name == 'class') {
22638 if (a.value.match(/^Mso/)) {
22639 node.className = '';
22642 if (a.value.match(/^body$/)) {
22643 node.className = '';
22654 this.cleanUpChildren(node);
22660 * Clean up MS wordisms...
22662 cleanWord : function(node)
22667 this.cleanWord(this.doc.body);
22670 if (node.nodeName == "#text") {
22671 // clean up silly Windows -- stuff?
22674 if (node.nodeName == "#comment") {
22675 node.parentNode.removeChild(node);
22676 // clean up silly Windows -- stuff?
22680 if (node.tagName.toLowerCase().match(/^(style|script|applet|embed|noframes|noscript)$/)) {
22681 node.parentNode.removeChild(node);
22685 // remove - but keep children..
22686 if (node.tagName.toLowerCase().match(/^(meta|link|\\?xml:|st1:|o:|font)/)) {
22687 while (node.childNodes.length) {
22688 var cn = node.childNodes[0];
22689 node.removeChild(cn);
22690 node.parentNode.insertBefore(cn, node);
22692 node.parentNode.removeChild(node);
22693 this.iterateChildren(node, this.cleanWord);
22697 if (node.className.length) {
22699 var cn = node.className.split(/\W+/);
22701 Roo.each(cn, function(cls) {
22702 if (cls.match(/Mso[a-zA-Z]+/)) {
22707 node.className = cna.length ? cna.join(' ') : '';
22709 node.removeAttribute("class");
22713 if (node.hasAttribute("lang")) {
22714 node.removeAttribute("lang");
22717 if (node.hasAttribute("style")) {
22719 var styles = node.getAttribute("style").split(";");
22721 Roo.each(styles, function(s) {
22722 if (!s.match(/:/)) {
22725 var kv = s.split(":");
22726 if (kv[0].match(/^(mso-|line|font|background|margin|padding|color)/)) {
22729 // what ever is left... we allow.
22732 node.setAttribute("style", nstyle.length ? nstyle.join(';') : '');
22733 if (!nstyle.length) {
22734 node.removeAttribute('style');
22737 this.iterateChildren(node, this.cleanWord);
22743 * iterateChildren of a Node, calling fn each time, using this as the scole..
22744 * @param {DomNode} node node to iterate children of.
22745 * @param {Function} fn method of this class to call on each item.
22747 iterateChildren : function(node, fn)
22749 if (!node.childNodes.length) {
22752 for (var i = node.childNodes.length-1; i > -1 ; i--) {
22753 fn.call(this, node.childNodes[i])
22759 * cleanTableWidths.
22761 * Quite often pasting from word etc.. results in tables with column and widths.
22762 * This does not work well on fluid HTML layouts - like emails. - so this code should hunt an destroy them..
22765 cleanTableWidths : function(node)
22770 this.cleanTableWidths(this.doc.body);
22775 if (node.nodeName == "#text" || node.nodeName == "#comment") {
22778 Roo.log(node.tagName);
22779 if (!node.tagName.toLowerCase().match(/^(table|td|tr)$/)) {
22780 this.iterateChildren(node, this.cleanTableWidths);
22783 if (node.hasAttribute('width')) {
22784 node.removeAttribute('width');
22788 if (node.hasAttribute("style")) {
22791 var styles = node.getAttribute("style").split(";");
22793 Roo.each(styles, function(s) {
22794 if (!s.match(/:/)) {
22797 var kv = s.split(":");
22798 if (kv[0].match(/^\s*(width|min-width)\s*$/)) {
22801 // what ever is left... we allow.
22804 node.setAttribute("style", nstyle.length ? nstyle.join(';') : '');
22805 if (!nstyle.length) {
22806 node.removeAttribute('style');
22810 this.iterateChildren(node, this.cleanTableWidths);
22818 domToHTML : function(currentElement, depth, nopadtext) {
22820 depth = depth || 0;
22821 nopadtext = nopadtext || false;
22823 if (!currentElement) {
22824 return this.domToHTML(this.doc.body);
22827 //Roo.log(currentElement);
22829 var allText = false;
22830 var nodeName = currentElement.nodeName;
22831 var tagName = Roo.util.Format.htmlEncode(currentElement.tagName);
22833 if (nodeName == '#text') {
22835 return nopadtext ? currentElement.nodeValue : currentElement.nodeValue.trim();
22840 if (nodeName != 'BODY') {
22843 // Prints the node tagName, such as <A>, <IMG>, etc
22846 for(i = 0; i < currentElement.attributes.length;i++) {
22848 var aname = currentElement.attributes.item(i).name;
22849 if (!currentElement.attributes.item(i).value.length) {
22852 attr.push(aname + '="' + Roo.util.Format.htmlEncode(currentElement.attributes.item(i).value) + '"' );
22855 ret = "<"+currentElement.tagName+ ( attr.length ? (' ' + attr.join(' ') ) : '') + ">";
22864 if (['IMG', 'BR', 'HR', 'INPUT'].indexOf(tagName) > -1) {
22867 if (['PRE', 'TEXTAREA', 'TD', 'A', 'SPAN'].indexOf(tagName) > -1) { // or code?
22872 // Traverse the tree
22874 var currentElementChild = currentElement.childNodes.item(i);
22875 var allText = true;
22876 var innerHTML = '';
22878 while (currentElementChild) {
22879 // Formatting code (indent the tree so it looks nice on the screen)
22880 var nopad = nopadtext;
22881 if (lastnode == 'SPAN') {
22885 if (currentElementChild.nodeName == '#text') {
22886 var toadd = Roo.util.Format.htmlEncode(currentElementChild.nodeValue);
22887 toadd = nopadtext ? toadd : toadd.trim();
22888 if (!nopad && toadd.length > 80) {
22889 innerHTML += "\n" + (new Array( depth + 1 )).join( " " );
22891 innerHTML += toadd;
22894 currentElementChild = currentElement.childNodes.item(i);
22900 innerHTML += nopad ? '' : "\n" + (new Array( depth + 1 )).join( " " );
22902 // Recursively traverse the tree structure of the child node
22903 innerHTML += this.domToHTML(currentElementChild, depth+1, nopadtext);
22904 lastnode = currentElementChild.nodeName;
22906 currentElementChild=currentElement.childNodes.item(i);
22912 // The remaining code is mostly for formatting the tree
22913 ret+= nopadtext ? '' : "\n" + (new Array( depth )).join( " " );
22918 ret+= "</"+tagName+">";
22924 applyBlacklists : function()
22926 var w = typeof(this.owner.white) != 'undefined' && this.owner.white ? this.owner.white : [];
22927 var b = typeof(this.owner.black) != 'undefined' && this.owner.black ? this.owner.black : [];
22931 Roo.each(Roo.HtmlEditorCore.white, function(tag) {
22932 if (b.indexOf(tag) > -1) {
22935 this.white.push(tag);
22939 Roo.each(w, function(tag) {
22940 if (b.indexOf(tag) > -1) {
22943 if (this.white.indexOf(tag) > -1) {
22946 this.white.push(tag);
22951 Roo.each(Roo.HtmlEditorCore.black, function(tag) {
22952 if (w.indexOf(tag) > -1) {
22955 this.black.push(tag);
22959 Roo.each(b, function(tag) {
22960 if (w.indexOf(tag) > -1) {
22963 if (this.black.indexOf(tag) > -1) {
22966 this.black.push(tag);
22971 w = typeof(this.owner.cwhite) != 'undefined' && this.owner.cwhite ? this.owner.cwhite : [];
22972 b = typeof(this.owner.cblack) != 'undefined' && this.owner.cblack ? this.owner.cblack : [];
22976 Roo.each(Roo.HtmlEditorCore.cwhite, function(tag) {
22977 if (b.indexOf(tag) > -1) {
22980 this.cwhite.push(tag);
22984 Roo.each(w, function(tag) {
22985 if (b.indexOf(tag) > -1) {
22988 if (this.cwhite.indexOf(tag) > -1) {
22991 this.cwhite.push(tag);
22996 Roo.each(Roo.HtmlEditorCore.cblack, function(tag) {
22997 if (w.indexOf(tag) > -1) {
23000 this.cblack.push(tag);
23004 Roo.each(b, function(tag) {
23005 if (w.indexOf(tag) > -1) {
23008 if (this.cblack.indexOf(tag) > -1) {
23011 this.cblack.push(tag);
23016 setStylesheets : function(stylesheets)
23018 if(typeof(stylesheets) == 'string'){
23019 Roo.get(this.iframe.contentDocument.head).createChild({
23021 rel : 'stylesheet',
23030 Roo.each(stylesheets, function(s) {
23035 Roo.get(_this.iframe.contentDocument.head).createChild({
23037 rel : 'stylesheet',
23046 removeStylesheets : function()
23050 Roo.each(Roo.get(_this.iframe.contentDocument.head).select('link[rel=stylesheet]', true).elements, function(s){
23055 setStyle : function(style)
23057 Roo.get(this.iframe.contentDocument.head).createChild({
23066 // hide stuff that is not compatible
23080 * @event specialkey
23084 * @cfg {String} fieldClass @hide
23087 * @cfg {String} focusClass @hide
23090 * @cfg {String} autoCreate @hide
23093 * @cfg {String} inputType @hide
23096 * @cfg {String} invalidClass @hide
23099 * @cfg {String} invalidText @hide
23102 * @cfg {String} msgFx @hide
23105 * @cfg {String} validateOnBlur @hide
23109 Roo.HtmlEditorCore.white = [
23110 'area', 'br', 'img', 'input', 'hr', 'wbr',
23112 'address', 'blockquote', 'center', 'dd', 'dir', 'div',
23113 'dl', 'dt', 'h1', 'h2', 'h3', 'h4',
23114 'h5', 'h6', 'hr', 'isindex', 'listing', 'marquee',
23115 'menu', 'multicol', 'ol', 'p', 'plaintext', 'pre',
23116 'table', 'ul', 'xmp',
23118 'caption', 'col', 'colgroup', 'tbody', 'td', 'tfoot', 'th',
23121 'dir', 'menu', 'ol', 'ul', 'dl',
23127 Roo.HtmlEditorCore.black = [
23128 // 'embed', 'object', // enable - backend responsiblity to clean thiese
23130 'base', 'basefont', 'bgsound', 'blink', 'body',
23131 'frame', 'frameset', 'head', 'html', 'ilayer',
23132 'iframe', 'layer', 'link', 'meta', 'object',
23133 'script', 'style' ,'title', 'xml' // clean later..
23135 Roo.HtmlEditorCore.clean = [
23136 'script', 'style', 'title', 'xml'
23138 Roo.HtmlEditorCore.remove = [
23143 Roo.HtmlEditorCore.ablack = [
23147 Roo.HtmlEditorCore.aclean = [
23148 'action', 'background', 'codebase', 'dynsrc', 'href', 'lowsrc'
23152 Roo.HtmlEditorCore.pwhite= [
23153 'http', 'https', 'mailto'
23156 // white listed style attributes.
23157 Roo.HtmlEditorCore.cwhite= [
23158 // 'text-align', /// default is to allow most things..
23164 // black listed style attributes.
23165 Roo.HtmlEditorCore.cblack= [
23166 // 'font-size' -- this can be set by the project
23170 Roo.HtmlEditorCore.swapCodes =[
23189 * @class Roo.bootstrap.HtmlEditor
23190 * @extends Roo.bootstrap.TextArea
23191 * Bootstrap HtmlEditor class
23194 * Create a new HtmlEditor
23195 * @param {Object} config The config object
23198 Roo.bootstrap.HtmlEditor = function(config){
23199 Roo.bootstrap.HtmlEditor.superclass.constructor.call(this, config);
23200 if (!this.toolbars) {
23201 this.toolbars = [];
23204 this.editorcore = new Roo.HtmlEditorCore(Roo.apply({ owner : this} , config));
23207 * @event initialize
23208 * Fires when the editor is fully initialized (including the iframe)
23209 * @param {HtmlEditor} this
23214 * Fires when the editor is first receives the focus. Any insertion must wait
23215 * until after this event.
23216 * @param {HtmlEditor} this
23220 * @event beforesync
23221 * Fires before the textarea is updated with content from the editor iframe. Return false
23222 * to cancel the sync.
23223 * @param {HtmlEditor} this
23224 * @param {String} html
23228 * @event beforepush
23229 * Fires before the iframe editor is updated with content from the textarea. Return false
23230 * to cancel the push.
23231 * @param {HtmlEditor} this
23232 * @param {String} html
23237 * Fires when the textarea is updated with content from the editor iframe.
23238 * @param {HtmlEditor} this
23239 * @param {String} html
23244 * Fires when the iframe editor is updated with content from the textarea.
23245 * @param {HtmlEditor} this
23246 * @param {String} html
23250 * @event editmodechange
23251 * Fires when the editor switches edit modes
23252 * @param {HtmlEditor} this
23253 * @param {Boolean} sourceEdit True if source edit, false if standard editing.
23255 editmodechange: true,
23257 * @event editorevent
23258 * Fires when on any editor (mouse up/down cursor movement etc.) - used for toolbar hooks.
23259 * @param {HtmlEditor} this
23263 * @event firstfocus
23264 * Fires when on first focus - needed by toolbars..
23265 * @param {HtmlEditor} this
23270 * Auto save the htmlEditor value as a file into Events
23271 * @param {HtmlEditor} this
23275 * @event savedpreview
23276 * preview the saved version of htmlEditor
23277 * @param {HtmlEditor} this
23284 Roo.extend(Roo.bootstrap.HtmlEditor, Roo.bootstrap.TextArea, {
23288 * @cfg {Array} toolbars Array of toolbars. - defaults to just the Standard one
23293 * @cfg {Array} buttons Array of toolbar's buttons. - defaults to empty
23298 * @cfg {String} resizable 's' or 'se' or 'e' - wrapps the element in a
23303 * @cfg {Number} height (in pixels)
23307 * @cfg {Number} width (in pixels)
23312 * @cfg {Array} stylesheets url of stylesheets. set to [] to disable stylesheets.
23315 stylesheets: false,
23320 // private properties
23321 validationEvent : false,
23323 initialized : false,
23326 onFocus : Roo.emptyFn,
23328 hideMode:'offsets',
23330 tbContainer : false,
23334 toolbarContainer :function() {
23335 return this.wrap.select('.x-html-editor-tb',true).first();
23339 * Protected method that will not generally be called directly. It
23340 * is called when the editor creates its toolbar. Override this method if you need to
23341 * add custom toolbar buttons.
23342 * @param {HtmlEditor} editor
23344 createToolbar : function(){
23345 Roo.log('renewing');
23346 Roo.log("create toolbars");
23348 this.toolbars = [ new Roo.bootstrap.htmleditor.ToolbarStandard({editor: this} ) ];
23349 this.toolbars[0].render(this.toolbarContainer());
23353 // if (!editor.toolbars || !editor.toolbars.length) {
23354 // editor.toolbars = [ new Roo.bootstrap.HtmlEditor.ToolbarStandard() ]; // can be empty?
23357 // for (var i =0 ; i < editor.toolbars.length;i++) {
23358 // editor.toolbars[i] = Roo.factory(
23359 // typeof(editor.toolbars[i]) == 'string' ?
23360 // { xtype: editor.toolbars[i]} : editor.toolbars[i],
23361 // Roo.bootstrap.HtmlEditor);
23362 // editor.toolbars[i].init(editor);
23368 onRender : function(ct, position)
23370 // Roo.log("Call onRender: " + this.xtype);
23372 Roo.bootstrap.HtmlEditor.superclass.onRender.call(this, ct, position);
23374 this.wrap = this.inputEl().wrap({
23375 cls:'x-html-editor-wrap', cn:{cls:'x-html-editor-tb'}
23378 this.editorcore.onRender(ct, position);
23380 if (this.resizable) {
23381 this.resizeEl = new Roo.Resizable(this.wrap, {
23385 minHeight : this.height,
23386 height: this.height,
23387 handles : this.resizable,
23390 resize : function(r, w, h) {
23391 _t.onResize(w,h); // -something
23397 this.createToolbar(this);
23400 if(!this.width && this.resizable){
23401 this.setSize(this.wrap.getSize());
23403 if (this.resizeEl) {
23404 this.resizeEl.resizeTo.defer(100, this.resizeEl,[ this.width,this.height ] );
23405 // should trigger onReize..
23411 onResize : function(w, h)
23413 Roo.log('resize: ' +w + ',' + h );
23414 Roo.bootstrap.HtmlEditor.superclass.onResize.apply(this, arguments);
23418 if(this.inputEl() ){
23419 if(typeof w == 'number'){
23420 var aw = w - this.wrap.getFrameWidth('lr');
23421 this.inputEl().setWidth(this.adjustWidth('textarea', aw));
23424 if(typeof h == 'number'){
23425 var tbh = -11; // fixme it needs to tool bar size!
23426 for (var i =0; i < this.toolbars.length;i++) {
23427 // fixme - ask toolbars for heights?
23428 tbh += this.toolbars[i].el.getHeight();
23429 //if (this.toolbars[i].footer) {
23430 // tbh += this.toolbars[i].footer.el.getHeight();
23438 var ah = h - this.wrap.getFrameWidth('tb') - tbh;// this.tb.el.getHeight();
23439 ah -= 5; // knock a few pixes off for look..
23440 this.inputEl().setHeight(this.adjustWidth('textarea', ah));
23444 Roo.log('onResize:' + [w,h,ew,eh].join(',') );
23445 this.editorcore.onResize(ew,eh);
23450 * Toggles the editor between standard and source edit mode.
23451 * @param {Boolean} sourceEdit (optional) True for source edit, false for standard
23453 toggleSourceEdit : function(sourceEditMode)
23455 this.editorcore.toggleSourceEdit(sourceEditMode);
23457 if(this.editorcore.sourceEditMode){
23458 Roo.log('editor - showing textarea');
23461 // Roo.log(this.syncValue());
23463 this.inputEl().removeClass(['hide', 'x-hidden']);
23464 this.inputEl().dom.removeAttribute('tabIndex');
23465 this.inputEl().focus();
23467 Roo.log('editor - hiding textarea');
23469 // Roo.log(this.pushValue());
23472 this.inputEl().addClass(['hide', 'x-hidden']);
23473 this.inputEl().dom.setAttribute('tabIndex', -1);
23474 //this.deferFocus();
23477 if(this.resizable){
23478 this.setSize(this.wrap.getSize());
23481 this.fireEvent('editmodechange', this, this.editorcore.sourceEditMode);
23484 // private (for BoxComponent)
23485 adjustSize : Roo.BoxComponent.prototype.adjustSize,
23487 // private (for BoxComponent)
23488 getResizeEl : function(){
23492 // private (for BoxComponent)
23493 getPositionEl : function(){
23498 initEvents : function(){
23499 this.originalValue = this.getValue();
23503 // * Overridden and disabled. The editor element does not support standard valid/invalid marking. @hide
23506 // markInvalid : Roo.emptyFn,
23508 // * Overridden and disabled. The editor element does not support standard valid/invalid marking. @hide
23511 // clearInvalid : Roo.emptyFn,
23513 setValue : function(v){
23514 Roo.bootstrap.HtmlEditor.superclass.setValue.call(this, v);
23515 this.editorcore.pushValue();
23520 deferFocus : function(){
23521 this.focus.defer(10, this);
23525 focus : function(){
23526 this.editorcore.focus();
23532 onDestroy : function(){
23538 for (var i =0; i < this.toolbars.length;i++) {
23539 // fixme - ask toolbars for heights?
23540 this.toolbars[i].onDestroy();
23543 this.wrap.dom.innerHTML = '';
23544 this.wrap.remove();
23549 onFirstFocus : function(){
23550 //Roo.log("onFirstFocus");
23551 this.editorcore.onFirstFocus();
23552 for (var i =0; i < this.toolbars.length;i++) {
23553 this.toolbars[i].onFirstFocus();
23559 syncValue : function()
23561 this.editorcore.syncValue();
23564 pushValue : function()
23566 this.editorcore.pushValue();
23570 // hide stuff that is not compatible
23584 * @event specialkey
23588 * @cfg {String} fieldClass @hide
23591 * @cfg {String} focusClass @hide
23594 * @cfg {String} autoCreate @hide
23597 * @cfg {String} inputType @hide
23600 * @cfg {String} invalidClass @hide
23603 * @cfg {String} invalidText @hide
23606 * @cfg {String} msgFx @hide
23609 * @cfg {String} validateOnBlur @hide
23618 Roo.namespace('Roo.bootstrap.htmleditor');
23620 * @class Roo.bootstrap.HtmlEditorToolbar1
23625 new Roo.bootstrap.HtmlEditor({
23628 new Roo.bootstrap.HtmlEditorToolbar1({
23629 disable : { fonts: 1 , format: 1, ..., ... , ...],
23635 * @cfg {Object} disable List of elements to disable..
23636 * @cfg {Array} btns List of additional buttons.
23640 * .x-html-editor-tb .x-edit-none .x-btn-text { background: none; }
23643 Roo.bootstrap.htmleditor.ToolbarStandard = function(config)
23646 Roo.apply(this, config);
23648 // default disabled, based on 'good practice'..
23649 this.disable = this.disable || {};
23650 Roo.applyIf(this.disable, {
23653 specialElements : true
23655 Roo.bootstrap.htmleditor.ToolbarStandard.superclass.constructor.call(this, config);
23657 this.editor = config.editor;
23658 this.editorcore = config.editor.editorcore;
23660 this.buttons = new Roo.util.MixedCollection(false, function(o) { return o.cmd; });
23662 //Roo.form.HtmlEditorToolbar1.superclass.constructor.call(this, editor.wrap.dom.firstChild, [], config);
23663 // dont call parent... till later.
23665 Roo.extend(Roo.bootstrap.htmleditor.ToolbarStandard, Roo.bootstrap.NavSimplebar, {
23670 editorcore : false,
23675 "h1","h2","h3","h4","h5","h6",
23677 "abbr", "acronym", "address", "cite", "samp", "var",
23681 onRender : function(ct, position)
23683 // Roo.log("Call onRender: " + this.xtype);
23685 Roo.bootstrap.htmleditor.ToolbarStandard.superclass.onRender.call(this, ct, position);
23687 this.el.dom.style.marginBottom = '0';
23689 var editorcore = this.editorcore;
23690 var editor= this.editor;
23693 var btn = function(id,cmd , toggle, handler, html){
23695 var event = toggle ? 'toggle' : 'click';
23700 xns: Roo.bootstrap,
23703 enableToggle:toggle !== false,
23705 pressed : toggle ? false : null,
23708 a.listeners[toggle ? 'toggle' : 'click'] = function() {
23709 handler ? handler.call(_this,this) :_this.onBtnClick.call(_this, cmd || id);
23715 // var cb_box = function...
23720 xns: Roo.bootstrap,
23721 glyphicon : 'font',
23725 xns: Roo.bootstrap,
23729 Roo.each(this.formats, function(f) {
23730 style.menu.items.push({
23732 xns: Roo.bootstrap,
23733 html : '<'+ f+' style="margin:2px">'+f +'</'+ f+'>',
23738 editorcore.insertTag(this.tagname);
23745 children.push(style);
23747 btn('bold',false,true);
23748 btn('italic',false,true);
23749 btn('align-left', 'justifyleft',true);
23750 btn('align-center', 'justifycenter',true);
23751 btn('align-right' , 'justifyright',true);
23752 btn('link', false, false, function(btn) {
23753 //Roo.log("create link?");
23754 var url = prompt(this.createLinkText, this.defaultLinkValue);
23755 if(url && url != 'http:/'+'/'){
23756 this.editorcore.relayCmd('createlink', url);
23759 btn('list','insertunorderedlist',true);
23760 btn('pencil', false,true, function(btn){
23762 this.toggleSourceEdit(btn.pressed);
23765 if (this.editor.btns.length > 0) {
23766 for (var i = 0; i<this.editor.btns.length; i++) {
23767 children.push(this.editor.btns[i]);
23775 xns: Roo.bootstrap,
23780 xns: Roo.bootstrap,
23785 cog.menu.items.push({
23787 xns: Roo.bootstrap,
23788 html : Clean styles,
23793 editorcore.insertTag(this.tagname);
23802 this.xtype = 'NavSimplebar';
23804 for(var i=0;i< children.length;i++) {
23806 this.buttons.add(this.addxtypeChild(children[i]));
23810 editor.on('editorevent', this.updateToolbar, this);
23812 onBtnClick : function(id)
23814 this.editorcore.relayCmd(id);
23815 this.editorcore.focus();
23819 * Protected method that will not generally be called directly. It triggers
23820 * a toolbar update by reading the markup state of the current selection in the editor.
23822 updateToolbar: function(){
23824 if(!this.editorcore.activated){
23825 this.editor.onFirstFocus(); // is this neeed?
23829 var btns = this.buttons;
23830 var doc = this.editorcore.doc;
23831 btns.get('bold').setActive(doc.queryCommandState('bold'));
23832 btns.get('italic').setActive(doc.queryCommandState('italic'));
23833 //btns.get('underline').setActive(doc.queryCommandState('underline'));
23835 btns.get('align-left').setActive(doc.queryCommandState('justifyleft'));
23836 btns.get('align-center').setActive(doc.queryCommandState('justifycenter'));
23837 btns.get('align-right').setActive(doc.queryCommandState('justifyright'));
23839 //btns[frameId + '-insertorderedlist').setActive(doc.queryCommandState('insertorderedlist'));
23840 btns.get('list').setActive(doc.queryCommandState('insertunorderedlist'));
23843 var ans = this.editorcore.getAllAncestors();
23844 if (this.formatCombo) {
23847 var store = this.formatCombo.store;
23848 this.formatCombo.setValue("");
23849 for (var i =0; i < ans.length;i++) {
23850 if (ans[i] && store.query('tag',ans[i].tagName.toLowerCase(), false).length) {
23852 this.formatCombo.setValue(ans[i].tagName.toLowerCase());
23860 // hides menus... - so this cant be on a menu...
23861 Roo.bootstrap.MenuMgr.hideAll();
23863 Roo.bootstrap.MenuMgr.hideAll();
23864 //this.editorsyncValue();
23866 onFirstFocus: function() {
23867 this.buttons.each(function(item){
23871 toggleSourceEdit : function(sourceEditMode){
23874 if(sourceEditMode){
23875 Roo.log("disabling buttons");
23876 this.buttons.each( function(item){
23877 if(item.cmd != 'pencil'){
23883 Roo.log("enabling buttons");
23884 if(this.editorcore.initialized){
23885 this.buttons.each( function(item){
23891 Roo.log("calling toggole on editor");
23892 // tell the editor that it's been pressed..
23893 this.editor.toggleSourceEdit(sourceEditMode);
23903 * @class Roo.bootstrap.Table.AbstractSelectionModel
23904 * @extends Roo.util.Observable
23905 * Abstract base class for grid SelectionModels. It provides the interface that should be
23906 * implemented by descendant classes. This class should not be directly instantiated.
23909 Roo.bootstrap.Table.AbstractSelectionModel = function(){
23910 this.locked = false;
23911 Roo.bootstrap.Table.AbstractSelectionModel.superclass.constructor.call(this);
23915 Roo.extend(Roo.bootstrap.Table.AbstractSelectionModel, Roo.util.Observable, {
23916 /** @ignore Called by the grid automatically. Do not call directly. */
23917 init : function(grid){
23923 * Locks the selections.
23926 this.locked = true;
23930 * Unlocks the selections.
23932 unlock : function(){
23933 this.locked = false;
23937 * Returns true if the selections are locked.
23938 * @return {Boolean}
23940 isLocked : function(){
23941 return this.locked;
23945 * @extends Roo.bootstrap.Table.AbstractSelectionModel
23946 * @class Roo.bootstrap.Table.RowSelectionModel
23947 * The default SelectionModel used by {@link Roo.bootstrap.Table}.
23948 * It supports multiple selections and keyboard selection/navigation.
23950 * @param {Object} config
23953 Roo.bootstrap.Table.RowSelectionModel = function(config){
23954 Roo.apply(this, config);
23955 this.selections = new Roo.util.MixedCollection(false, function(o){
23960 this.lastActive = false;
23964 * @event selectionchange
23965 * Fires when the selection changes
23966 * @param {SelectionModel} this
23968 "selectionchange" : true,
23970 * @event afterselectionchange
23971 * Fires after the selection changes (eg. by key press or clicking)
23972 * @param {SelectionModel} this
23974 "afterselectionchange" : true,
23976 * @event beforerowselect
23977 * Fires when a row is selected being selected, return false to cancel.
23978 * @param {SelectionModel} this
23979 * @param {Number} rowIndex The selected index
23980 * @param {Boolean} keepExisting False if other selections will be cleared
23982 "beforerowselect" : true,
23985 * Fires when a row is selected.
23986 * @param {SelectionModel} this
23987 * @param {Number} rowIndex The selected index
23988 * @param {Roo.data.Record} r The record
23990 "rowselect" : true,
23992 * @event rowdeselect
23993 * Fires when a row is deselected.
23994 * @param {SelectionModel} this
23995 * @param {Number} rowIndex The selected index
23997 "rowdeselect" : true
23999 Roo.bootstrap.Table.RowSelectionModel.superclass.constructor.call(this);
24000 this.locked = false;
24003 Roo.extend(Roo.bootstrap.Table.RowSelectionModel, Roo.bootstrap.Table.AbstractSelectionModel, {
24005 * @cfg {Boolean} singleSelect
24006 * True to allow selection of only one row at a time (defaults to false)
24008 singleSelect : false,
24011 initEvents : function()
24014 //if(!this.grid.enableDragDrop && !this.grid.enableDrag){
24015 // this.growclickrid.on("mousedown", this.handleMouseDown, this);
24016 //}else{ // allow click to work like normal
24017 // this.grid.on("rowclick", this.handleDragableRowClick, this);
24019 //this.grid.on("rowdblclick", this.handleMouseDBClick, this);
24020 this.grid.on("rowclick", this.handleMouseDown, this);
24022 this.rowNav = new Roo.KeyNav(this.grid.getGridEl(), {
24023 "up" : function(e){
24025 this.selectPrevious(e.shiftKey);
24026 }else if(this.last !== false && this.lastActive !== false){
24027 var last = this.last;
24028 this.selectRange(this.last, this.lastActive-1);
24029 this.grid.getView().focusRow(this.lastActive);
24030 if(last !== false){
24034 this.selectFirstRow();
24036 this.fireEvent("afterselectionchange", this);
24038 "down" : function(e){
24040 this.selectNext(e.shiftKey);
24041 }else if(this.last !== false && this.lastActive !== false){
24042 var last = this.last;
24043 this.selectRange(this.last, this.lastActive+1);
24044 this.grid.getView().focusRow(this.lastActive);
24045 if(last !== false){
24049 this.selectFirstRow();
24051 this.fireEvent("afterselectionchange", this);
24055 this.grid.store.on('load', function(){
24056 this.selections.clear();
24059 var view = this.grid.view;
24060 view.on("refresh", this.onRefresh, this);
24061 view.on("rowupdated", this.onRowUpdated, this);
24062 view.on("rowremoved", this.onRemove, this);
24067 onRefresh : function()
24069 var ds = this.grid.store, i, v = this.grid.view;
24070 var s = this.selections;
24071 s.each(function(r){
24072 if((i = ds.indexOfId(r.id)) != -1){
24081 onRemove : function(v, index, r){
24082 this.selections.remove(r);
24086 onRowUpdated : function(v, index, r){
24087 if(this.isSelected(r)){
24088 v.onRowSelect(index);
24094 * @param {Array} records The records to select
24095 * @param {Boolean} keepExisting (optional) True to keep existing selections
24097 selectRecords : function(records, keepExisting)
24100 this.clearSelections();
24102 var ds = this.grid.store;
24103 for(var i = 0, len = records.length; i < len; i++){
24104 this.selectRow(ds.indexOf(records[i]), true);
24109 * Gets the number of selected rows.
24112 getCount : function(){
24113 return this.selections.length;
24117 * Selects the first row in the grid.
24119 selectFirstRow : function(){
24124 * Select the last row.
24125 * @param {Boolean} keepExisting (optional) True to keep existing selections
24127 selectLastRow : function(keepExisting){
24128 //this.selectRow(this.grid.dataSource.getCount() - 1, keepExisting);
24129 this.selectRow(this.grid.store.getCount() - 1, keepExisting);
24133 * Selects the row immediately following the last selected row.
24134 * @param {Boolean} keepExisting (optional) True to keep existing selections
24136 selectNext : function(keepExisting)
24138 if(this.last !== false && (this.last+1) < this.grid.store.getCount()){
24139 this.selectRow(this.last+1, keepExisting);
24140 this.grid.getView().focusRow(this.last);
24145 * Selects the row that precedes the last selected row.
24146 * @param {Boolean} keepExisting (optional) True to keep existing selections
24148 selectPrevious : function(keepExisting){
24150 this.selectRow(this.last-1, keepExisting);
24151 this.grid.getView().focusRow(this.last);
24156 * Returns the selected records
24157 * @return {Array} Array of selected records
24159 getSelections : function(){
24160 return [].concat(this.selections.items);
24164 * Returns the first selected record.
24167 getSelected : function(){
24168 return this.selections.itemAt(0);
24173 * Clears all selections.
24175 clearSelections : function(fast)
24181 var ds = this.grid.store;
24182 var s = this.selections;
24183 s.each(function(r){
24184 this.deselectRow(ds.indexOfId(r.id));
24188 this.selections.clear();
24195 * Selects all rows.
24197 selectAll : function(){
24201 this.selections.clear();
24202 for(var i = 0, len = this.grid.store.getCount(); i < len; i++){
24203 this.selectRow(i, true);
24208 * Returns True if there is a selection.
24209 * @return {Boolean}
24211 hasSelection : function(){
24212 return this.selections.length > 0;
24216 * Returns True if the specified row is selected.
24217 * @param {Number/Record} record The record or index of the record to check
24218 * @return {Boolean}
24220 isSelected : function(index){
24221 var r = typeof index == "number" ? this.grid.store.getAt(index) : index;
24222 return (r && this.selections.key(r.id) ? true : false);
24226 * Returns True if the specified record id is selected.
24227 * @param {String} id The id of record to check
24228 * @return {Boolean}
24230 isIdSelected : function(id){
24231 return (this.selections.key(id) ? true : false);
24236 handleMouseDBClick : function(e, t){
24240 handleMouseDown : function(e, t)
24242 var rowIndex = this.grid.headerShow ? t.dom.rowIndex - 1 : t.dom.rowIndex ; // first row is header???
24243 if(this.isLocked() || rowIndex < 0 ){
24246 if(e.shiftKey && this.last !== false){
24247 var last = this.last;
24248 this.selectRange(last, rowIndex, e.ctrlKey);
24249 this.last = last; // reset the last
24253 var isSelected = this.isSelected(rowIndex);
24254 //Roo.log("select row:" + rowIndex);
24256 this.deselectRow(rowIndex);
24258 this.selectRow(rowIndex, true);
24262 if(e.button !== 0 && isSelected){
24263 alert('rowIndex 2: ' + rowIndex);
24264 view.focusRow(rowIndex);
24265 }else if(e.ctrlKey && isSelected){
24266 this.deselectRow(rowIndex);
24267 }else if(!isSelected){
24268 this.selectRow(rowIndex, e.button === 0 && (e.ctrlKey || e.shiftKey));
24269 view.focusRow(rowIndex);
24273 this.fireEvent("afterselectionchange", this);
24276 handleDragableRowClick : function(grid, rowIndex, e)
24278 if(e.button === 0 && !e.shiftKey && !e.ctrlKey) {
24279 this.selectRow(rowIndex, false);
24280 grid.view.focusRow(rowIndex);
24281 this.fireEvent("afterselectionchange", this);
24286 * Selects multiple rows.
24287 * @param {Array} rows Array of the indexes of the row to select
24288 * @param {Boolean} keepExisting (optional) True to keep existing selections
24290 selectRows : function(rows, keepExisting){
24292 this.clearSelections();
24294 for(var i = 0, len = rows.length; i < len; i++){
24295 this.selectRow(rows[i], true);
24300 * Selects a range of rows. All rows in between startRow and endRow are also selected.
24301 * @param {Number} startRow The index of the first row in the range
24302 * @param {Number} endRow The index of the last row in the range
24303 * @param {Boolean} keepExisting (optional) True to retain existing selections
24305 selectRange : function(startRow, endRow, keepExisting){
24310 this.clearSelections();
24312 if(startRow <= endRow){
24313 for(var i = startRow; i <= endRow; i++){
24314 this.selectRow(i, true);
24317 for(var i = startRow; i >= endRow; i--){
24318 this.selectRow(i, true);
24324 * Deselects a range of rows. All rows in between startRow and endRow are also deselected.
24325 * @param {Number} startRow The index of the first row in the range
24326 * @param {Number} endRow The index of the last row in the range
24328 deselectRange : function(startRow, endRow, preventViewNotify){
24332 for(var i = startRow; i <= endRow; i++){
24333 this.deselectRow(i, preventViewNotify);
24339 * @param {Number} row The index of the row to select
24340 * @param {Boolean} keepExisting (optional) True to keep existing selections
24342 selectRow : function(index, keepExisting, preventViewNotify)
24344 if(this.locked || (index < 0 || index > this.grid.store.getCount())) {
24347 if(this.fireEvent("beforerowselect", this, index, keepExisting) !== false){
24348 if(!keepExisting || this.singleSelect){
24349 this.clearSelections();
24352 var r = this.grid.store.getAt(index);
24353 //console.log('selectRow - record id :' + r.id);
24355 this.selections.add(r);
24356 this.last = this.lastActive = index;
24357 if(!preventViewNotify){
24358 var proxy = new Roo.Element(
24359 this.grid.getRowDom(index)
24361 proxy.addClass('bg-info info');
24363 this.fireEvent("rowselect", this, index, r);
24364 this.fireEvent("selectionchange", this);
24370 * @param {Number} row The index of the row to deselect
24372 deselectRow : function(index, preventViewNotify)
24377 if(this.last == index){
24380 if(this.lastActive == index){
24381 this.lastActive = false;
24384 var r = this.grid.store.getAt(index);
24389 this.selections.remove(r);
24390 //.console.log('deselectRow - record id :' + r.id);
24391 if(!preventViewNotify){
24393 var proxy = new Roo.Element(
24394 this.grid.getRowDom(index)
24396 proxy.removeClass('bg-info info');
24398 this.fireEvent("rowdeselect", this, index);
24399 this.fireEvent("selectionchange", this);
24403 restoreLast : function(){
24405 this.last = this._last;
24410 acceptsNav : function(row, col, cm){
24411 return !cm.isHidden(col) && cm.isCellEditable(col, row);
24415 onEditorKey : function(field, e){
24416 var k = e.getKey(), newCell, g = this.grid, ed = g.activeEditor;
24421 newCell = g.walkCells(ed.row, ed.col-1, -1, this.acceptsNav, this);
24423 newCell = g.walkCells(ed.row, ed.col+1, 1, this.acceptsNav, this);
24425 }else if(k == e.ENTER && !e.ctrlKey){
24429 newCell = g.walkCells(ed.row-1, ed.col, -1, this.acceptsNav, this);
24431 newCell = g.walkCells(ed.row+1, ed.col, 1, this.acceptsNav, this);
24433 }else if(k == e.ESC){
24437 g.startEditing(newCell[0], newCell[1]);
24443 * Ext JS Library 1.1.1
24444 * Copyright(c) 2006-2007, Ext JS, LLC.
24446 * Originally Released Under LGPL - original licence link has changed is not relivant.
24449 * <script type="text/javascript">
24453 * @class Roo.bootstrap.PagingToolbar
24454 * @extends Roo.bootstrap.NavSimplebar
24455 * A specialized toolbar that is bound to a {@link Roo.data.Store} and provides automatic paging controls.
24457 * Create a new PagingToolbar
24458 * @param {Object} config The config object
24459 * @param {Roo.data.Store} store
24461 Roo.bootstrap.PagingToolbar = function(config)
24463 // old args format still supported... - xtype is prefered..
24464 // created from xtype...
24466 this.ds = config.dataSource;
24468 if (config.store && !this.ds) {
24469 this.store= Roo.factory(config.store, Roo.data);
24470 this.ds = this.store;
24471 this.ds.xmodule = this.xmodule || false;
24474 this.toolbarItems = [];
24475 if (config.items) {
24476 this.toolbarItems = config.items;
24479 Roo.bootstrap.PagingToolbar.superclass.constructor.call(this, config);
24484 this.bind(this.ds);
24487 this.navgroup = new Roo.bootstrap.NavGroup({ cls: 'pagination' });
24491 Roo.extend(Roo.bootstrap.PagingToolbar, Roo.bootstrap.NavSimplebar, {
24493 * @cfg {Roo.data.Store} dataSource
24494 * The underlying data store providing the paged data
24497 * @cfg {String/HTMLElement/Element} container
24498 * container The id or element that will contain the toolbar
24501 * @cfg {Boolean} displayInfo
24502 * True to display the displayMsg (defaults to false)
24505 * @cfg {Number} pageSize
24506 * The number of records to display per page (defaults to 20)
24510 * @cfg {String} displayMsg
24511 * The paging status message to display (defaults to "Displaying {start} - {end} of {total}")
24513 displayMsg : 'Displaying {0} - {1} of {2}',
24515 * @cfg {String} emptyMsg
24516 * The message to display when no records are found (defaults to "No data to display")
24518 emptyMsg : 'No data to display',
24520 * Customizable piece of the default paging text (defaults to "Page")
24523 beforePageText : "Page",
24525 * Customizable piece of the default paging text (defaults to "of %0")
24528 afterPageText : "of {0}",
24530 * Customizable piece of the default paging text (defaults to "First Page")
24533 firstText : "First Page",
24535 * Customizable piece of the default paging text (defaults to "Previous Page")
24538 prevText : "Previous Page",
24540 * Customizable piece of the default paging text (defaults to "Next Page")
24543 nextText : "Next Page",
24545 * Customizable piece of the default paging text (defaults to "Last Page")
24548 lastText : "Last Page",
24550 * Customizable piece of the default paging text (defaults to "Refresh")
24553 refreshText : "Refresh",
24557 onRender : function(ct, position)
24559 Roo.bootstrap.PagingToolbar.superclass.onRender.call(this, ct, position);
24560 this.navgroup.parentId = this.id;
24561 this.navgroup.onRender(this.el, null);
24562 // add the buttons to the navgroup
24564 if(this.displayInfo){
24565 this.el.select('ul.navbar-nav',true).first().createChild({cls:'x-paging-info'});
24566 this.displayEl = this.el.select('.x-paging-info', true).first();
24567 // var navel = this.navgroup.addItem( { tagtype : 'span', html : '', cls : 'x-paging-info', preventDefault : true } );
24568 // this.displayEl = navel.el.select('span',true).first();
24574 Roo.each(_this.buttons, function(e){ // this might need to use render????
24575 Roo.factory(e).render(_this.el);
24579 Roo.each(_this.toolbarItems, function(e) {
24580 _this.navgroup.addItem(e);
24584 this.first = this.navgroup.addItem({
24585 tooltip: this.firstText,
24587 icon : 'fa fa-backward',
24589 preventDefault: true,
24590 listeners : { click : this.onClick.createDelegate(this, ["first"]) }
24593 this.prev = this.navgroup.addItem({
24594 tooltip: this.prevText,
24596 icon : 'fa fa-step-backward',
24598 preventDefault: true,
24599 listeners : { click : this.onClick.createDelegate(this, ["prev"]) }
24601 //this.addSeparator();
24604 var field = this.navgroup.addItem( {
24606 cls : 'x-paging-position',
24608 html : this.beforePageText +
24609 '<input type="text" size="3" value="1" class="x-grid-page-number">' +
24610 '<span class="x-paging-after">' + String.format(this.afterPageText, 1) + '</span>'
24613 this.field = field.el.select('input', true).first();
24614 this.field.on("keydown", this.onPagingKeydown, this);
24615 this.field.on("focus", function(){this.dom.select();});
24618 this.afterTextEl = field.el.select('.x-paging-after',true).first();
24619 //this.field.setHeight(18);
24620 //this.addSeparator();
24621 this.next = this.navgroup.addItem({
24622 tooltip: this.nextText,
24624 html : ' <i class="fa fa-step-forward">',
24626 preventDefault: true,
24627 listeners : { click : this.onClick.createDelegate(this, ["next"]) }
24629 this.last = this.navgroup.addItem({
24630 tooltip: this.lastText,
24631 icon : 'fa fa-forward',
24634 preventDefault: true,
24635 listeners : { click : this.onClick.createDelegate(this, ["last"]) }
24637 //this.addSeparator();
24638 this.loading = this.navgroup.addItem({
24639 tooltip: this.refreshText,
24640 icon: 'fa fa-refresh',
24641 preventDefault: true,
24642 listeners : { click : this.onClick.createDelegate(this, ["refresh"]) }
24648 updateInfo : function(){
24649 if(this.displayEl){
24650 var count = (typeof(this.getCount) == 'undefined') ? this.ds.getCount() : this.getCount();
24651 var msg = count == 0 ?
24655 this.cursor+1, this.cursor+count, this.ds.getTotalCount()
24657 this.displayEl.update(msg);
24662 onLoad : function(ds, r, o)
24664 this.cursor = o.params.start ? o.params.start : 0;
24666 var d = this.getPageData(),
24671 this.afterTextEl.dom.innerHTML = String.format(this.afterPageText, d.pages);
24672 this.field.dom.value = ap;
24673 this.first.setDisabled(ap == 1);
24674 this.prev.setDisabled(ap == 1);
24675 this.next.setDisabled(ap == ps);
24676 this.last.setDisabled(ap == ps);
24677 this.loading.enable();
24682 getPageData : function(){
24683 var total = this.ds.getTotalCount();
24686 activePage : Math.ceil((this.cursor+this.pageSize)/this.pageSize),
24687 pages : total < this.pageSize ? 1 : Math.ceil(total/this.pageSize)
24692 onLoadError : function(){
24693 this.loading.enable();
24697 onPagingKeydown : function(e){
24698 var k = e.getKey();
24699 var d = this.getPageData();
24701 var v = this.field.dom.value, pageNum;
24702 if(!v || isNaN(pageNum = parseInt(v, 10))){
24703 this.field.dom.value = d.activePage;
24706 pageNum = Math.min(Math.max(1, pageNum), d.pages) - 1;
24707 this.ds.load({params:{start: pageNum * this.pageSize, limit: this.pageSize}});
24710 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))
24712 var pageNum = (k == e.HOME || (k == e.DOWN && e.ctrlKey) || (k == e.LEFT && e.ctrlKey) || (k == e.PAGEDOWN && e.ctrlKey)) ? 1 : d.pages;
24713 this.field.dom.value = pageNum;
24714 this.ds.load({params:{start: (pageNum - 1) * this.pageSize, limit: this.pageSize}});
24717 else if(k == e.UP || k == e.RIGHT || k == e.PAGEUP || k == e.DOWN || k == e.LEFT || k == e.PAGEDOWN)
24719 var v = this.field.dom.value, pageNum;
24720 var increment = (e.shiftKey) ? 10 : 1;
24721 if(k == e.DOWN || k == e.LEFT || k == e.PAGEDOWN) {
24724 if(!v || isNaN(pageNum = parseInt(v, 10))) {
24725 this.field.dom.value = d.activePage;
24728 else if(parseInt(v, 10) + increment >= 1 & parseInt(v, 10) + increment <= d.pages)
24730 this.field.dom.value = parseInt(v, 10) + increment;
24731 pageNum = Math.min(Math.max(1, pageNum + increment), d.pages) - 1;
24732 this.ds.load({params:{start: pageNum * this.pageSize, limit: this.pageSize}});
24739 beforeLoad : function(){
24741 this.loading.disable();
24746 onClick : function(which){
24755 ds.load({params:{start: 0, limit: this.pageSize}});
24758 ds.load({params:{start: Math.max(0, this.cursor-this.pageSize), limit: this.pageSize}});
24761 ds.load({params:{start: this.cursor+this.pageSize, limit: this.pageSize}});
24764 var total = ds.getTotalCount();
24765 var extra = total % this.pageSize;
24766 var lastStart = extra ? (total - extra) : total-this.pageSize;
24767 ds.load({params:{start: lastStart, limit: this.pageSize}});
24770 ds.load({params:{start: this.cursor, limit: this.pageSize}});
24776 * Unbinds the paging toolbar from the specified {@link Roo.data.Store}
24777 * @param {Roo.data.Store} store The data store to unbind
24779 unbind : function(ds){
24780 ds.un("beforeload", this.beforeLoad, this);
24781 ds.un("load", this.onLoad, this);
24782 ds.un("loadexception", this.onLoadError, this);
24783 ds.un("remove", this.updateInfo, this);
24784 ds.un("add", this.updateInfo, this);
24785 this.ds = undefined;
24789 * Binds the paging toolbar to the specified {@link Roo.data.Store}
24790 * @param {Roo.data.Store} store The data store to bind
24792 bind : function(ds){
24793 ds.on("beforeload", this.beforeLoad, this);
24794 ds.on("load", this.onLoad, this);
24795 ds.on("loadexception", this.onLoadError, this);
24796 ds.on("remove", this.updateInfo, this);
24797 ds.on("add", this.updateInfo, this);
24808 * @class Roo.bootstrap.MessageBar
24809 * @extends Roo.bootstrap.Component
24810 * Bootstrap MessageBar class
24811 * @cfg {String} html contents of the MessageBar
24812 * @cfg {String} weight (info | success | warning | danger) default info
24813 * @cfg {String} beforeClass insert the bar before the given class
24814 * @cfg {Boolean} closable (true | false) default false
24815 * @cfg {Boolean} fixed (true | false) default false, fix the bar at the top
24818 * Create a new Element
24819 * @param {Object} config The config object
24822 Roo.bootstrap.MessageBar = function(config){
24823 Roo.bootstrap.MessageBar.superclass.constructor.call(this, config);
24826 Roo.extend(Roo.bootstrap.MessageBar, Roo.bootstrap.Component, {
24832 beforeClass: 'bootstrap-sticky-wrap',
24834 getAutoCreate : function(){
24838 cls: 'alert alert-dismissable alert-' + this.weight,
24843 html: this.html || ''
24849 cfg.cls += ' alert-messages-fixed';
24863 onRender : function(ct, position)
24865 Roo.bootstrap.Component.superclass.onRender.call(this, ct, position);
24868 var cfg = Roo.apply({}, this.getAutoCreate());
24872 cfg.cls += ' ' + this.cls;
24875 cfg.style = this.style;
24877 this.el = Roo.get(document.body).createChild(cfg, Roo.select('.'+this.beforeClass, true).first());
24879 this.el.setVisibilityMode(Roo.Element.DISPLAY);
24882 this.el.select('>button.close').on('click', this.hide, this);
24888 if (!this.rendered) {
24894 this.fireEvent('show', this);
24900 if (!this.rendered) {
24906 this.fireEvent('hide', this);
24909 update : function()
24911 // var e = this.el.dom.firstChild;
24913 // if(this.closable){
24914 // e = e.nextSibling;
24917 // e.data = this.html || '';
24919 this.el.select('>.message', true).first().dom.innerHTML = this.html || '';
24935 * @class Roo.bootstrap.Graph
24936 * @extends Roo.bootstrap.Component
24937 * Bootstrap Graph class
24941 @cfg {String} graphtype bar | vbar | pie
24942 @cfg {number} g_x coodinator | centre x (pie)
24943 @cfg {number} g_y coodinator | centre y (pie)
24944 @cfg {number} g_r radius (pie)
24945 @cfg {number} g_height height of the chart (respected by all elements in the set)
24946 @cfg {number} g_width width of the chart (respected by all elements in the set)
24947 @cfg {Object} title The title of the chart
24950 -opts (object) options for the chart
24952 o type (string) type of endings of the bar. Default: 'square'. Other options are: 'round', 'sharp', 'soft'.
24953 o gutter (number)(string) default '20%' (WHAT DOES IT DO?)
24955 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.
24956 o stacked (boolean) whether or not to tread values as in a stacked bar chart
24958 o stretch (boolean)
24960 -opts (object) options for the pie
24963 o startAngle (number)
24964 o endAngle (number)
24968 * Create a new Input
24969 * @param {Object} config The config object
24972 Roo.bootstrap.Graph = function(config){
24973 Roo.bootstrap.Graph.superclass.constructor.call(this, config);
24979 * The img click event for the img.
24980 * @param {Roo.EventObject} e
24986 Roo.extend(Roo.bootstrap.Graph, Roo.bootstrap.Component, {
24997 //g_colors: this.colors,
25004 getAutoCreate : function(){
25015 onRender : function(ct,position){
25018 Roo.bootstrap.Graph.superclass.onRender.call(this,ct,position);
25020 if (typeof(Raphael) == 'undefined') {
25021 Roo.bootstrap.MessageBox.alert("Error","Raphael is not availabe");
25025 this.raphael = Raphael(this.el.dom);
25027 // data1 = [[55, 20, 13, 32, 5, 1, 2, 10], [10, 2, 1, 5, 32, 13, 20, 55], [12, 20, 30]],
25028 // data2 = [[55, 20, 13, 32, 5, 1, 2, 10], [10, 2, 1, 5, 32, 13, 20, 55], [12, 20, 30]],
25029 // data3 = [[55, 20, 13, 32, 5, 1, 2, 10], [10, 2, 1, 5, 32, 13, 20, 55], [12, 20, 30]],
25030 // txtattr = { font: "12px 'Fontin Sans', Fontin-Sans, sans-serif" };
25032 r.text(160, 10, "Single Series Chart").attr(txtattr);
25033 r.text(480, 10, "Multiline Series Chart").attr(txtattr);
25034 r.text(160, 250, "Multiple Series Stacked Chart").attr(txtattr);
25035 r.text(480, 250, 'Multiline Series Stacked Vertical Chart. Type "round"').attr(txtattr);
25037 r.barchart(10, 10, 300, 220, [[55, 20, 13, 32, 5, 1, 2, 10]], 0, {type: "sharp"});
25038 r.barchart(330, 10, 300, 220, data1);
25039 r.barchart(10, 250, 300, 220, data2, {stacked: true});
25040 r.barchart(330, 250, 300, 220, data3, {stacked: true, type: "round"});
25043 // var xdata = [55, 20, 13, 32, 5, 1, 2, 10,5 , 10];
25044 // r.barchart(30, 30, 560, 250, xdata, {
25045 // labels : [55, 20, 13, 32, 5, 1, 2, 10,5 , 10],
25046 // axis : "0 0 1 1",
25047 // axisxlabels : xdata
25048 // //yvalues : cols,
25051 // var xdata = [55, 20, 13, 32, 5, 1, 2, 10,5 , 10];
25053 // this.load(null,xdata,{
25054 // axis : "0 0 1 1",
25055 // axisxlabels : xdata
25060 load : function(graphtype,xdata,opts)
25062 this.raphael.clear();
25064 graphtype = this.graphtype;
25069 var r = this.raphael,
25070 fin = function () {
25071 this.flag = r.popup(this.bar.x, this.bar.y, this.bar.value || "0").insertBefore(this);
25073 fout = function () {
25074 this.flag.animate({opacity: 0}, 300, function () {this.remove();});
25076 pfin = function() {
25077 this.sector.stop();
25078 this.sector.scale(1.1, 1.1, this.cx, this.cy);
25081 this.label[0].stop();
25082 this.label[0].attr({ r: 7.5 });
25083 this.label[1].attr({ "font-weight": 800 });
25086 pfout = function() {
25087 this.sector.animate({ transform: 's1 1 ' + this.cx + ' ' + this.cy }, 500, "bounce");
25090 this.label[0].animate({ r: 5 }, 500, "bounce");
25091 this.label[1].attr({ "font-weight": 400 });
25097 this.raphael.barchart(this.g_x,this.g_y,this.g_width,this.g_height,xdata,opts).hover(fin,fout);
25100 this.raphael.hbarchart(this.g_x,this.g_y,this.g_width,this.g_height,xdata,opts).hover(fin,fout);
25103 // opts = { legend: ["%% - Enterprise Users", "% - ddd","Chrome Users"], legendpos: "west",
25104 // href: ["http://raphaeljs.com", "http://g.raphaeljs.com"]};
25106 this.raphael.piechart(this.g_x,this.g_y,this.g_r,xdata,opts).hover(pfin, pfout);
25113 this.raphael.text(this.title.x, this.title.y, this.title.text).attr(this.title.attr);
25118 setTitle: function(o)
25123 initEvents: function() {
25126 this.el.on('click', this.onClick, this);
25130 onClick : function(e)
25132 Roo.log('img onclick');
25133 this.fireEvent('click', this, e);
25145 Roo.bootstrap.dash = Roo.bootstrap.dash || {};
25148 * @class Roo.bootstrap.dash.NumberBox
25149 * @extends Roo.bootstrap.Component
25150 * Bootstrap NumberBox class
25151 * @cfg {String} headline Box headline
25152 * @cfg {String} content Box content
25153 * @cfg {String} icon Box icon
25154 * @cfg {String} footer Footer text
25155 * @cfg {String} fhref Footer href
25158 * Create a new NumberBox
25159 * @param {Object} config The config object
25163 Roo.bootstrap.dash.NumberBox = function(config){
25164 Roo.bootstrap.dash.NumberBox.superclass.constructor.call(this, config);
25168 Roo.extend(Roo.bootstrap.dash.NumberBox, Roo.bootstrap.Component, {
25177 getAutoCreate : function(){
25181 cls : 'small-box ',
25189 cls : 'roo-headline',
25190 html : this.headline
25194 cls : 'roo-content',
25195 html : this.content
25209 cls : 'ion ' + this.icon
25218 cls : 'small-box-footer',
25219 href : this.fhref || '#',
25223 cfg.cn.push(footer);
25230 onRender : function(ct,position){
25231 Roo.bootstrap.dash.NumberBox.superclass.onRender.call(this,ct,position);
25238 setHeadline: function (value)
25240 this.el.select('.roo-headline',true).first().dom.innerHTML = value;
25243 setFooter: function (value, href)
25245 this.el.select('a.small-box-footer',true).first().dom.innerHTML = value;
25248 this.el.select('a.small-box-footer',true).first().attr('href', href);
25253 setContent: function (value)
25255 this.el.select('.roo-content',true).first().dom.innerHTML = value;
25258 initEvents: function()
25272 Roo.bootstrap.dash = Roo.bootstrap.dash || {};
25275 * @class Roo.bootstrap.dash.TabBox
25276 * @extends Roo.bootstrap.Component
25277 * Bootstrap TabBox class
25278 * @cfg {String} title Title of the TabBox
25279 * @cfg {String} icon Icon of the TabBox
25280 * @cfg {Boolean} showtabs (true|false) show the tabs default true
25281 * @cfg {Boolean} tabScrollable (true|false) tab scrollable when mobile view default false
25284 * Create a new TabBox
25285 * @param {Object} config The config object
25289 Roo.bootstrap.dash.TabBox = function(config){
25290 Roo.bootstrap.dash.TabBox.superclass.constructor.call(this, config);
25295 * When a pane is added
25296 * @param {Roo.bootstrap.dash.TabPane} pane
25300 * @event activatepane
25301 * When a pane is activated
25302 * @param {Roo.bootstrap.dash.TabPane} pane
25304 "activatepane" : true
25312 Roo.extend(Roo.bootstrap.dash.TabBox, Roo.bootstrap.Component, {
25317 tabScrollable : false,
25319 getChildContainer : function()
25321 return this.el.select('.tab-content', true).first();
25324 getAutoCreate : function(){
25328 cls: 'pull-left header',
25336 cls: 'fa ' + this.icon
25342 cls: 'nav nav-tabs pull-right',
25348 if(this.tabScrollable){
25355 cls: 'nav nav-tabs pull-right',
25366 cls: 'nav-tabs-custom',
25371 cls: 'tab-content no-padding',
25379 initEvents : function()
25381 //Roo.log('add add pane handler');
25382 this.on('addpane', this.onAddPane, this);
25385 * Updates the box title
25386 * @param {String} html to set the title to.
25388 setTitle : function(value)
25390 this.el.select('.nav-tabs .header', true).first().dom.innerHTML = value;
25392 onAddPane : function(pane)
25394 this.panes.push(pane);
25395 //Roo.log('addpane');
25397 // tabs are rendere left to right..
25398 if(!this.showtabs){
25402 var ctr = this.el.select('.nav-tabs', true).first();
25405 var existing = ctr.select('.nav-tab',true);
25406 var qty = existing.getCount();;
25409 var tab = ctr.createChild({
25411 cls : 'nav-tab' + (qty ? '' : ' active'),
25419 }, qty ? existing.first().dom : ctr.select('.header', true).first().dom );
25422 tab.on('click', this.onTabClick.createDelegate(this, [pane], true));
25424 pane.el.addClass('active');
25429 onTabClick : function(ev,un,ob,pane)
25431 //Roo.log('tab - prev default');
25432 ev.preventDefault();
25435 this.el.select('.nav-tabs li.nav-tab', true).removeClass('active');
25436 pane.tab.addClass('active');
25437 //Roo.log(pane.title);
25438 this.getChildContainer().select('.tab-pane',true).removeClass('active');
25439 // technically we should have a deactivate event.. but maybe add later.
25440 // and it should not de-activate the selected tab...
25441 this.fireEvent('activatepane', pane);
25442 pane.el.addClass('active');
25443 pane.fireEvent('activate');
25448 getActivePane : function()
25451 Roo.each(this.panes, function(p) {
25452 if(p.el.hasClass('active')){
25473 Roo.bootstrap.dash = Roo.bootstrap.dash || {};
25475 * @class Roo.bootstrap.TabPane
25476 * @extends Roo.bootstrap.Component
25477 * Bootstrap TabPane class
25478 * @cfg {Boolean} active (false | true) Default false
25479 * @cfg {String} title title of panel
25483 * Create a new TabPane
25484 * @param {Object} config The config object
25487 Roo.bootstrap.dash.TabPane = function(config){
25488 Roo.bootstrap.dash.TabPane.superclass.constructor.call(this, config);
25494 * When a pane is activated
25495 * @param {Roo.bootstrap.dash.TabPane} pane
25502 Roo.extend(Roo.bootstrap.dash.TabPane, Roo.bootstrap.Component, {
25507 // the tabBox that this is attached to.
25510 getAutoCreate : function()
25518 cfg.cls += ' active';
25523 initEvents : function()
25525 //Roo.log('trigger add pane handler');
25526 this.parent().fireEvent('addpane', this)
25530 * Updates the tab title
25531 * @param {String} html to set the title to.
25533 setTitle: function(str)
25539 this.tab.select('a', true).first().dom.innerHTML = str;
25556 Roo.bootstrap.menu = Roo.bootstrap.menu || {};
25559 * @class Roo.bootstrap.menu.Menu
25560 * @extends Roo.bootstrap.Component
25561 * Bootstrap Menu class - container for Menu
25562 * @cfg {String} html Text of the menu
25563 * @cfg {String} weight (default | primary | success | info | warning | danger | inverse)
25564 * @cfg {String} icon Font awesome icon
25565 * @cfg {String} pos Menu align to (top | bottom) default bottom
25569 * Create a new Menu
25570 * @param {Object} config The config object
25574 Roo.bootstrap.menu.Menu = function(config){
25575 Roo.bootstrap.menu.Menu.superclass.constructor.call(this, config);
25579 * @event beforeshow
25580 * Fires before this menu is displayed
25581 * @param {Roo.bootstrap.menu.Menu} this
25585 * @event beforehide
25586 * Fires before this menu is hidden
25587 * @param {Roo.bootstrap.menu.Menu} this
25592 * Fires after this menu is displayed
25593 * @param {Roo.bootstrap.menu.Menu} this
25598 * Fires after this menu is hidden
25599 * @param {Roo.bootstrap.menu.Menu} this
25604 * Fires when this menu is clicked (or when the enter key is pressed while it is active)
25605 * @param {Roo.bootstrap.menu.Menu} this
25606 * @param {Roo.EventObject} e
25613 Roo.extend(Roo.bootstrap.menu.Menu, Roo.bootstrap.Component, {
25617 weight : 'default',
25622 getChildContainer : function() {
25623 if(this.isSubMenu){
25627 return this.el.select('ul.dropdown-menu', true).first();
25630 getAutoCreate : function()
25635 cls : 'roo-menu-text',
25643 cls : 'fa ' + this.icon
25654 cls : 'dropdown-button btn btn-' + this.weight,
25659 cls : 'dropdown-toggle btn btn-' + this.weight,
25669 cls : 'dropdown-menu'
25675 if(this.pos == 'top'){
25676 cfg.cls += ' dropup';
25679 if(this.isSubMenu){
25682 cls : 'dropdown-menu'
25689 onRender : function(ct, position)
25691 this.isSubMenu = ct.hasClass('dropdown-submenu');
25693 Roo.bootstrap.menu.Menu.superclass.onRender.call(this, ct, position);
25696 initEvents : function()
25698 if(this.isSubMenu){
25702 this.hidden = true;
25704 this.triggerEl = this.el.select('button.dropdown-toggle', true).first();
25705 this.triggerEl.on('click', this.onTriggerPress, this);
25707 this.buttonEl = this.el.select('button.dropdown-button', true).first();
25708 this.buttonEl.on('click', this.onClick, this);
25714 if(this.isSubMenu){
25718 return this.el.select('ul.dropdown-menu', true).first();
25721 onClick : function(e)
25723 this.fireEvent("click", this, e);
25726 onTriggerPress : function(e)
25728 if (this.isVisible()) {
25735 isVisible : function(){
25736 return !this.hidden;
25741 this.fireEvent("beforeshow", this);
25743 this.hidden = false;
25744 this.el.addClass('open');
25746 Roo.get(document).on("mouseup", this.onMouseUp, this);
25748 this.fireEvent("show", this);
25755 this.fireEvent("beforehide", this);
25757 this.hidden = true;
25758 this.el.removeClass('open');
25760 Roo.get(document).un("mouseup", this.onMouseUp);
25762 this.fireEvent("hide", this);
25765 onMouseUp : function()
25779 Roo.bootstrap.menu = Roo.bootstrap.menu || {};
25782 * @class Roo.bootstrap.menu.Item
25783 * @extends Roo.bootstrap.Component
25784 * Bootstrap MenuItem class
25785 * @cfg {Boolean} submenu (true | false) default false
25786 * @cfg {String} html text of the item
25787 * @cfg {String} href the link
25788 * @cfg {Boolean} disable (true | false) default false
25789 * @cfg {Boolean} preventDefault (true | false) default true
25790 * @cfg {String} icon Font awesome icon
25791 * @cfg {String} pos Submenu align to (left | right) default right
25795 * Create a new Item
25796 * @param {Object} config The config object
25800 Roo.bootstrap.menu.Item = function(config){
25801 Roo.bootstrap.menu.Item.superclass.constructor.call(this, config);
25805 * Fires when the mouse is hovering over this menu
25806 * @param {Roo.bootstrap.menu.Item} this
25807 * @param {Roo.EventObject} e
25812 * Fires when the mouse exits this menu
25813 * @param {Roo.bootstrap.menu.Item} this
25814 * @param {Roo.EventObject} e
25820 * The raw click event for the entire grid.
25821 * @param {Roo.EventObject} e
25827 Roo.extend(Roo.bootstrap.menu.Item, Roo.bootstrap.Component, {
25832 preventDefault: true,
25837 getAutoCreate : function()
25842 cls : 'roo-menu-item-text',
25850 cls : 'fa ' + this.icon
25859 href : this.href || '#',
25866 cfg.cls = (typeof(cfg.cls) == 'undefined') ? 'disabled' : (cfg.cls + ' disabled');
25870 cfg.cls = (typeof(cfg.cls) == 'undefined') ? 'dropdown-submenu' : (cfg.cls + ' dropdown-submenu');
25872 if(this.pos == 'left'){
25873 cfg.cls = (typeof(cfg.cls) == 'undefined') ? 'pull-left' : (cfg.cls + ' pull-left');
25880 initEvents : function()
25882 this.el.on('mouseover', this.onMouseOver, this);
25883 this.el.on('mouseout', this.onMouseOut, this);
25885 this.el.select('a', true).first().on('click', this.onClick, this);
25889 onClick : function(e)
25891 if(this.preventDefault){
25892 e.preventDefault();
25895 this.fireEvent("click", this, e);
25898 onMouseOver : function(e)
25900 if(this.submenu && this.pos == 'left'){
25901 this.el.select('ul.dropdown-menu', true).first().setLeft(this.el.select('ul.dropdown-menu', true).first().getWidth() * -1);
25904 this.fireEvent("mouseover", this, e);
25907 onMouseOut : function(e)
25909 this.fireEvent("mouseout", this, e);
25921 Roo.bootstrap.menu = Roo.bootstrap.menu || {};
25924 * @class Roo.bootstrap.menu.Separator
25925 * @extends Roo.bootstrap.Component
25926 * Bootstrap Separator class
25929 * Create a new Separator
25930 * @param {Object} config The config object
25934 Roo.bootstrap.menu.Separator = function(config){
25935 Roo.bootstrap.menu.Separator.superclass.constructor.call(this, config);
25938 Roo.extend(Roo.bootstrap.menu.Separator, Roo.bootstrap.Component, {
25940 getAutoCreate : function(){
25961 * @class Roo.bootstrap.Tooltip
25962 * Bootstrap Tooltip class
25963 * This is basic at present - all componets support it by default, however they should add tooltipEl() method
25964 * to determine which dom element triggers the tooltip.
25966 * It needs to add support for additional attributes like tooltip-position
25969 * Create a new Toolti
25970 * @param {Object} config The config object
25973 Roo.bootstrap.Tooltip = function(config){
25974 Roo.bootstrap.Tooltip.superclass.constructor.call(this, config);
25976 this.alignment = Roo.bootstrap.Tooltip.alignment;
25978 if(typeof(config) != 'undefined' && typeof(config.alignment) != 'undefined'){
25979 this.alignment = config.alignment;
25984 Roo.apply(Roo.bootstrap.Tooltip, {
25986 * @function init initialize tooltip monitoring.
25990 currentTip : false,
25991 currentRegion : false,
25997 Roo.get(document).on('mouseover', this.enter ,this);
25998 Roo.get(document).on('mouseout', this.leave, this);
26001 this.currentTip = new Roo.bootstrap.Tooltip();
26004 enter : function(ev)
26006 var dom = ev.getTarget();
26008 //Roo.log(['enter',dom]);
26009 var el = Roo.fly(dom);
26010 if (this.currentEl) {
26012 //Roo.log(this.currentEl);
26013 //Roo.log(this.currentEl.contains(dom));
26014 if (this.currentEl == el) {
26017 if (dom != this.currentEl.dom && this.currentEl.contains(dom)) {
26023 if (this.currentTip.el) {
26024 this.currentTip.el.setVisibilityMode(Roo.Element.DISPLAY).hide(); // force hiding...
26028 if(!el || el.dom == document){
26034 // you can not look for children, as if el is the body.. then everythign is the child..
26035 if (!el.attr('tooltip')) { //
26036 if (!el.select("[tooltip]").elements.length) {
26039 // is the mouse over this child...?
26040 bindEl = el.select("[tooltip]").first();
26041 var xy = ev.getXY();
26042 if (!bindEl.getRegion().contains( { top : xy[1] ,right : xy[0] , bottom : xy[1], left : xy[0]})) {
26043 //Roo.log("not in region.");
26046 //Roo.log("child element over..");
26049 this.currentEl = bindEl;
26050 this.currentTip.bind(bindEl);
26051 this.currentRegion = Roo.lib.Region.getRegion(dom);
26052 this.currentTip.enter();
26055 leave : function(ev)
26057 var dom = ev.getTarget();
26058 //Roo.log(['leave',dom]);
26059 if (!this.currentEl) {
26064 if (dom != this.currentEl.dom) {
26067 var xy = ev.getXY();
26068 if (this.currentRegion.contains( new Roo.lib.Region( xy[1], xy[0] ,xy[1], xy[0] ))) {
26071 // only activate leave if mouse cursor is outside... bounding box..
26076 if (this.currentTip) {
26077 this.currentTip.leave();
26079 //Roo.log('clear currentEl');
26080 this.currentEl = false;
26085 'left' : ['r-l', [-2,0], 'right'],
26086 'right' : ['l-r', [2,0], 'left'],
26087 'bottom' : ['t-b', [0,2], 'top'],
26088 'top' : [ 'b-t', [0,-2], 'bottom']
26094 Roo.extend(Roo.bootstrap.Tooltip, Roo.bootstrap.Component, {
26099 delay : null, // can be { show : 300 , hide: 500}
26103 hoverState : null, //???
26105 placement : 'bottom',
26109 getAutoCreate : function(){
26116 cls : 'tooltip-arrow'
26119 cls : 'tooltip-inner'
26126 bind : function(el)
26132 enter : function () {
26134 if (this.timeout != null) {
26135 clearTimeout(this.timeout);
26138 this.hoverState = 'in';
26139 //Roo.log("enter - show");
26140 if (!this.delay || !this.delay.show) {
26145 this.timeout = setTimeout(function () {
26146 if (_t.hoverState == 'in') {
26149 }, this.delay.show);
26153 clearTimeout(this.timeout);
26155 this.hoverState = 'out';
26156 if (!this.delay || !this.delay.hide) {
26162 this.timeout = setTimeout(function () {
26163 //Roo.log("leave - timeout");
26165 if (_t.hoverState == 'out') {
26167 Roo.bootstrap.Tooltip.currentEl = false;
26172 show : function (msg)
26175 this.render(document.body);
26178 //Roo.log([this.bindEl, this.bindEl.attr('tooltip')]);
26180 var tip = msg || this.bindEl.attr('tooltip') || this.bindEl.select("[tooltip]").first().attr('tooltip');
26182 this.el.select('.tooltip-inner',true).first().dom.innerHTML = tip;
26184 this.el.removeClass(['fade','top','bottom', 'left', 'right','in']);
26186 var placement = typeof this.placement == 'function' ?
26187 this.placement.call(this, this.el, on_el) :
26190 var autoToken = /\s?auto?\s?/i;
26191 var autoPlace = autoToken.test(placement);
26193 placement = placement.replace(autoToken, '') || 'top';
26197 //this.el.setXY([0,0]);
26199 //this.el.dom.style.display='block';
26201 //this.el.appendTo(on_el);
26203 var p = this.getPosition();
26204 var box = this.el.getBox();
26210 var align = this.alignment[placement];
26212 var xy = this.el.getAlignToXY(this.bindEl, align[0], align[1]);
26214 if(placement == 'top' || placement == 'bottom'){
26216 placement = 'right';
26219 if(xy[0] + this.el.getWidth() > Roo.lib.Dom.getViewWidth()){
26220 placement = 'left';
26223 var scroll = Roo.select('body', true).first().getScroll();
26225 if(xy[1] > Roo.lib.Dom.getViewHeight() + scroll.top - this.el.getHeight()){
26229 align = this.alignment[placement];
26232 this.el.alignTo(this.bindEl, align[0],align[1]);
26233 //var arrow = this.el.select('.arrow',true).first();
26234 //arrow.set(align[2],
26236 this.el.addClass(placement);
26238 this.el.addClass('in fade');
26240 this.hoverState = null;
26242 if (this.el.hasClass('fade')) {
26253 //this.el.setXY([0,0]);
26254 this.el.removeClass('in');
26270 * @class Roo.bootstrap.LocationPicker
26271 * @extends Roo.bootstrap.Component
26272 * Bootstrap LocationPicker class
26273 * @cfg {Number} latitude Position when init default 0
26274 * @cfg {Number} longitude Position when init default 0
26275 * @cfg {Number} zoom default 15
26276 * @cfg {String} mapTypeId default google.maps.MapTypeId.ROADMAP
26277 * @cfg {Boolean} mapTypeControl default false
26278 * @cfg {Boolean} disableDoubleClickZoom default false
26279 * @cfg {Boolean} scrollwheel default true
26280 * @cfg {Boolean} streetViewControl default false
26281 * @cfg {Number} radius default 0
26282 * @cfg {String} locationName
26283 * @cfg {Boolean} draggable default true
26284 * @cfg {Boolean} enableAutocomplete default false
26285 * @cfg {Boolean} enableReverseGeocode default true
26286 * @cfg {String} markerTitle
26289 * Create a new LocationPicker
26290 * @param {Object} config The config object
26294 Roo.bootstrap.LocationPicker = function(config){
26296 Roo.bootstrap.LocationPicker.superclass.constructor.call(this, config);
26301 * Fires when the picker initialized.
26302 * @param {Roo.bootstrap.LocationPicker} this
26303 * @param {Google Location} location
26307 * @event positionchanged
26308 * Fires when the picker position changed.
26309 * @param {Roo.bootstrap.LocationPicker} this
26310 * @param {Google Location} location
26312 positionchanged : true,
26315 * Fires when the map resize.
26316 * @param {Roo.bootstrap.LocationPicker} this
26321 * Fires when the map show.
26322 * @param {Roo.bootstrap.LocationPicker} this
26327 * Fires when the map hide.
26328 * @param {Roo.bootstrap.LocationPicker} this
26333 * Fires when click the map.
26334 * @param {Roo.bootstrap.LocationPicker} this
26335 * @param {Map event} e
26339 * @event mapRightClick
26340 * Fires when right click the map.
26341 * @param {Roo.bootstrap.LocationPicker} this
26342 * @param {Map event} e
26344 mapRightClick : true,
26346 * @event markerClick
26347 * Fires when click the marker.
26348 * @param {Roo.bootstrap.LocationPicker} this
26349 * @param {Map event} e
26351 markerClick : true,
26353 * @event markerRightClick
26354 * Fires when right click the marker.
26355 * @param {Roo.bootstrap.LocationPicker} this
26356 * @param {Map event} e
26358 markerRightClick : true,
26360 * @event OverlayViewDraw
26361 * Fires when OverlayView Draw
26362 * @param {Roo.bootstrap.LocationPicker} this
26364 OverlayViewDraw : true,
26366 * @event OverlayViewOnAdd
26367 * Fires when OverlayView Draw
26368 * @param {Roo.bootstrap.LocationPicker} this
26370 OverlayViewOnAdd : true,
26372 * @event OverlayViewOnRemove
26373 * Fires when OverlayView Draw
26374 * @param {Roo.bootstrap.LocationPicker} this
26376 OverlayViewOnRemove : true,
26378 * @event OverlayViewShow
26379 * Fires when OverlayView Draw
26380 * @param {Roo.bootstrap.LocationPicker} this
26381 * @param {Pixel} cpx
26383 OverlayViewShow : true,
26385 * @event OverlayViewHide
26386 * Fires when OverlayView Draw
26387 * @param {Roo.bootstrap.LocationPicker} this
26389 OverlayViewHide : true,
26391 * @event loadexception
26392 * Fires when load google lib failed.
26393 * @param {Roo.bootstrap.LocationPicker} this
26395 loadexception : true
26400 Roo.extend(Roo.bootstrap.LocationPicker, Roo.bootstrap.Component, {
26402 gMapContext: false,
26408 mapTypeControl: false,
26409 disableDoubleClickZoom: false,
26411 streetViewControl: false,
26415 enableAutocomplete: false,
26416 enableReverseGeocode: true,
26419 getAutoCreate: function()
26424 cls: 'roo-location-picker'
26430 initEvents: function(ct, position)
26432 if(!this.el.getWidth() || this.isApplied()){
26436 this.el.setVisibilityMode(Roo.Element.DISPLAY);
26441 initial: function()
26443 if(typeof(google) == 'undefined' || typeof(google.maps) == 'undefined'){
26444 this.fireEvent('loadexception', this);
26448 if(!this.mapTypeId){
26449 this.mapTypeId = google.maps.MapTypeId.ROADMAP;
26452 this.gMapContext = this.GMapContext();
26454 this.initOverlayView();
26456 this.OverlayView = new Roo.bootstrap.LocationPicker.OverlayView(this.gMapContext.map);
26460 google.maps.event.addListener(this.gMapContext.marker, "dragend", function(event) {
26461 _this.setPosition(_this.gMapContext.marker.position);
26464 google.maps.event.addListener(this.gMapContext.map, 'click', function(event){
26465 _this.fireEvent('mapClick', this, event);
26469 google.maps.event.addListener(this.gMapContext.map, 'rightclick', function(event){
26470 _this.fireEvent('mapRightClick', this, event);
26474 google.maps.event.addListener(this.gMapContext.marker, 'click', function(event){
26475 _this.fireEvent('markerClick', this, event);
26479 google.maps.event.addListener(this.gMapContext.marker, 'rightclick', function(event){
26480 _this.fireEvent('markerRightClick', this, event);
26484 this.setPosition(this.gMapContext.location);
26486 this.fireEvent('initial', this, this.gMapContext.location);
26489 initOverlayView: function()
26493 Roo.bootstrap.LocationPicker.OverlayView.prototype = Roo.apply(new google.maps.OverlayView(), {
26497 _this.fireEvent('OverlayViewDraw', _this);
26502 _this.fireEvent('OverlayViewOnAdd', _this);
26505 onRemove: function()
26507 _this.fireEvent('OverlayViewOnRemove', _this);
26510 show: function(cpx)
26512 _this.fireEvent('OverlayViewShow', _this, cpx);
26517 _this.fireEvent('OverlayViewHide', _this);
26523 fromLatLngToContainerPixel: function(event)
26525 return this.OverlayView.getProjection().fromLatLngToContainerPixel(event.latLng);
26528 isApplied: function()
26530 return this.getGmapContext() == false ? false : true;
26533 getGmapContext: function()
26535 return (typeof(this.gMapContext) == 'undefined') ? false : this.gMapContext;
26538 GMapContext: function()
26540 var position = new google.maps.LatLng(this.latitude, this.longitude);
26542 var _map = new google.maps.Map(this.el.dom, {
26545 mapTypeId: this.mapTypeId,
26546 mapTypeControl: this.mapTypeControl,
26547 disableDoubleClickZoom: this.disableDoubleClickZoom,
26548 scrollwheel: this.scrollwheel,
26549 streetViewControl: this.streetViewControl,
26550 locationName: this.locationName,
26551 draggable: this.draggable,
26552 enableAutocomplete: this.enableAutocomplete,
26553 enableReverseGeocode: this.enableReverseGeocode
26556 var _marker = new google.maps.Marker({
26557 position: position,
26559 title: this.markerTitle,
26560 draggable: this.draggable
26567 location: position,
26568 radius: this.radius,
26569 locationName: this.locationName,
26570 addressComponents: {
26571 formatted_address: null,
26572 addressLine1: null,
26573 addressLine2: null,
26575 streetNumber: null,
26579 stateOrProvince: null
26582 domContainer: this.el.dom,
26583 geodecoder: new google.maps.Geocoder()
26587 drawCircle: function(center, radius, options)
26589 if (this.gMapContext.circle != null) {
26590 this.gMapContext.circle.setMap(null);
26594 options = Roo.apply({}, options, {
26595 strokeColor: "#0000FF",
26596 strokeOpacity: .35,
26598 fillColor: "#0000FF",
26602 options.map = this.gMapContext.map;
26603 options.radius = radius;
26604 options.center = center;
26605 this.gMapContext.circle = new google.maps.Circle(options);
26606 return this.gMapContext.circle;
26612 setPosition: function(location)
26614 this.gMapContext.location = location;
26615 this.gMapContext.marker.setPosition(location);
26616 this.gMapContext.map.panTo(location);
26617 this.drawCircle(location, this.gMapContext.radius, {});
26621 if (this.gMapContext.settings.enableReverseGeocode) {
26622 this.gMapContext.geodecoder.geocode({
26623 latLng: this.gMapContext.location
26624 }, function(results, status) {
26626 if (status == google.maps.GeocoderStatus.OK && results.length > 0) {
26627 _this.gMapContext.locationName = results[0].formatted_address;
26628 _this.gMapContext.addressComponents = _this.address_component_from_google_geocode(results[0].address_components);
26630 _this.fireEvent('positionchanged', this, location);
26637 this.fireEvent('positionchanged', this, location);
26642 google.maps.event.trigger(this.gMapContext.map, "resize");
26644 this.gMapContext.map.setCenter(this.gMapContext.marker.position);
26646 this.fireEvent('resize', this);
26649 setPositionByLatLng: function(latitude, longitude)
26651 this.setPosition(new google.maps.LatLng(latitude, longitude));
26654 getCurrentPosition: function()
26657 latitude: this.gMapContext.location.lat(),
26658 longitude: this.gMapContext.location.lng()
26662 getAddressName: function()
26664 return this.gMapContext.locationName;
26667 getAddressComponents: function()
26669 return this.gMapContext.addressComponents;
26672 address_component_from_google_geocode: function(address_components)
26676 for (var i = 0; i < address_components.length; i++) {
26677 var component = address_components[i];
26678 if (component.types.indexOf("postal_code") >= 0) {
26679 result.postalCode = component.short_name;
26680 } else if (component.types.indexOf("street_number") >= 0) {
26681 result.streetNumber = component.short_name;
26682 } else if (component.types.indexOf("route") >= 0) {
26683 result.streetName = component.short_name;
26684 } else if (component.types.indexOf("neighborhood") >= 0) {
26685 result.city = component.short_name;
26686 } else if (component.types.indexOf("locality") >= 0) {
26687 result.city = component.short_name;
26688 } else if (component.types.indexOf("sublocality") >= 0) {
26689 result.district = component.short_name;
26690 } else if (component.types.indexOf("administrative_area_level_1") >= 0) {
26691 result.stateOrProvince = component.short_name;
26692 } else if (component.types.indexOf("country") >= 0) {
26693 result.country = component.short_name;
26697 result.addressLine1 = [ result.streetNumber, result.streetName ].join(" ").trim();
26698 result.addressLine2 = "";
26702 setZoomLevel: function(zoom)
26704 this.gMapContext.map.setZoom(zoom);
26717 this.fireEvent('show', this);
26728 this.fireEvent('hide', this);
26733 Roo.apply(Roo.bootstrap.LocationPicker, {
26735 OverlayView : function(map, options)
26737 options = options || {};
26751 * @class Roo.bootstrap.Alert
26752 * @extends Roo.bootstrap.Component
26753 * Bootstrap Alert class
26754 * @cfg {String} title The title of alert
26755 * @cfg {String} html The content of alert
26756 * @cfg {String} weight ( success | info | warning | danger )
26757 * @cfg {String} faicon font-awesomeicon
26760 * Create a new alert
26761 * @param {Object} config The config object
26765 Roo.bootstrap.Alert = function(config){
26766 Roo.bootstrap.Alert.superclass.constructor.call(this, config);
26770 Roo.extend(Roo.bootstrap.Alert, Roo.bootstrap.Component, {
26777 getAutoCreate : function()
26786 cls : 'roo-alert-icon'
26791 cls : 'roo-alert-title',
26796 cls : 'roo-alert-text',
26803 cfg.cn[0].cls += ' fa ' + this.faicon;
26807 cfg.cls += ' alert-' + this.weight;
26813 initEvents: function()
26815 this.el.setVisibilityMode(Roo.Element.DISPLAY);
26818 setTitle : function(str)
26820 this.el.select('.roo-alert-title',true).first().dom.innerHTML = str;
26823 setText : function(str)
26825 this.el.select('.roo-alert-text',true).first().dom.innerHTML = str;
26828 setWeight : function(weight)
26831 this.el.select('.alert',true).first().removeClass('alert-' + this.weight);
26834 this.weight = weight;
26836 this.el.select('.alert',true).first().addClass('alert-' + this.weight);
26839 setIcon : function(icon)
26842 this.el.select('.roo-alert-icon',true).first().removeClass(['fa', 'fa-' + this.faicon]);
26845 this.faicon = icon;
26847 this.el.select('.roo-alert-icon',true).first().addClass(['fa', 'fa-' + this.faicon]);
26868 * @class Roo.bootstrap.UploadCropbox
26869 * @extends Roo.bootstrap.Component
26870 * Bootstrap UploadCropbox class
26871 * @cfg {String} emptyText show when image has been loaded
26872 * @cfg {String} rotateNotify show when image too small to rotate
26873 * @cfg {Number} errorTimeout default 3000
26874 * @cfg {Number} minWidth default 300
26875 * @cfg {Number} minHeight default 300
26876 * @cfg {Array} buttons default ['rotateLeft', 'pictureBtn', 'rotateRight']
26877 * @cfg {Boolean} isDocument (true|false) default false
26878 * @cfg {String} url action url
26879 * @cfg {String} paramName default 'imageUpload'
26880 * @cfg {String} method default POST
26881 * @cfg {Boolean} loadMask (true|false) default true
26882 * @cfg {Boolean} loadingText default 'Loading...'
26885 * Create a new UploadCropbox
26886 * @param {Object} config The config object
26889 Roo.bootstrap.UploadCropbox = function(config){
26890 Roo.bootstrap.UploadCropbox.superclass.constructor.call(this, config);
26894 * @event beforeselectfile
26895 * Fire before select file
26896 * @param {Roo.bootstrap.UploadCropbox} this
26898 "beforeselectfile" : true,
26901 * Fire after initEvent
26902 * @param {Roo.bootstrap.UploadCropbox} this
26907 * Fire after initEvent
26908 * @param {Roo.bootstrap.UploadCropbox} this
26909 * @param {String} data
26914 * Fire when preparing the file data
26915 * @param {Roo.bootstrap.UploadCropbox} this
26916 * @param {Object} file
26921 * Fire when get exception
26922 * @param {Roo.bootstrap.UploadCropbox} this
26923 * @param {XMLHttpRequest} xhr
26925 "exception" : true,
26927 * @event beforeloadcanvas
26928 * Fire before load the canvas
26929 * @param {Roo.bootstrap.UploadCropbox} this
26930 * @param {String} src
26932 "beforeloadcanvas" : true,
26935 * Fire when trash image
26936 * @param {Roo.bootstrap.UploadCropbox} this
26941 * Fire when download the image
26942 * @param {Roo.bootstrap.UploadCropbox} this
26946 * @event footerbuttonclick
26947 * Fire when footerbuttonclick
26948 * @param {Roo.bootstrap.UploadCropbox} this
26949 * @param {String} type
26951 "footerbuttonclick" : true,
26955 * @param {Roo.bootstrap.UploadCropbox} this
26960 * Fire when rotate the image
26961 * @param {Roo.bootstrap.UploadCropbox} this
26962 * @param {String} pos
26967 * Fire when inspect the file
26968 * @param {Roo.bootstrap.UploadCropbox} this
26969 * @param {Object} file
26974 * Fire when xhr upload the file
26975 * @param {Roo.bootstrap.UploadCropbox} this
26976 * @param {Object} data
26981 * Fire when arrange the file data
26982 * @param {Roo.bootstrap.UploadCropbox} this
26983 * @param {Object} formData
26988 this.buttons = this.buttons || Roo.bootstrap.UploadCropbox.footer.STANDARD;
26991 Roo.extend(Roo.bootstrap.UploadCropbox, Roo.bootstrap.Component, {
26993 emptyText : 'Click to upload image',
26994 rotateNotify : 'Image is too small to rotate',
26995 errorTimeout : 3000,
27009 cropType : 'image/jpeg',
27011 canvasLoaded : false,
27012 isDocument : false,
27014 paramName : 'imageUpload',
27016 loadingText : 'Loading...',
27019 getAutoCreate : function()
27023 cls : 'roo-upload-cropbox',
27027 cls : 'roo-upload-cropbox-selector',
27032 cls : 'roo-upload-cropbox-body',
27033 style : 'cursor:pointer',
27037 cls : 'roo-upload-cropbox-preview'
27041 cls : 'roo-upload-cropbox-thumb'
27045 cls : 'roo-upload-cropbox-empty-notify',
27046 html : this.emptyText
27050 cls : 'roo-upload-cropbox-error-notify alert alert-danger',
27051 html : this.rotateNotify
27057 cls : 'roo-upload-cropbox-footer',
27060 cls : 'btn-group btn-group-justified roo-upload-cropbox-btn-group',
27070 onRender : function(ct, position)
27072 Roo.bootstrap.UploadCropbox.superclass.onRender.call(this, ct, position);
27074 if (this.buttons.length) {
27076 Roo.each(this.buttons, function(bb) {
27078 var btn = this.el.select('.roo-upload-cropbox-footer div.roo-upload-cropbox-btn-group').first().createChild(bb);
27080 btn.on('click', this.onFooterButtonClick.createDelegate(this, [bb.action], true));
27086 this.maskEl = this.el;
27090 initEvents : function()
27092 this.urlAPI = (window.createObjectURL && window) ||
27093 (window.URL && URL.revokeObjectURL && URL) ||
27094 (window.webkitURL && webkitURL);
27096 this.bodyEl = this.el.select('.roo-upload-cropbox-body', true).first();
27097 this.bodyEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
27099 this.selectorEl = this.el.select('.roo-upload-cropbox-selector', true).first();
27100 this.selectorEl.hide();
27102 this.previewEl = this.el.select('.roo-upload-cropbox-preview', true).first();
27103 this.previewEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
27105 this.thumbEl = this.el.select('.roo-upload-cropbox-thumb', true).first();
27106 this.thumbEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
27107 this.thumbEl.hide();
27109 this.notifyEl = this.el.select('.roo-upload-cropbox-empty-notify', true).first();
27110 this.notifyEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
27112 this.errorEl = this.el.select('.roo-upload-cropbox-error-notify', true).first();
27113 this.errorEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
27114 this.errorEl.hide();
27116 this.footerEl = this.el.select('.roo-upload-cropbox-footer', true).first();
27117 this.footerEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
27118 this.footerEl.hide();
27120 this.setThumbBoxSize();
27126 this.fireEvent('initial', this);
27133 window.addEventListener("resize", function() { _this.resize(); } );
27135 this.bodyEl.on('click', this.beforeSelectFile, this);
27138 this.bodyEl.on('touchstart', this.onTouchStart, this);
27139 this.bodyEl.on('touchmove', this.onTouchMove, this);
27140 this.bodyEl.on('touchend', this.onTouchEnd, this);
27144 this.bodyEl.on('mousedown', this.onMouseDown, this);
27145 this.bodyEl.on('mousemove', this.onMouseMove, this);
27146 var mousewheel = (/Firefox/i.test(navigator.userAgent))? 'DOMMouseScroll' : 'mousewheel';
27147 this.bodyEl.on(mousewheel, this.onMouseWheel, this);
27148 Roo.get(document).on('mouseup', this.onMouseUp, this);
27151 this.selectorEl.on('change', this.onFileSelected, this);
27157 this.baseScale = 1;
27159 this.baseRotate = 1;
27160 this.dragable = false;
27161 this.pinching = false;
27164 this.cropData = false;
27165 this.notifyEl.dom.innerHTML = this.emptyText;
27167 this.selectorEl.dom.value = '';
27171 resize : function()
27173 if(this.fireEvent('resize', this) != false){
27174 this.setThumbBoxPosition();
27175 this.setCanvasPosition();
27179 onFooterButtonClick : function(e, el, o, type)
27182 case 'rotate-left' :
27183 this.onRotateLeft(e);
27185 case 'rotate-right' :
27186 this.onRotateRight(e);
27189 this.beforeSelectFile(e);
27204 this.fireEvent('footerbuttonclick', this, type);
27207 beforeSelectFile : function(e)
27209 e.preventDefault();
27211 if(this.fireEvent('beforeselectfile', this) != false){
27212 this.selectorEl.dom.click();
27216 onFileSelected : function(e)
27218 e.preventDefault();
27220 if(typeof(this.selectorEl.dom.files) == 'undefined' || !this.selectorEl.dom.files.length){
27224 var file = this.selectorEl.dom.files[0];
27226 if(this.fireEvent('inspect', this, file) != false){
27227 this.prepare(file);
27232 trash : function(e)
27234 this.fireEvent('trash', this);
27237 download : function(e)
27239 this.fireEvent('download', this);
27242 loadCanvas : function(src)
27244 if(this.fireEvent('beforeloadcanvas', this, src) != false){
27248 this.imageEl = document.createElement('img');
27252 this.imageEl.addEventListener("load", function(){ _this.onLoadCanvas(); });
27254 this.imageEl.src = src;
27258 onLoadCanvas : function()
27260 this.imageEl.OriginWidth = this.imageEl.naturalWidth || this.imageEl.width;
27261 this.imageEl.OriginHeight = this.imageEl.naturalHeight || this.imageEl.height;
27263 this.bodyEl.un('click', this.beforeSelectFile, this);
27265 this.notifyEl.hide();
27266 this.thumbEl.show();
27267 this.footerEl.show();
27269 this.baseRotateLevel();
27271 if(this.isDocument){
27272 this.setThumbBoxSize();
27275 this.setThumbBoxPosition();
27277 this.baseScaleLevel();
27283 this.canvasLoaded = true;
27286 this.maskEl.unmask();
27291 setCanvasPosition : function()
27293 if(!this.canvasEl){
27297 var pw = Math.ceil((this.bodyEl.getWidth() - this.canvasEl.width) / 2);
27298 var ph = Math.ceil((this.bodyEl.getHeight() - this.canvasEl.height) / 2);
27300 this.previewEl.setLeft(pw);
27301 this.previewEl.setTop(ph);
27305 onMouseDown : function(e)
27309 this.dragable = true;
27310 this.pinching = false;
27312 if(this.isDocument && (this.canvasEl.width < this.thumbEl.getWidth() || this.canvasEl.height < this.thumbEl.getHeight())){
27313 this.dragable = false;
27317 this.mouseX = Roo.isTouch ? e.browserEvent.touches[0].pageX : e.getPageX();
27318 this.mouseY = Roo.isTouch ? e.browserEvent.touches[0].pageY : e.getPageY();
27322 onMouseMove : function(e)
27326 if(!this.canvasLoaded){
27330 if (!this.dragable){
27334 var minX = Math.ceil(this.thumbEl.getLeft(true));
27335 var minY = Math.ceil(this.thumbEl.getTop(true));
27337 var maxX = Math.ceil(minX + this.thumbEl.getWidth() - this.canvasEl.width);
27338 var maxY = Math.ceil(minY + this.thumbEl.getHeight() - this.canvasEl.height);
27340 var x = Roo.isTouch ? e.browserEvent.touches[0].pageX : e.getPageX();
27341 var y = Roo.isTouch ? e.browserEvent.touches[0].pageY : e.getPageY();
27343 x = x - this.mouseX;
27344 y = y - this.mouseY;
27346 var bgX = Math.ceil(x + this.previewEl.getLeft(true));
27347 var bgY = Math.ceil(y + this.previewEl.getTop(true));
27349 bgX = (minX < bgX) ? minX : ((maxX > bgX) ? maxX : bgX);
27350 bgY = (minY < bgY) ? minY : ((maxY > bgY) ? maxY : bgY);
27352 this.previewEl.setLeft(bgX);
27353 this.previewEl.setTop(bgY);
27355 this.mouseX = Roo.isTouch ? e.browserEvent.touches[0].pageX : e.getPageX();
27356 this.mouseY = Roo.isTouch ? e.browserEvent.touches[0].pageY : e.getPageY();
27359 onMouseUp : function(e)
27363 this.dragable = false;
27366 onMouseWheel : function(e)
27370 this.startScale = this.scale;
27372 this.scale = (e.getWheelDelta() == 1) ? (this.scale + 1) : (this.scale - 1);
27374 if(!this.zoomable()){
27375 this.scale = this.startScale;
27384 zoomable : function()
27386 var minScale = this.thumbEl.getWidth() / this.minWidth;
27388 if(this.minWidth < this.minHeight){
27389 minScale = this.thumbEl.getHeight() / this.minHeight;
27392 var width = Math.ceil(this.imageEl.OriginWidth * this.getScaleLevel() / minScale);
27393 var height = Math.ceil(this.imageEl.OriginHeight * this.getScaleLevel() / minScale);
27397 (this.rotate == 0 || this.rotate == 180) &&
27399 width > this.imageEl.OriginWidth ||
27400 height > this.imageEl.OriginHeight ||
27401 (width < this.minWidth && height < this.minHeight)
27409 (this.rotate == 90 || this.rotate == 270) &&
27411 width > this.imageEl.OriginWidth ||
27412 height > this.imageEl.OriginHeight ||
27413 (width < this.minHeight && height < this.minWidth)
27420 !this.isDocument &&
27421 (this.rotate == 0 || this.rotate == 180) &&
27423 width < this.minWidth ||
27424 width > this.imageEl.OriginWidth ||
27425 height < this.minHeight ||
27426 height > this.imageEl.OriginHeight
27433 !this.isDocument &&
27434 (this.rotate == 90 || this.rotate == 270) &&
27436 width < this.minHeight ||
27437 width > this.imageEl.OriginWidth ||
27438 height < this.minWidth ||
27439 height > this.imageEl.OriginHeight
27449 onRotateLeft : function(e)
27451 if(!this.isDocument && (this.canvasEl.height < this.thumbEl.getWidth() || this.canvasEl.width < this.thumbEl.getHeight())){
27453 var minScale = this.thumbEl.getWidth() / this.minWidth;
27455 var bw = Math.ceil(this.canvasEl.width / this.getScaleLevel());
27456 var bh = Math.ceil(this.canvasEl.height / this.getScaleLevel());
27458 this.startScale = this.scale;
27460 while (this.getScaleLevel() < minScale){
27462 this.scale = this.scale + 1;
27464 if(!this.zoomable()){
27469 Math.ceil(bw * this.getScaleLevel()) < this.thumbEl.getHeight() ||
27470 Math.ceil(bh * this.getScaleLevel()) < this.thumbEl.getWidth()
27475 this.rotate = (this.rotate < 90) ? 270 : this.rotate - 90;
27482 this.scale = this.startScale;
27484 this.onRotateFail();
27489 this.rotate = (this.rotate < 90) ? 270 : this.rotate - 90;
27491 if(this.isDocument){
27492 this.setThumbBoxSize();
27493 this.setThumbBoxPosition();
27494 this.setCanvasPosition();
27499 this.fireEvent('rotate', this, 'left');
27503 onRotateRight : function(e)
27505 if(!this.isDocument && (this.canvasEl.height < this.thumbEl.getWidth() || this.canvasEl.width < this.thumbEl.getHeight())){
27507 var minScale = this.thumbEl.getWidth() / this.minWidth;
27509 var bw = Math.ceil(this.canvasEl.width / this.getScaleLevel());
27510 var bh = Math.ceil(this.canvasEl.height / this.getScaleLevel());
27512 this.startScale = this.scale;
27514 while (this.getScaleLevel() < minScale){
27516 this.scale = this.scale + 1;
27518 if(!this.zoomable()){
27523 Math.ceil(bw * this.getScaleLevel()) < this.thumbEl.getHeight() ||
27524 Math.ceil(bh * this.getScaleLevel()) < this.thumbEl.getWidth()
27529 this.rotate = (this.rotate > 180) ? 0 : this.rotate + 90;
27536 this.scale = this.startScale;
27538 this.onRotateFail();
27543 this.rotate = (this.rotate > 180) ? 0 : this.rotate + 90;
27545 if(this.isDocument){
27546 this.setThumbBoxSize();
27547 this.setThumbBoxPosition();
27548 this.setCanvasPosition();
27553 this.fireEvent('rotate', this, 'right');
27556 onRotateFail : function()
27558 this.errorEl.show(true);
27562 (function() { _this.errorEl.hide(true); }).defer(this.errorTimeout);
27567 this.previewEl.dom.innerHTML = '';
27569 var canvasEl = document.createElement("canvas");
27571 var contextEl = canvasEl.getContext("2d");
27573 canvasEl.width = this.imageEl.OriginWidth * this.getScaleLevel();
27574 canvasEl.height = this.imageEl.OriginWidth * this.getScaleLevel();
27575 var center = this.imageEl.OriginWidth / 2;
27577 if(this.imageEl.OriginWidth < this.imageEl.OriginHeight){
27578 canvasEl.width = this.imageEl.OriginHeight * this.getScaleLevel();
27579 canvasEl.height = this.imageEl.OriginHeight * this.getScaleLevel();
27580 center = this.imageEl.OriginHeight / 2;
27583 contextEl.scale(this.getScaleLevel(), this.getScaleLevel());
27585 contextEl.translate(center, center);
27586 contextEl.rotate(this.rotate * Math.PI / 180);
27588 contextEl.drawImage(this.imageEl, 0, 0, this.imageEl.OriginWidth, this.imageEl.OriginHeight, center * -1, center * -1, this.imageEl.OriginWidth, this.imageEl.OriginHeight);
27590 this.canvasEl = document.createElement("canvas");
27592 this.contextEl = this.canvasEl.getContext("2d");
27594 switch (this.rotate) {
27597 this.canvasEl.width = this.imageEl.OriginWidth * this.getScaleLevel();
27598 this.canvasEl.height = this.imageEl.OriginHeight * this.getScaleLevel();
27600 this.contextEl.drawImage(canvasEl, 0, 0, this.canvasEl.width, this.canvasEl.height, 0, 0, this.canvasEl.width, this.canvasEl.height);
27605 this.canvasEl.width = this.imageEl.OriginHeight * this.getScaleLevel();
27606 this.canvasEl.height = this.imageEl.OriginWidth * this.getScaleLevel();
27608 if(this.imageEl.OriginWidth > this.imageEl.OriginHeight){
27609 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);
27613 this.contextEl.drawImage(canvasEl, 0, 0, this.canvasEl.width, this.canvasEl.height, 0, 0, this.canvasEl.width, this.canvasEl.height);
27618 this.canvasEl.width = this.imageEl.OriginWidth * this.getScaleLevel();
27619 this.canvasEl.height = this.imageEl.OriginHeight * this.getScaleLevel();
27621 if(this.imageEl.OriginWidth > this.imageEl.OriginHeight){
27622 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);
27626 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);
27631 this.canvasEl.width = this.imageEl.OriginHeight * this.getScaleLevel();
27632 this.canvasEl.height = this.imageEl.OriginWidth * this.getScaleLevel();
27634 if(this.imageEl.OriginWidth > this.imageEl.OriginHeight){
27635 this.contextEl.drawImage(canvasEl, 0, 0, this.canvasEl.width, this.canvasEl.height, 0, 0, this.canvasEl.width, this.canvasEl.height);
27639 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);
27646 this.previewEl.appendChild(this.canvasEl);
27648 this.setCanvasPosition();
27653 if(!this.canvasLoaded){
27657 var imageCanvas = document.createElement("canvas");
27659 var imageContext = imageCanvas.getContext("2d");
27661 imageCanvas.width = (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? this.imageEl.OriginWidth : this.imageEl.OriginHeight;
27662 imageCanvas.height = (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? this.imageEl.OriginWidth : this.imageEl.OriginHeight;
27664 var center = imageCanvas.width / 2;
27666 imageContext.translate(center, center);
27668 imageContext.rotate(this.rotate * Math.PI / 180);
27670 imageContext.drawImage(this.imageEl, 0, 0, this.imageEl.OriginWidth, this.imageEl.OriginHeight, center * -1, center * -1, this.imageEl.OriginWidth, this.imageEl.OriginHeight);
27672 var canvas = document.createElement("canvas");
27674 var context = canvas.getContext("2d");
27676 canvas.width = this.minWidth;
27677 canvas.height = this.minHeight;
27679 switch (this.rotate) {
27682 var width = (this.thumbEl.getWidth() / this.getScaleLevel() > this.imageEl.OriginWidth) ? this.imageEl.OriginWidth : (this.thumbEl.getWidth() / this.getScaleLevel());
27683 var height = (this.thumbEl.getHeight() / this.getScaleLevel() > this.imageEl.OriginHeight) ? this.imageEl.OriginHeight : (this.thumbEl.getHeight() / this.getScaleLevel());
27685 var x = (this.thumbEl.getLeft(true) > this.previewEl.getLeft(true)) ? 0 : ((this.previewEl.getLeft(true) - this.thumbEl.getLeft(true)) / this.getScaleLevel());
27686 var y = (this.thumbEl.getTop(true) > this.previewEl.getTop(true)) ? 0 : ((this.previewEl.getTop(true) - this.thumbEl.getTop(true)) / this.getScaleLevel());
27688 var targetWidth = this.minWidth - 2 * x;
27689 var targetHeight = this.minHeight - 2 * y;
27693 if((x == 0 && y == 0) || (x == 0 && y > 0)){
27694 scale = targetWidth / width;
27697 if(x > 0 && y == 0){
27698 scale = targetHeight / height;
27701 if(x > 0 && y > 0){
27702 scale = targetWidth / width;
27704 if(width < height){
27705 scale = targetHeight / height;
27709 context.scale(scale, scale);
27711 var sx = Math.min(this.canvasEl.width - this.thumbEl.getWidth(), this.thumbEl.getLeft(true) - this.previewEl.getLeft(true));
27712 var sy = Math.min(this.canvasEl.height - this.thumbEl.getHeight(), this.thumbEl.getTop(true) - this.previewEl.getTop(true));
27714 sx = sx < 0 ? 0 : (sx / this.getScaleLevel());
27715 sy = sy < 0 ? 0 : (sy / this.getScaleLevel());
27717 context.drawImage(imageCanvas, sx, sy, width, height, x, y, width, height);
27722 var width = (this.thumbEl.getWidth() / this.getScaleLevel() > this.imageEl.OriginHeight) ? this.imageEl.OriginHeight : (this.thumbEl.getWidth() / this.getScaleLevel());
27723 var height = (this.thumbEl.getHeight() / this.getScaleLevel() > this.imageEl.OriginWidth) ? this.imageEl.OriginWidth : (this.thumbEl.getHeight() / this.getScaleLevel());
27725 var x = (this.thumbEl.getLeft(true) > this.previewEl.getLeft(true)) ? 0 : ((this.previewEl.getLeft(true) - this.thumbEl.getLeft(true)) / this.getScaleLevel());
27726 var y = (this.thumbEl.getTop(true) > this.previewEl.getTop(true)) ? 0 : ((this.previewEl.getTop(true) - this.thumbEl.getTop(true)) / this.getScaleLevel());
27728 var targetWidth = this.minWidth - 2 * x;
27729 var targetHeight = this.minHeight - 2 * y;
27733 if((x == 0 && y == 0) || (x == 0 && y > 0)){
27734 scale = targetWidth / width;
27737 if(x > 0 && y == 0){
27738 scale = targetHeight / height;
27741 if(x > 0 && y > 0){
27742 scale = targetWidth / width;
27744 if(width < height){
27745 scale = targetHeight / height;
27749 context.scale(scale, scale);
27751 var sx = Math.min(this.canvasEl.width - this.thumbEl.getWidth(), this.thumbEl.getLeft(true) - this.previewEl.getLeft(true));
27752 var sy = Math.min(this.canvasEl.height - this.thumbEl.getHeight(), this.thumbEl.getTop(true) - this.previewEl.getTop(true));
27754 sx = sx < 0 ? 0 : (sx / this.getScaleLevel());
27755 sy = sy < 0 ? 0 : (sy / this.getScaleLevel());
27757 sx += (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? Math.abs(this.imageEl.OriginWidth - this.imageEl.OriginHeight) : 0;
27759 context.drawImage(imageCanvas, sx, sy, width, height, x, y, width, height);
27764 var width = (this.thumbEl.getWidth() / this.getScaleLevel() > this.imageEl.OriginWidth) ? this.imageEl.OriginWidth : (this.thumbEl.getWidth() / this.getScaleLevel());
27765 var height = (this.thumbEl.getHeight() / this.getScaleLevel() > this.imageEl.OriginHeight) ? this.imageEl.OriginHeight : (this.thumbEl.getHeight() / this.getScaleLevel());
27767 var x = (this.thumbEl.getLeft(true) > this.previewEl.getLeft(true)) ? 0 : ((this.previewEl.getLeft(true) - this.thumbEl.getLeft(true)) / this.getScaleLevel());
27768 var y = (this.thumbEl.getTop(true) > this.previewEl.getTop(true)) ? 0 : ((this.previewEl.getTop(true) - this.thumbEl.getTop(true)) / this.getScaleLevel());
27770 var targetWidth = this.minWidth - 2 * x;
27771 var targetHeight = this.minHeight - 2 * y;
27775 if((x == 0 && y == 0) || (x == 0 && y > 0)){
27776 scale = targetWidth / width;
27779 if(x > 0 && y == 0){
27780 scale = targetHeight / height;
27783 if(x > 0 && y > 0){
27784 scale = targetWidth / width;
27786 if(width < height){
27787 scale = targetHeight / height;
27791 context.scale(scale, scale);
27793 var sx = Math.min(this.canvasEl.width - this.thumbEl.getWidth(), this.thumbEl.getLeft(true) - this.previewEl.getLeft(true));
27794 var sy = Math.min(this.canvasEl.height - this.thumbEl.getHeight(), this.thumbEl.getTop(true) - this.previewEl.getTop(true));
27796 sx = sx < 0 ? 0 : (sx / this.getScaleLevel());
27797 sy = sy < 0 ? 0 : (sy / this.getScaleLevel());
27799 sx += (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? 0 : Math.abs(this.imageEl.OriginWidth - this.imageEl.OriginHeight);
27800 sy += (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? Math.abs(this.imageEl.OriginWidth - this.imageEl.OriginHeight) : 0;
27802 context.drawImage(imageCanvas, sx, sy, width, height, x, y, width, height);
27807 var width = (this.thumbEl.getWidth() / this.getScaleLevel() > this.imageEl.OriginHeight) ? this.imageEl.OriginHeight : (this.thumbEl.getWidth() / this.getScaleLevel());
27808 var height = (this.thumbEl.getHeight() / this.getScaleLevel() > this.imageEl.OriginWidth) ? this.imageEl.OriginWidth : (this.thumbEl.getHeight() / this.getScaleLevel());
27810 var x = (this.thumbEl.getLeft(true) > this.previewEl.getLeft(true)) ? 0 : ((this.previewEl.getLeft(true) - this.thumbEl.getLeft(true)) / this.getScaleLevel());
27811 var y = (this.thumbEl.getTop(true) > this.previewEl.getTop(true)) ? 0 : ((this.previewEl.getTop(true) - this.thumbEl.getTop(true)) / this.getScaleLevel());
27813 var targetWidth = this.minWidth - 2 * x;
27814 var targetHeight = this.minHeight - 2 * y;
27818 if((x == 0 && y == 0) || (x == 0 && y > 0)){
27819 scale = targetWidth / width;
27822 if(x > 0 && y == 0){
27823 scale = targetHeight / height;
27826 if(x > 0 && y > 0){
27827 scale = targetWidth / width;
27829 if(width < height){
27830 scale = targetHeight / height;
27834 context.scale(scale, scale);
27836 var sx = Math.min(this.canvasEl.width - this.thumbEl.getWidth(), this.thumbEl.getLeft(true) - this.previewEl.getLeft(true));
27837 var sy = Math.min(this.canvasEl.height - this.thumbEl.getHeight(), this.thumbEl.getTop(true) - this.previewEl.getTop(true));
27839 sx = sx < 0 ? 0 : (sx / this.getScaleLevel());
27840 sy = sy < 0 ? 0 : (sy / this.getScaleLevel());
27842 sy += (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? 0 : Math.abs(this.imageEl.OriginWidth - this.imageEl.OriginHeight);
27844 context.drawImage(imageCanvas, sx, sy, width, height, x, y, width, height);
27851 this.cropData = canvas.toDataURL(this.cropType);
27853 if(this.fireEvent('crop', this, this.cropData) !== false){
27854 this.process(this.file, this.cropData);
27861 setThumbBoxSize : function()
27865 if(this.isDocument && typeof(this.imageEl) != 'undefined'){
27866 width = (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? Math.max(this.minWidth, this.minHeight) : Math.min(this.minWidth, this.minHeight);
27867 height = (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? Math.min(this.minWidth, this.minHeight) : Math.max(this.minWidth, this.minHeight);
27869 this.minWidth = width;
27870 this.minHeight = height;
27872 if(this.rotate == 90 || this.rotate == 270){
27873 this.minWidth = height;
27874 this.minHeight = width;
27879 width = Math.ceil(this.minWidth * height / this.minHeight);
27881 if(this.minWidth > this.minHeight){
27883 height = Math.ceil(this.minHeight * width / this.minWidth);
27886 this.thumbEl.setStyle({
27887 width : width + 'px',
27888 height : height + 'px'
27895 setThumbBoxPosition : function()
27897 var x = Math.ceil((this.bodyEl.getWidth() - this.thumbEl.getWidth()) / 2 );
27898 var y = Math.ceil((this.bodyEl.getHeight() - this.thumbEl.getHeight()) / 2);
27900 this.thumbEl.setLeft(x);
27901 this.thumbEl.setTop(y);
27905 baseRotateLevel : function()
27907 this.baseRotate = 1;
27910 typeof(this.exif) != 'undefined' &&
27911 typeof(this.exif[Roo.bootstrap.UploadCropbox['tags']['Orientation']]) != 'undefined' &&
27912 [1, 3, 6, 8].indexOf(this.exif[Roo.bootstrap.UploadCropbox['tags']['Orientation']]) != -1
27914 this.baseRotate = this.exif[Roo.bootstrap.UploadCropbox['tags']['Orientation']];
27917 this.rotate = Roo.bootstrap.UploadCropbox['Orientation'][this.baseRotate];
27921 baseScaleLevel : function()
27925 if(this.isDocument){
27927 if(this.baseRotate == 6 || this.baseRotate == 8){
27929 height = this.thumbEl.getHeight();
27930 this.baseScale = height / this.imageEl.OriginWidth;
27932 if(this.imageEl.OriginHeight * this.baseScale > this.thumbEl.getWidth()){
27933 width = this.thumbEl.getWidth();
27934 this.baseScale = width / this.imageEl.OriginHeight;
27940 height = this.thumbEl.getHeight();
27941 this.baseScale = height / this.imageEl.OriginHeight;
27943 if(this.imageEl.OriginWidth * this.baseScale > this.thumbEl.getWidth()){
27944 width = this.thumbEl.getWidth();
27945 this.baseScale = width / this.imageEl.OriginWidth;
27951 if(this.baseRotate == 6 || this.baseRotate == 8){
27953 width = this.thumbEl.getHeight();
27954 this.baseScale = width / this.imageEl.OriginHeight;
27956 if(this.imageEl.OriginHeight * this.baseScale < this.thumbEl.getWidth()){
27957 height = this.thumbEl.getWidth();
27958 this.baseScale = height / this.imageEl.OriginHeight;
27961 if(this.imageEl.OriginWidth > this.imageEl.OriginHeight){
27962 height = this.thumbEl.getWidth();
27963 this.baseScale = height / this.imageEl.OriginHeight;
27965 if(this.imageEl.OriginWidth * this.baseScale < this.thumbEl.getHeight()){
27966 width = this.thumbEl.getHeight();
27967 this.baseScale = width / this.imageEl.OriginWidth;
27974 width = this.thumbEl.getWidth();
27975 this.baseScale = width / this.imageEl.OriginWidth;
27977 if(this.imageEl.OriginHeight * this.baseScale < this.thumbEl.getHeight()){
27978 height = this.thumbEl.getHeight();
27979 this.baseScale = height / this.imageEl.OriginHeight;
27982 if(this.imageEl.OriginWidth > this.imageEl.OriginHeight){
27984 height = this.thumbEl.getHeight();
27985 this.baseScale = height / this.imageEl.OriginHeight;
27987 if(this.imageEl.OriginWidth * this.baseScale < this.thumbEl.getWidth()){
27988 width = this.thumbEl.getWidth();
27989 this.baseScale = width / this.imageEl.OriginWidth;
27997 getScaleLevel : function()
27999 return this.baseScale * Math.pow(1.1, this.scale);
28002 onTouchStart : function(e)
28004 if(!this.canvasLoaded){
28005 this.beforeSelectFile(e);
28009 var touches = e.browserEvent.touches;
28015 if(touches.length == 1){
28016 this.onMouseDown(e);
28020 if(touches.length != 2){
28026 for(var i = 0, finger; finger = touches[i]; i++){
28027 coords.push(finger.pageX, finger.pageY);
28030 var x = Math.pow(coords[0] - coords[2], 2);
28031 var y = Math.pow(coords[1] - coords[3], 2);
28033 this.startDistance = Math.sqrt(x + y);
28035 this.startScale = this.scale;
28037 this.pinching = true;
28038 this.dragable = false;
28042 onTouchMove : function(e)
28044 if(!this.pinching && !this.dragable){
28048 var touches = e.browserEvent.touches;
28055 this.onMouseMove(e);
28061 for(var i = 0, finger; finger = touches[i]; i++){
28062 coords.push(finger.pageX, finger.pageY);
28065 var x = Math.pow(coords[0] - coords[2], 2);
28066 var y = Math.pow(coords[1] - coords[3], 2);
28068 this.endDistance = Math.sqrt(x + y);
28070 this.scale = this.startScale + Math.floor(Math.log(this.endDistance / this.startDistance) / Math.log(1.1));
28072 if(!this.zoomable()){
28073 this.scale = this.startScale;
28081 onTouchEnd : function(e)
28083 this.pinching = false;
28084 this.dragable = false;
28088 process : function(file, crop)
28091 this.maskEl.mask(this.loadingText);
28094 this.xhr = new XMLHttpRequest();
28096 file.xhr = this.xhr;
28098 this.xhr.open(this.method, this.url, true);
28101 "Accept": "application/json",
28102 "Cache-Control": "no-cache",
28103 "X-Requested-With": "XMLHttpRequest"
28106 for (var headerName in headers) {
28107 var headerValue = headers[headerName];
28109 this.xhr.setRequestHeader(headerName, headerValue);
28115 this.xhr.onload = function()
28117 _this.xhrOnLoad(_this.xhr);
28120 this.xhr.onerror = function()
28122 _this.xhrOnError(_this.xhr);
28125 var formData = new FormData();
28127 formData.append('returnHTML', 'NO');
28130 formData.append('crop', crop);
28133 if(typeof(file) != 'undefined' && (typeof(file.id) == 'undefined' || file.id * 1 < 1)){
28134 formData.append(this.paramName, file, file.name);
28137 if(typeof(file.filename) != 'undefined'){
28138 formData.append('filename', file.filename);
28141 if(typeof(file.mimetype) != 'undefined'){
28142 formData.append('mimetype', file.mimetype);
28145 if(this.fireEvent('arrange', this, formData) != false){
28146 this.xhr.send(formData);
28150 xhrOnLoad : function(xhr)
28153 this.maskEl.unmask();
28156 if (xhr.readyState !== 4) {
28157 this.fireEvent('exception', this, xhr);
28161 var response = Roo.decode(xhr.responseText);
28163 if(!response.success){
28164 this.fireEvent('exception', this, xhr);
28168 var response = Roo.decode(xhr.responseText);
28170 this.fireEvent('upload', this, response);
28174 xhrOnError : function()
28177 this.maskEl.unmask();
28180 Roo.log('xhr on error');
28182 var response = Roo.decode(xhr.responseText);
28188 prepare : function(file)
28191 this.maskEl.mask(this.loadingText);
28197 if(typeof(file) === 'string'){
28198 this.loadCanvas(file);
28202 if(!file || !this.urlAPI){
28207 this.cropType = file.type;
28211 if(this.fireEvent('prepare', this, this.file) != false){
28213 var reader = new FileReader();
28215 reader.onload = function (e) {
28216 if (e.target.error) {
28217 Roo.log(e.target.error);
28221 var buffer = e.target.result,
28222 dataView = new DataView(buffer),
28224 maxOffset = dataView.byteLength - 4,
28228 if (dataView.getUint16(0) === 0xffd8) {
28229 while (offset < maxOffset) {
28230 markerBytes = dataView.getUint16(offset);
28232 if ((markerBytes >= 0xffe0 && markerBytes <= 0xffef) || markerBytes === 0xfffe) {
28233 markerLength = dataView.getUint16(offset + 2) + 2;
28234 if (offset + markerLength > dataView.byteLength) {
28235 Roo.log('Invalid meta data: Invalid segment size.');
28239 if(markerBytes == 0xffe1){
28240 _this.parseExifData(
28247 offset += markerLength;
28257 var url = _this.urlAPI.createObjectURL(_this.file);
28259 _this.loadCanvas(url);
28264 reader.readAsArrayBuffer(this.file);
28270 parseExifData : function(dataView, offset, length)
28272 var tiffOffset = offset + 10,
28276 if (dataView.getUint32(offset + 4) !== 0x45786966) {
28277 // No Exif data, might be XMP data instead
28281 // Check for the ASCII code for "Exif" (0x45786966):
28282 if (dataView.getUint32(offset + 4) !== 0x45786966) {
28283 // No Exif data, might be XMP data instead
28286 if (tiffOffset + 8 > dataView.byteLength) {
28287 Roo.log('Invalid Exif data: Invalid segment size.');
28290 // Check for the two null bytes:
28291 if (dataView.getUint16(offset + 8) !== 0x0000) {
28292 Roo.log('Invalid Exif data: Missing byte alignment offset.');
28295 // Check the byte alignment:
28296 switch (dataView.getUint16(tiffOffset)) {
28298 littleEndian = true;
28301 littleEndian = false;
28304 Roo.log('Invalid Exif data: Invalid byte alignment marker.');
28307 // Check for the TIFF tag marker (0x002A):
28308 if (dataView.getUint16(tiffOffset + 2, littleEndian) !== 0x002A) {
28309 Roo.log('Invalid Exif data: Missing TIFF marker.');
28312 // Retrieve the directory offset bytes, usually 0x00000008 or 8 decimal:
28313 dirOffset = dataView.getUint32(tiffOffset + 4, littleEndian);
28315 this.parseExifTags(
28318 tiffOffset + dirOffset,
28323 parseExifTags : function(dataView, tiffOffset, dirOffset, littleEndian)
28328 if (dirOffset + 6 > dataView.byteLength) {
28329 Roo.log('Invalid Exif data: Invalid directory offset.');
28332 tagsNumber = dataView.getUint16(dirOffset, littleEndian);
28333 dirEndOffset = dirOffset + 2 + 12 * tagsNumber;
28334 if (dirEndOffset + 4 > dataView.byteLength) {
28335 Roo.log('Invalid Exif data: Invalid directory size.');
28338 for (i = 0; i < tagsNumber; i += 1) {
28342 dirOffset + 2 + 12 * i, // tag offset
28346 // Return the offset to the next directory:
28347 return dataView.getUint32(dirEndOffset, littleEndian);
28350 parseExifTag : function (dataView, tiffOffset, offset, littleEndian)
28352 var tag = dataView.getUint16(offset, littleEndian);
28354 this.exif[tag] = this.getExifValue(
28358 dataView.getUint16(offset + 2, littleEndian), // tag type
28359 dataView.getUint32(offset + 4, littleEndian), // tag length
28364 getExifValue : function (dataView, tiffOffset, offset, type, length, littleEndian)
28366 var tagType = Roo.bootstrap.UploadCropbox.exifTagTypes[type],
28375 Roo.log('Invalid Exif data: Invalid tag type.');
28379 tagSize = tagType.size * length;
28380 // Determine if the value is contained in the dataOffset bytes,
28381 // or if the value at the dataOffset is a pointer to the actual data:
28382 dataOffset = tagSize > 4 ?
28383 tiffOffset + dataView.getUint32(offset + 8, littleEndian) : (offset + 8);
28384 if (dataOffset + tagSize > dataView.byteLength) {
28385 Roo.log('Invalid Exif data: Invalid data offset.');
28388 if (length === 1) {
28389 return tagType.getValue(dataView, dataOffset, littleEndian);
28392 for (i = 0; i < length; i += 1) {
28393 values[i] = tagType.getValue(dataView, dataOffset + i * tagType.size, littleEndian);
28396 if (tagType.ascii) {
28398 // Concatenate the chars:
28399 for (i = 0; i < values.length; i += 1) {
28401 // Ignore the terminating NULL byte(s):
28402 if (c === '\u0000') {
28414 Roo.apply(Roo.bootstrap.UploadCropbox, {
28416 'Orientation': 0x0112
28420 1: 0, //'top-left',
28422 3: 180, //'bottom-right',
28423 // 4: 'bottom-left',
28425 6: 90, //'right-top',
28426 // 7: 'right-bottom',
28427 8: 270 //'left-bottom'
28431 // byte, 8-bit unsigned int:
28433 getValue: function (dataView, dataOffset) {
28434 return dataView.getUint8(dataOffset);
28438 // ascii, 8-bit byte:
28440 getValue: function (dataView, dataOffset) {
28441 return String.fromCharCode(dataView.getUint8(dataOffset));
28446 // short, 16 bit int:
28448 getValue: function (dataView, dataOffset, littleEndian) {
28449 return dataView.getUint16(dataOffset, littleEndian);
28453 // long, 32 bit int:
28455 getValue: function (dataView, dataOffset, littleEndian) {
28456 return dataView.getUint32(dataOffset, littleEndian);
28460 // rational = two long values, first is numerator, second is denominator:
28462 getValue: function (dataView, dataOffset, littleEndian) {
28463 return dataView.getUint32(dataOffset, littleEndian) /
28464 dataView.getUint32(dataOffset + 4, littleEndian);
28468 // slong, 32 bit signed int:
28470 getValue: function (dataView, dataOffset, littleEndian) {
28471 return dataView.getInt32(dataOffset, littleEndian);
28475 // srational, two slongs, first is numerator, second is denominator:
28477 getValue: function (dataView, dataOffset, littleEndian) {
28478 return dataView.getInt32(dataOffset, littleEndian) /
28479 dataView.getInt32(dataOffset + 4, littleEndian);
28489 cls : 'btn-group roo-upload-cropbox-rotate-left',
28490 action : 'rotate-left',
28494 cls : 'btn btn-default',
28495 html : '<i class="fa fa-undo"></i>'
28501 cls : 'btn-group roo-upload-cropbox-picture',
28502 action : 'picture',
28506 cls : 'btn btn-default',
28507 html : '<i class="fa fa-picture-o"></i>'
28513 cls : 'btn-group roo-upload-cropbox-rotate-right',
28514 action : 'rotate-right',
28518 cls : 'btn btn-default',
28519 html : '<i class="fa fa-repeat"></i>'
28527 cls : 'btn-group roo-upload-cropbox-rotate-left',
28528 action : 'rotate-left',
28532 cls : 'btn btn-default',
28533 html : '<i class="fa fa-undo"></i>'
28539 cls : 'btn-group roo-upload-cropbox-download',
28540 action : 'download',
28544 cls : 'btn btn-default',
28545 html : '<i class="fa fa-download"></i>'
28551 cls : 'btn-group roo-upload-cropbox-crop',
28556 cls : 'btn btn-default',
28557 html : '<i class="fa fa-crop"></i>'
28563 cls : 'btn-group roo-upload-cropbox-trash',
28568 cls : 'btn btn-default',
28569 html : '<i class="fa fa-trash"></i>'
28575 cls : 'btn-group roo-upload-cropbox-rotate-right',
28576 action : 'rotate-right',
28580 cls : 'btn btn-default',
28581 html : '<i class="fa fa-repeat"></i>'
28589 cls : 'btn-group roo-upload-cropbox-rotate-left',
28590 action : 'rotate-left',
28594 cls : 'btn btn-default',
28595 html : '<i class="fa fa-undo"></i>'
28601 cls : 'btn-group roo-upload-cropbox-rotate-right',
28602 action : 'rotate-right',
28606 cls : 'btn btn-default',
28607 html : '<i class="fa fa-repeat"></i>'
28620 * @class Roo.bootstrap.DocumentManager
28621 * @extends Roo.bootstrap.Component
28622 * Bootstrap DocumentManager class
28623 * @cfg {String} paramName default 'imageUpload'
28624 * @cfg {String} toolTipName default 'filename'
28625 * @cfg {String} method default POST
28626 * @cfg {String} url action url
28627 * @cfg {Number} boxes number of boxes, 0 is no limit.. default 0
28628 * @cfg {Boolean} multiple multiple upload default true
28629 * @cfg {Number} thumbSize default 300
28630 * @cfg {String} fieldLabel
28631 * @cfg {Number} labelWidth default 4
28632 * @cfg {String} labelAlign (left|top) default left
28633 * @cfg {Boolean} editable (true|false) allow edit when upload a image default true
28634 * @cfg {Number} labellg set the width of label (1-12)
28635 * @cfg {Number} labelmd set the width of label (1-12)
28636 * @cfg {Number} labelsm set the width of label (1-12)
28637 * @cfg {Number} labelxs set the width of label (1-12)
28640 * Create a new DocumentManager
28641 * @param {Object} config The config object
28644 Roo.bootstrap.DocumentManager = function(config){
28645 Roo.bootstrap.DocumentManager.superclass.constructor.call(this, config);
28648 this.delegates = [];
28653 * Fire when initial the DocumentManager
28654 * @param {Roo.bootstrap.DocumentManager} this
28659 * inspect selected file
28660 * @param {Roo.bootstrap.DocumentManager} this
28661 * @param {File} file
28666 * Fire when xhr load exception
28667 * @param {Roo.bootstrap.DocumentManager} this
28668 * @param {XMLHttpRequest} xhr
28670 "exception" : true,
28672 * @event afterupload
28673 * Fire when xhr load exception
28674 * @param {Roo.bootstrap.DocumentManager} this
28675 * @param {XMLHttpRequest} xhr
28677 "afterupload" : true,
28680 * prepare the form data
28681 * @param {Roo.bootstrap.DocumentManager} this
28682 * @param {Object} formData
28687 * Fire when remove the file
28688 * @param {Roo.bootstrap.DocumentManager} this
28689 * @param {Object} file
28694 * Fire after refresh the file
28695 * @param {Roo.bootstrap.DocumentManager} this
28700 * Fire after click the image
28701 * @param {Roo.bootstrap.DocumentManager} this
28702 * @param {Object} file
28707 * Fire when upload a image and editable set to true
28708 * @param {Roo.bootstrap.DocumentManager} this
28709 * @param {Object} file
28713 * @event beforeselectfile
28714 * Fire before select file
28715 * @param {Roo.bootstrap.DocumentManager} this
28717 "beforeselectfile" : true,
28720 * Fire before process file
28721 * @param {Roo.bootstrap.DocumentManager} this
28722 * @param {Object} file
28726 * @event previewrendered
28727 * Fire when preview rendered
28728 * @param {Roo.bootstrap.DocumentManager} this
28729 * @param {Object} file
28731 "previewrendered" : true,
28734 "previewResize" : true
28739 Roo.extend(Roo.bootstrap.DocumentManager, Roo.bootstrap.Component, {
28748 paramName : 'imageUpload',
28749 toolTipName : 'filename',
28752 labelAlign : 'left',
28762 getAutoCreate : function()
28764 var managerWidget = {
28766 cls : 'roo-document-manager',
28770 cls : 'roo-document-manager-selector',
28775 cls : 'roo-document-manager-uploader',
28779 cls : 'roo-document-manager-upload-btn',
28780 html : '<i class="fa fa-plus"></i>'
28791 cls : 'column col-md-12',
28796 if(this.fieldLabel.length){
28801 cls : 'column col-md-12',
28802 html : this.fieldLabel
28806 cls : 'column col-md-12',
28811 if(this.labelAlign == 'left'){
28816 html : this.fieldLabel
28825 if(this.labelWidth > 12){
28826 content[0].style = "width: " + this.labelWidth + 'px';
28829 if(this.labelWidth < 13 && this.labelmd == 0){
28830 this.labelmd = this.labelWidth;
28833 if(this.labellg > 0){
28834 content[0].cls += ' col-lg-' + this.labellg;
28835 content[1].cls += ' col-lg-' + (12 - this.labellg);
28838 if(this.labelmd > 0){
28839 content[0].cls += ' col-md-' + this.labelmd;
28840 content[1].cls += ' col-md-' + (12 - this.labelmd);
28843 if(this.labelsm > 0){
28844 content[0].cls += ' col-sm-' + this.labelsm;
28845 content[1].cls += ' col-sm-' + (12 - this.labelsm);
28848 if(this.labelxs > 0){
28849 content[0].cls += ' col-xs-' + this.labelxs;
28850 content[1].cls += ' col-xs-' + (12 - this.labelxs);
28858 cls : 'row clearfix',
28866 initEvents : function()
28868 this.managerEl = this.el.select('.roo-document-manager', true).first();
28869 this.managerEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
28871 this.selectorEl = this.el.select('.roo-document-manager-selector', true).first();
28872 this.selectorEl.hide();
28875 this.selectorEl.attr('multiple', 'multiple');
28878 this.selectorEl.on('change', this.onFileSelected, this);
28880 this.uploader = this.el.select('.roo-document-manager-uploader', true).first();
28881 this.uploader.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
28883 this.uploader.on('click', this.onUploaderClick, this);
28885 this.renderProgressDialog();
28889 window.addEventListener("resize", function() { _this.refresh(); } );
28891 this.fireEvent('initial', this);
28894 renderProgressDialog : function()
28898 this.progressDialog = new Roo.bootstrap.Modal({
28899 cls : 'roo-document-manager-progress-dialog',
28900 allow_close : false,
28910 btnclick : function() {
28911 _this.uploadCancel();
28917 this.progressDialog.render(Roo.get(document.body));
28919 this.progress = new Roo.bootstrap.Progress({
28920 cls : 'roo-document-manager-progress',
28925 this.progress.render(this.progressDialog.getChildContainer());
28927 this.progressBar = new Roo.bootstrap.ProgressBar({
28928 cls : 'roo-document-manager-progress-bar',
28931 aria_valuemax : 12,
28935 this.progressBar.render(this.progress.getChildContainer());
28938 onUploaderClick : function(e)
28940 e.preventDefault();
28942 if(this.fireEvent('beforeselectfile', this) != false){
28943 this.selectorEl.dom.click();
28948 onFileSelected : function(e)
28950 e.preventDefault();
28952 if(typeof(this.selectorEl.dom.files) == 'undefined' || !this.selectorEl.dom.files.length){
28956 Roo.each(this.selectorEl.dom.files, function(file){
28957 if(this.fireEvent('inspect', this, file) != false){
28958 this.files.push(file);
28968 this.selectorEl.dom.value = '';
28970 if(!this.files || !this.files.length){
28974 if(this.boxes > 0 && this.files.length > this.boxes){
28975 this.files = this.files.slice(0, this.boxes);
28978 this.uploader.show();
28980 if(this.boxes > 0 && this.files.length > this.boxes - 1){
28981 this.uploader.hide();
28990 Roo.each(this.files, function(file){
28992 if(typeof(file.id) != 'undefined' && file.id * 1 > 0){
28993 var f = this.renderPreview(file);
28998 if(file.type.indexOf('image') != -1){
28999 this.delegates.push(
29001 _this.process(file);
29002 }).createDelegate(this)
29010 _this.process(file);
29011 }).createDelegate(this)
29016 this.files = files;
29018 this.delegates = this.delegates.concat(docs);
29020 if(!this.delegates.length){
29025 this.progressBar.aria_valuemax = this.delegates.length;
29032 arrange : function()
29034 if(!this.delegates.length){
29035 this.progressDialog.hide();
29040 var delegate = this.delegates.shift();
29042 this.progressDialog.show();
29044 this.progressDialog.setTitle((this.progressBar.aria_valuemax - this.delegates.length) + ' / ' + this.progressBar.aria_valuemax);
29046 this.progressBar.update(this.progressBar.aria_valuemax - this.delegates.length);
29051 refresh : function()
29053 this.uploader.show();
29055 if(this.boxes > 0 && this.files.length > this.boxes - 1){
29056 this.uploader.hide();
29059 Roo.isTouch ? this.closable(false) : this.closable(true);
29061 this.fireEvent('refresh', this);
29064 onRemove : function(e, el, o)
29066 e.preventDefault();
29068 this.fireEvent('remove', this, o);
29072 remove : function(o)
29076 Roo.each(this.files, function(file){
29077 if(typeof(file.id) == 'undefined' || file.id * 1 < 1 || file.id != o.id){
29086 this.files = files;
29093 Roo.each(this.files, function(file){
29098 file.target.remove();
29107 onClick : function(e, el, o)
29109 e.preventDefault();
29111 this.fireEvent('click', this, o);
29115 closable : function(closable)
29117 Roo.each(this.managerEl.select('.roo-document-manager-preview > button.close', true).elements, function(el){
29119 el.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
29131 xhrOnLoad : function(xhr)
29133 Roo.each(this.managerEl.select('.roo-document-manager-loading', true).elements, function(el){
29137 if (xhr.readyState !== 4) {
29139 this.fireEvent('exception', this, xhr);
29143 var response = Roo.decode(xhr.responseText);
29145 if(!response.success){
29147 this.fireEvent('exception', this, xhr);
29151 var file = this.renderPreview(response.data);
29153 this.files.push(file);
29157 this.fireEvent('afterupload', this, xhr);
29161 xhrOnError : function(xhr)
29163 Roo.log('xhr on error');
29165 var response = Roo.decode(xhr.responseText);
29172 process : function(file)
29174 if(this.fireEvent('process', this, file) !== false){
29175 if(this.editable && file.type.indexOf('image') != -1){
29176 this.fireEvent('edit', this, file);
29180 this.uploadStart(file, false);
29187 uploadStart : function(file, crop)
29189 this.xhr = new XMLHttpRequest();
29191 if(typeof(file.id) != 'undefined' && file.id * 1 > 0){
29196 file.xhr = this.xhr;
29198 this.managerEl.createChild({
29200 cls : 'roo-document-manager-loading',
29204 tooltip : file.name,
29205 cls : 'roo-document-manager-thumb',
29206 html : '<i class="fa fa-circle-o-notch fa-spin"></i>'
29212 this.xhr.open(this.method, this.url, true);
29215 "Accept": "application/json",
29216 "Cache-Control": "no-cache",
29217 "X-Requested-With": "XMLHttpRequest"
29220 for (var headerName in headers) {
29221 var headerValue = headers[headerName];
29223 this.xhr.setRequestHeader(headerName, headerValue);
29229 this.xhr.onload = function()
29231 _this.xhrOnLoad(_this.xhr);
29234 this.xhr.onerror = function()
29236 _this.xhrOnError(_this.xhr);
29239 var formData = new FormData();
29241 formData.append('returnHTML', 'NO');
29244 formData.append('crop', crop);
29247 formData.append(this.paramName, file, file.name);
29254 if(this.fireEvent('prepare', this, formData, options) != false){
29256 if(options.manually){
29260 this.xhr.send(formData);
29264 this.uploadCancel();
29267 uploadCancel : function()
29273 this.delegates = [];
29275 Roo.each(this.managerEl.select('.roo-document-manager-loading', true).elements, function(el){
29282 renderPreview : function(file)
29284 if(typeof(file.target) != 'undefined' && file.target){
29288 var img_src = encodeURI(baseURL +'/Images/Thumb/' + this.thumbSize + '/' + file.id + '/' + file.filename);
29290 var previewEl = this.managerEl.createChild({
29292 cls : 'roo-document-manager-preview',
29296 tooltip : file[this.toolTipName],
29297 cls : 'roo-document-manager-thumb',
29298 html : '<img tooltip="' + file[this.toolTipName] + '" src="' + img_src + '">'
29303 html : '<i class="fa fa-times-circle"></i>'
29308 var close = previewEl.select('button.close', true).first();
29310 close.on('click', this.onRemove, this, file);
29312 file.target = previewEl;
29314 var image = previewEl.select('img', true).first();
29318 image.dom.addEventListener("load", function(){ _this.onPreviewLoad(file, image); });
29320 image.on('click', this.onClick, this, file);
29322 this.fireEvent('previewrendered', this, file);
29328 onPreviewLoad : function(file, image)
29330 if(typeof(file.target) == 'undefined' || !file.target){
29334 var width = image.dom.naturalWidth || image.dom.width;
29335 var height = image.dom.naturalHeight || image.dom.height;
29337 if(!this.previewResize) {
29341 if(width > height){
29342 file.target.addClass('wide');
29346 file.target.addClass('tall');
29351 uploadFromSource : function(file, crop)
29353 this.xhr = new XMLHttpRequest();
29355 this.managerEl.createChild({
29357 cls : 'roo-document-manager-loading',
29361 tooltip : file.name,
29362 cls : 'roo-document-manager-thumb',
29363 html : '<i class="fa fa-circle-o-notch fa-spin"></i>'
29369 this.xhr.open(this.method, this.url, true);
29372 "Accept": "application/json",
29373 "Cache-Control": "no-cache",
29374 "X-Requested-With": "XMLHttpRequest"
29377 for (var headerName in headers) {
29378 var headerValue = headers[headerName];
29380 this.xhr.setRequestHeader(headerName, headerValue);
29386 this.xhr.onload = function()
29388 _this.xhrOnLoad(_this.xhr);
29391 this.xhr.onerror = function()
29393 _this.xhrOnError(_this.xhr);
29396 var formData = new FormData();
29398 formData.append('returnHTML', 'NO');
29400 formData.append('crop', crop);
29402 if(typeof(file.filename) != 'undefined'){
29403 formData.append('filename', file.filename);
29406 if(typeof(file.mimetype) != 'undefined'){
29407 formData.append('mimetype', file.mimetype);
29412 if(this.fireEvent('prepare', this, formData) != false){
29413 this.xhr.send(formData);
29423 * @class Roo.bootstrap.DocumentViewer
29424 * @extends Roo.bootstrap.Component
29425 * Bootstrap DocumentViewer class
29426 * @cfg {Boolean} showDownload (true|false) show download button (default true)
29427 * @cfg {Boolean} showTrash (true|false) show trash button (default true)
29430 * Create a new DocumentViewer
29431 * @param {Object} config The config object
29434 Roo.bootstrap.DocumentViewer = function(config){
29435 Roo.bootstrap.DocumentViewer.superclass.constructor.call(this, config);
29440 * Fire after initEvent
29441 * @param {Roo.bootstrap.DocumentViewer} this
29447 * @param {Roo.bootstrap.DocumentViewer} this
29452 * Fire after download button
29453 * @param {Roo.bootstrap.DocumentViewer} this
29458 * Fire after trash button
29459 * @param {Roo.bootstrap.DocumentViewer} this
29466 Roo.extend(Roo.bootstrap.DocumentViewer, Roo.bootstrap.Component, {
29468 showDownload : true,
29472 getAutoCreate : function()
29476 cls : 'roo-document-viewer',
29480 cls : 'roo-document-viewer-body',
29484 cls : 'roo-document-viewer-thumb',
29488 cls : 'roo-document-viewer-image'
29496 cls : 'roo-document-viewer-footer',
29499 cls : 'btn-group btn-group-justified roo-document-viewer-btn-group',
29503 cls : 'btn-group roo-document-viewer-download',
29507 cls : 'btn btn-default',
29508 html : '<i class="fa fa-download"></i>'
29514 cls : 'btn-group roo-document-viewer-trash',
29518 cls : 'btn btn-default',
29519 html : '<i class="fa fa-trash"></i>'
29532 initEvents : function()
29534 this.bodyEl = this.el.select('.roo-document-viewer-body', true).first();
29535 this.bodyEl.setVisibilityMode(Roo.Element.DISPLAY);
29537 this.thumbEl = this.el.select('.roo-document-viewer-thumb', true).first();
29538 this.thumbEl.setVisibilityMode(Roo.Element.DISPLAY);
29540 this.imageEl = this.el.select('.roo-document-viewer-image', true).first();
29541 this.imageEl.setVisibilityMode(Roo.Element.DISPLAY);
29543 this.footerEl = this.el.select('.roo-document-viewer-footer', true).first();
29544 this.footerEl.setVisibilityMode(Roo.Element.DISPLAY);
29546 this.downloadBtn = this.el.select('.roo-document-viewer-download', true).first();
29547 this.downloadBtn.setVisibilityMode(Roo.Element.DISPLAY);
29549 this.trashBtn = this.el.select('.roo-document-viewer-trash', true).first();
29550 this.trashBtn.setVisibilityMode(Roo.Element.DISPLAY);
29552 this.bodyEl.on('click', this.onClick, this);
29553 this.downloadBtn.on('click', this.onDownload, this);
29554 this.trashBtn.on('click', this.onTrash, this);
29556 this.downloadBtn.hide();
29557 this.trashBtn.hide();
29559 if(this.showDownload){
29560 this.downloadBtn.show();
29563 if(this.showTrash){
29564 this.trashBtn.show();
29567 if(!this.showDownload && !this.showTrash) {
29568 this.footerEl.hide();
29573 initial : function()
29575 this.fireEvent('initial', this);
29579 onClick : function(e)
29581 e.preventDefault();
29583 this.fireEvent('click', this);
29586 onDownload : function(e)
29588 e.preventDefault();
29590 this.fireEvent('download', this);
29593 onTrash : function(e)
29595 e.preventDefault();
29597 this.fireEvent('trash', this);
29609 * @class Roo.bootstrap.NavProgressBar
29610 * @extends Roo.bootstrap.Component
29611 * Bootstrap NavProgressBar class
29614 * Create a new nav progress bar
29615 * @param {Object} config The config object
29618 Roo.bootstrap.NavProgressBar = function(config){
29619 Roo.bootstrap.NavProgressBar.superclass.constructor.call(this, config);
29621 this.bullets = this.bullets || [];
29623 // Roo.bootstrap.NavProgressBar.register(this);
29627 * Fires when the active item changes
29628 * @param {Roo.bootstrap.NavProgressBar} this
29629 * @param {Roo.bootstrap.NavProgressItem} selected The item selected
29630 * @param {Roo.bootstrap.NavProgressItem} prev The previously selected item
29637 Roo.extend(Roo.bootstrap.NavProgressBar, Roo.bootstrap.Component, {
29642 getAutoCreate : function()
29644 var cfg = Roo.apply({}, Roo.bootstrap.NavProgressBar.superclass.getAutoCreate.call(this));
29648 cls : 'roo-navigation-bar-group',
29652 cls : 'roo-navigation-top-bar'
29656 cls : 'roo-navigation-bullets-bar',
29660 cls : 'roo-navigation-bar'
29667 cls : 'roo-navigation-bottom-bar'
29677 initEvents: function()
29682 onRender : function(ct, position)
29684 Roo.bootstrap.NavProgressBar.superclass.onRender.call(this, ct, position);
29686 if(this.bullets.length){
29687 Roo.each(this.bullets, function(b){
29696 addItem : function(cfg)
29698 var item = new Roo.bootstrap.NavProgressItem(cfg);
29700 item.parentId = this.id;
29701 item.render(this.el.select('.roo-navigation-bar', true).first(), null);
29704 var top = new Roo.bootstrap.Element({
29706 cls : 'roo-navigation-bar-text'
29709 var bottom = new Roo.bootstrap.Element({
29711 cls : 'roo-navigation-bar-text'
29714 top.onRender(this.el.select('.roo-navigation-top-bar', true).first(), null);
29715 bottom.onRender(this.el.select('.roo-navigation-bottom-bar', true).first(), null);
29717 var topText = new Roo.bootstrap.Element({
29719 html : (typeof(cfg.position) != 'undefined' && cfg.position == 'top') ? cfg.html : ''
29722 var bottomText = new Roo.bootstrap.Element({
29724 html : (typeof(cfg.position) != 'undefined' && cfg.position == 'top') ? '' : cfg.html
29727 topText.onRender(top.el, null);
29728 bottomText.onRender(bottom.el, null);
29731 item.bottomEl = bottom;
29734 this.barItems.push(item);
29739 getActive : function()
29741 var active = false;
29743 Roo.each(this.barItems, function(v){
29745 if (!v.isActive()) {
29757 setActiveItem : function(item)
29761 Roo.each(this.barItems, function(v){
29762 if (v.rid == item.rid) {
29766 if (v.isActive()) {
29767 v.setActive(false);
29772 item.setActive(true);
29774 this.fireEvent('changed', this, item, prev);
29777 getBarItem: function(rid)
29781 Roo.each(this.barItems, function(e) {
29782 if (e.rid != rid) {
29793 indexOfItem : function(item)
29797 Roo.each(this.barItems, function(v, i){
29799 if (v.rid != item.rid) {
29810 setActiveNext : function()
29812 var i = this.indexOfItem(this.getActive());
29814 if (i > this.barItems.length) {
29818 this.setActiveItem(this.barItems[i+1]);
29821 setActivePrev : function()
29823 var i = this.indexOfItem(this.getActive());
29829 this.setActiveItem(this.barItems[i-1]);
29832 format : function()
29834 if(!this.barItems.length){
29838 var width = 100 / this.barItems.length;
29840 Roo.each(this.barItems, function(i){
29841 i.el.setStyle('width', width + '%');
29842 i.topEl.el.setStyle('width', width + '%');
29843 i.bottomEl.el.setStyle('width', width + '%');
29852 * Nav Progress Item
29857 * @class Roo.bootstrap.NavProgressItem
29858 * @extends Roo.bootstrap.Component
29859 * Bootstrap NavProgressItem class
29860 * @cfg {String} rid the reference id
29861 * @cfg {Boolean} active (true|false) Is item active default false
29862 * @cfg {Boolean} disabled (true|false) Is item active default false
29863 * @cfg {String} html
29864 * @cfg {String} position (top|bottom) text position default bottom
29865 * @cfg {String} icon show icon instead of number
29868 * Create a new NavProgressItem
29869 * @param {Object} config The config object
29871 Roo.bootstrap.NavProgressItem = function(config){
29872 Roo.bootstrap.NavProgressItem.superclass.constructor.call(this, config);
29877 * The raw click event for the entire grid.
29878 * @param {Roo.bootstrap.NavProgressItem} this
29879 * @param {Roo.EventObject} e
29886 Roo.extend(Roo.bootstrap.NavProgressItem, Roo.bootstrap.Component, {
29892 position : 'bottom',
29895 getAutoCreate : function()
29897 var iconCls = 'roo-navigation-bar-item-icon';
29899 iconCls += ((this.icon) ? (' ' + this.icon) : (' step-number')) ;
29903 cls: 'roo-navigation-bar-item',
29913 cfg.cls += ' active';
29916 cfg.cls += ' disabled';
29922 disable : function()
29924 this.setDisabled(true);
29927 enable : function()
29929 this.setDisabled(false);
29932 initEvents: function()
29934 this.iconEl = this.el.select('.roo-navigation-bar-item-icon', true).first();
29936 this.iconEl.on('click', this.onClick, this);
29939 onClick : function(e)
29941 e.preventDefault();
29947 if(this.fireEvent('click', this, e) === false){
29951 this.parent().setActiveItem(this);
29954 isActive: function ()
29956 return this.active;
29959 setActive : function(state)
29961 if(this.active == state){
29965 this.active = state;
29968 this.el.addClass('active');
29972 this.el.removeClass('active');
29977 setDisabled : function(state)
29979 if(this.disabled == state){
29983 this.disabled = state;
29986 this.el.addClass('disabled');
29990 this.el.removeClass('disabled');
29993 tooltipEl : function()
29995 return this.el.select('.roo-navigation-bar-item-icon', true).first();;
30008 * @class Roo.bootstrap.FieldLabel
30009 * @extends Roo.bootstrap.Component
30010 * Bootstrap FieldLabel class
30011 * @cfg {String} html contents of the element
30012 * @cfg {String} tag tag of the element default label
30013 * @cfg {String} cls class of the element
30014 * @cfg {String} target label target
30015 * @cfg {Boolean} allowBlank (true|false) target allowBlank default true
30016 * @cfg {String} invalidClass default "text-warning"
30017 * @cfg {String} validClass default "text-success"
30018 * @cfg {String} iconTooltip default "This field is required"
30019 * @cfg {String} indicatorpos (left|right) default left
30022 * Create a new FieldLabel
30023 * @param {Object} config The config object
30026 Roo.bootstrap.FieldLabel = function(config){
30027 Roo.bootstrap.Element.superclass.constructor.call(this, config);
30032 * Fires after the field has been marked as invalid.
30033 * @param {Roo.form.FieldLabel} this
30034 * @param {String} msg The validation message
30039 * Fires after the field has been validated with no errors.
30040 * @param {Roo.form.FieldLabel} this
30046 Roo.extend(Roo.bootstrap.FieldLabel, Roo.bootstrap.Component, {
30053 invalidClass : 'has-warning',
30054 validClass : 'has-success',
30055 iconTooltip : 'This field is required',
30056 indicatorpos : 'left',
30058 getAutoCreate : function(){
30061 if (!this.allowBlank) {
30067 cls : 'roo-bootstrap-field-label ' + this.cls,
30072 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star ' + cls,
30073 tooltip : this.iconTooltip
30082 if(this.indicatorpos == 'right'){
30085 cls : 'roo-bootstrap-field-label ' + this.cls,
30094 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star '+ cls,
30095 tooltip : this.iconTooltip
30104 initEvents: function()
30106 Roo.bootstrap.Element.superclass.initEvents.call(this);
30108 this.indicator = this.indicatorEl();
30110 if(this.indicator){
30111 this.indicator.removeClass('visible');
30112 this.indicator.addClass('invisible');
30115 Roo.bootstrap.FieldLabel.register(this);
30118 indicatorEl : function()
30120 var indicator = this.el.select('i.roo-required-indicator',true).first();
30131 * Mark this field as valid
30133 markValid : function()
30135 if(this.indicator){
30136 this.indicator.removeClass('visible');
30137 this.indicator.addClass('invisible');
30140 this.el.removeClass(this.invalidClass);
30142 this.el.addClass(this.validClass);
30144 this.fireEvent('valid', this);
30148 * Mark this field as invalid
30149 * @param {String} msg The validation message
30151 markInvalid : function(msg)
30153 if(this.indicator){
30154 this.indicator.removeClass('invisible');
30155 this.indicator.addClass('visible');
30158 this.el.removeClass(this.validClass);
30160 this.el.addClass(this.invalidClass);
30162 this.fireEvent('invalid', this, msg);
30168 Roo.apply(Roo.bootstrap.FieldLabel, {
30173 * register a FieldLabel Group
30174 * @param {Roo.bootstrap.FieldLabel} the FieldLabel to add
30176 register : function(label)
30178 if(this.groups.hasOwnProperty(label.target)){
30182 this.groups[label.target] = label;
30186 * fetch a FieldLabel Group based on the target
30187 * @param {string} target
30188 * @returns {Roo.bootstrap.FieldLabel} the CheckBox group
30190 get: function(target) {
30191 if (typeof(this.groups[target]) == 'undefined') {
30195 return this.groups[target] ;
30204 * page DateSplitField.
30210 * @class Roo.bootstrap.DateSplitField
30211 * @extends Roo.bootstrap.Component
30212 * Bootstrap DateSplitField class
30213 * @cfg {string} fieldLabel - the label associated
30214 * @cfg {Number} labelWidth set the width of label (0-12)
30215 * @cfg {String} labelAlign (top|left)
30216 * @cfg {Boolean} dayAllowBlank (true|false) default false
30217 * @cfg {Boolean} monthAllowBlank (true|false) default false
30218 * @cfg {Boolean} yearAllowBlank (true|false) default false
30219 * @cfg {string} dayPlaceholder
30220 * @cfg {string} monthPlaceholder
30221 * @cfg {string} yearPlaceholder
30222 * @cfg {string} dayFormat default 'd'
30223 * @cfg {string} monthFormat default 'm'
30224 * @cfg {string} yearFormat default 'Y'
30225 * @cfg {Number} labellg set the width of label (1-12)
30226 * @cfg {Number} labelmd set the width of label (1-12)
30227 * @cfg {Number} labelsm set the width of label (1-12)
30228 * @cfg {Number} labelxs set the width of label (1-12)
30232 * Create a new DateSplitField
30233 * @param {Object} config The config object
30236 Roo.bootstrap.DateSplitField = function(config){
30237 Roo.bootstrap.DateSplitField.superclass.constructor.call(this, config);
30243 * getting the data of years
30244 * @param {Roo.bootstrap.DateSplitField} this
30245 * @param {Object} years
30250 * getting the data of days
30251 * @param {Roo.bootstrap.DateSplitField} this
30252 * @param {Object} days
30257 * Fires after the field has been marked as invalid.
30258 * @param {Roo.form.Field} this
30259 * @param {String} msg The validation message
30264 * Fires after the field has been validated with no errors.
30265 * @param {Roo.form.Field} this
30271 Roo.extend(Roo.bootstrap.DateSplitField, Roo.bootstrap.Component, {
30274 labelAlign : 'top',
30276 dayAllowBlank : false,
30277 monthAllowBlank : false,
30278 yearAllowBlank : false,
30279 dayPlaceholder : '',
30280 monthPlaceholder : '',
30281 yearPlaceholder : '',
30285 isFormField : true,
30291 getAutoCreate : function()
30295 cls : 'row roo-date-split-field-group',
30300 cls : 'form-hidden-field roo-date-split-field-group-value',
30306 var labelCls = 'col-md-12';
30307 var contentCls = 'col-md-4';
30309 if(this.fieldLabel){
30313 cls : 'column roo-date-split-field-label col-md-' + ((this.labelAlign == 'top') ? '12' : this.labelWidth),
30317 html : this.fieldLabel
30322 if(this.labelAlign == 'left'){
30324 if(this.labelWidth > 12){
30325 label.style = "width: " + this.labelWidth + 'px';
30328 if(this.labelWidth < 13 && this.labelmd == 0){
30329 this.labelmd = this.labelWidth;
30332 if(this.labellg > 0){
30333 labelCls = ' col-lg-' + this.labellg;
30334 contentCls = ' col-lg-' + ((12 - this.labellg) / 3);
30337 if(this.labelmd > 0){
30338 labelCls = ' col-md-' + this.labelmd;
30339 contentCls = ' col-md-' + ((12 - this.labelmd) / 3);
30342 if(this.labelsm > 0){
30343 labelCls = ' col-sm-' + this.labelsm;
30344 contentCls = ' col-sm-' + ((12 - this.labelsm) / 3);
30347 if(this.labelxs > 0){
30348 labelCls = ' col-xs-' + this.labelxs;
30349 contentCls = ' col-xs-' + ((12 - this.labelxs) / 3);
30353 label.cls += ' ' + labelCls;
30355 cfg.cn.push(label);
30358 Roo.each(['day', 'month', 'year'], function(t){
30361 cls : 'column roo-date-split-field-' + t + ' ' + contentCls
30368 inputEl: function ()
30370 return this.el.select('.roo-date-split-field-group-value', true).first();
30373 onRender : function(ct, position)
30377 Roo.bootstrap.NavProgressBar.superclass.onRender.call(this, ct, position);
30379 this.inputEl = this.el.select('.roo-date-split-field-group-value', true).first();
30381 this.dayField = new Roo.bootstrap.ComboBox({
30382 allowBlank : this.dayAllowBlank,
30383 alwaysQuery : true,
30384 displayField : 'value',
30387 forceSelection : true,
30389 placeholder : this.dayPlaceholder,
30390 selectOnFocus : true,
30391 tpl : '<div class="roo-select2-result"><b>{value}</b></div>',
30392 triggerAction : 'all',
30394 valueField : 'value',
30395 store : new Roo.data.SimpleStore({
30396 data : (function() {
30398 _this.fireEvent('days', _this, days);
30401 fields : [ 'value' ]
30404 select : function (_self, record, index)
30406 _this.setValue(_this.getValue());
30411 this.dayField.render(this.el.select('.roo-date-split-field-day', true).first(), null);
30413 this.monthField = new Roo.bootstrap.MonthField({
30414 after : '<i class=\"fa fa-calendar\"></i>',
30415 allowBlank : this.monthAllowBlank,
30416 placeholder : this.monthPlaceholder,
30419 render : function (_self)
30421 this.el.select('span.input-group-addon', true).first().on('click', function(e){
30422 e.preventDefault();
30426 select : function (_self, oldvalue, newvalue)
30428 _this.setValue(_this.getValue());
30433 this.monthField.render(this.el.select('.roo-date-split-field-month', true).first(), null);
30435 this.yearField = new Roo.bootstrap.ComboBox({
30436 allowBlank : this.yearAllowBlank,
30437 alwaysQuery : true,
30438 displayField : 'value',
30441 forceSelection : true,
30443 placeholder : this.yearPlaceholder,
30444 selectOnFocus : true,
30445 tpl : '<div class="roo-select2-result"><b>{value}</b></div>',
30446 triggerAction : 'all',
30448 valueField : 'value',
30449 store : new Roo.data.SimpleStore({
30450 data : (function() {
30452 _this.fireEvent('years', _this, years);
30455 fields : [ 'value' ]
30458 select : function (_self, record, index)
30460 _this.setValue(_this.getValue());
30465 this.yearField.render(this.el.select('.roo-date-split-field-year', true).first(), null);
30468 setValue : function(v, format)
30470 this.inputEl.dom.value = v;
30472 var f = format || (this.yearFormat + '-' + this.monthFormat + '-' + this.dayFormat);
30474 var d = Date.parseDate(v, f);
30481 this.setDay(d.format(this.dayFormat));
30482 this.setMonth(d.format(this.monthFormat));
30483 this.setYear(d.format(this.yearFormat));
30490 setDay : function(v)
30492 this.dayField.setValue(v);
30493 this.inputEl.dom.value = this.getValue();
30498 setMonth : function(v)
30500 this.monthField.setValue(v, true);
30501 this.inputEl.dom.value = this.getValue();
30506 setYear : function(v)
30508 this.yearField.setValue(v);
30509 this.inputEl.dom.value = this.getValue();
30514 getDay : function()
30516 return this.dayField.getValue();
30519 getMonth : function()
30521 return this.monthField.getValue();
30524 getYear : function()
30526 return this.yearField.getValue();
30529 getValue : function()
30531 var f = this.yearFormat + '-' + this.monthFormat + '-' + this.dayFormat;
30533 var date = this.yearField.getValue() + '-' + this.monthField.getValue() + '-' + this.dayField.getValue();
30543 this.inputEl.dom.value = '';
30548 validate : function()
30550 var d = this.dayField.validate();
30551 var m = this.monthField.validate();
30552 var y = this.yearField.validate();
30557 (!this.dayAllowBlank && !d) ||
30558 (!this.monthAllowBlank && !m) ||
30559 (!this.yearAllowBlank && !y)
30564 if(this.dayAllowBlank && this.monthAllowBlank && this.yearAllowBlank){
30573 this.markInvalid();
30578 markValid : function()
30581 var label = this.el.select('label', true).first();
30582 var icon = this.el.select('i.fa-star', true).first();
30588 this.fireEvent('valid', this);
30592 * Mark this field as invalid
30593 * @param {String} msg The validation message
30595 markInvalid : function(msg)
30598 var label = this.el.select('label', true).first();
30599 var icon = this.el.select('i.fa-star', true).first();
30601 if(label && !icon){
30602 this.el.select('.roo-date-split-field-label', true).createChild({
30604 cls : 'text-danger fa fa-lg fa-star',
30605 tooltip : 'This field is required',
30606 style : 'margin-right:5px;'
30610 this.fireEvent('invalid', this, msg);
30613 clearInvalid : function()
30615 var label = this.el.select('label', true).first();
30616 var icon = this.el.select('i.fa-star', true).first();
30622 this.fireEvent('valid', this);
30625 getName: function()
30635 * http://masonry.desandro.com
30637 * The idea is to render all the bricks based on vertical width...
30639 * The original code extends 'outlayer' - we might need to use that....
30645 * @class Roo.bootstrap.LayoutMasonry
30646 * @extends Roo.bootstrap.Component
30647 * Bootstrap Layout Masonry class
30650 * Create a new Element
30651 * @param {Object} config The config object
30654 Roo.bootstrap.LayoutMasonry = function(config){
30656 Roo.bootstrap.LayoutMasonry.superclass.constructor.call(this, config);
30660 Roo.bootstrap.LayoutMasonry.register(this);
30666 * Fire after layout the items
30667 * @param {Roo.bootstrap.LayoutMasonry} this
30668 * @param {Roo.EventObject} e
30675 Roo.extend(Roo.bootstrap.LayoutMasonry, Roo.bootstrap.Component, {
30678 * @cfg {Boolean} isLayoutInstant = no animation?
30680 isLayoutInstant : false, // needed?
30683 * @cfg {Number} boxWidth width of the columns
30688 * @cfg {Number} boxHeight - 0 for square, or fix it at a certian height
30693 * @cfg {Number} padWidth padding below box..
30698 * @cfg {Number} gutter gutter width..
30703 * @cfg {Number} maxCols maximum number of columns
30709 * @cfg {Boolean} isAutoInitial defalut true
30711 isAutoInitial : true,
30716 * @cfg {Boolean} isHorizontal defalut false
30718 isHorizontal : false,
30720 currentSize : null,
30726 bricks: null, //CompositeElement
30730 _isLayoutInited : false,
30732 // isAlternative : false, // only use for vertical layout...
30735 * @cfg {Number} alternativePadWidth padding below box..
30737 alternativePadWidth : 50,
30739 selectedBrick : [],
30741 getAutoCreate : function(){
30743 var cfg = Roo.apply({}, Roo.bootstrap.LayoutMasonry.superclass.getAutoCreate.call(this));
30747 cls: 'blog-masonary-wrapper ' + this.cls,
30749 cls : 'mas-boxes masonary'
30756 getChildContainer: function( )
30758 if (this.boxesEl) {
30759 return this.boxesEl;
30762 this.boxesEl = this.el.select('.mas-boxes').first();
30764 return this.boxesEl;
30768 initEvents : function()
30772 if(this.isAutoInitial){
30773 Roo.log('hook children rendered');
30774 this.on('childrenrendered', function() {
30775 Roo.log('children rendered');
30781 initial : function()
30783 this.selectedBrick = [];
30785 this.currentSize = this.el.getBox(true);
30787 Roo.EventManager.onWindowResize(this.resize, this);
30789 if(!this.isAutoInitial){
30797 //this.layout.defer(500,this);
30801 resize : function()
30803 var cs = this.el.getBox(true);
30806 this.currentSize.width == cs.width &&
30807 this.currentSize.x == cs.x &&
30808 this.currentSize.height == cs.height &&
30809 this.currentSize.y == cs.y
30811 Roo.log("no change in with or X or Y");
30815 this.currentSize = cs;
30821 layout : function()
30823 this._resetLayout();
30825 var isInstant = this.isLayoutInstant !== undefined ? this.isLayoutInstant : !this._isLayoutInited;
30827 this.layoutItems( isInstant );
30829 this._isLayoutInited = true;
30831 this.fireEvent('layout', this);
30835 _resetLayout : function()
30837 if(this.isHorizontal){
30838 this.horizontalMeasureColumns();
30842 this.verticalMeasureColumns();
30846 verticalMeasureColumns : function()
30848 this.getContainerWidth();
30850 // if(Roo.lib.Dom.getViewWidth() < 768 && this.isAlternative){
30851 // this.colWidth = Math.floor(this.containerWidth * 0.8);
30855 var boxWidth = this.boxWidth + this.padWidth;
30857 if(this.containerWidth < this.boxWidth){
30858 boxWidth = this.containerWidth
30861 var containerWidth = this.containerWidth;
30863 var cols = Math.floor(containerWidth / boxWidth);
30865 this.cols = Math.max( cols, 1 );
30867 this.cols = this.maxCols > 0 ? Math.min( this.cols, this.maxCols ) : this.cols;
30869 var totalBoxWidth = this.cols * boxWidth - this.padWidth;
30871 var avail = Math.floor((containerWidth - totalBoxWidth) / this.cols);
30873 this.colWidth = boxWidth + avail - this.padWidth;
30875 this.unitWidth = Math.round((this.colWidth - (this.gutter * 2)) / 3);
30876 this.unitHeight = this.boxHeight > 0 ? this.boxHeight : this.unitWidth;
30879 horizontalMeasureColumns : function()
30881 this.getContainerWidth();
30883 var boxWidth = this.boxWidth;
30885 if(this.containerWidth < boxWidth){
30886 boxWidth = this.containerWidth;
30889 this.unitWidth = Math.floor((boxWidth - (this.gutter * 2)) / 3);
30891 this.el.setHeight(boxWidth);
30895 getContainerWidth : function()
30897 this.containerWidth = this.el.getBox(true).width; //maybe use getComputedWidth
30900 layoutItems : function( isInstant )
30902 Roo.log(this.bricks);
30904 var items = Roo.apply([], this.bricks);
30906 if(this.isHorizontal){
30907 this._horizontalLayoutItems( items , isInstant );
30911 // if(Roo.lib.Dom.getViewWidth() < 768 && this.isAlternative){
30912 // this._verticalAlternativeLayoutItems( items , isInstant );
30916 this._verticalLayoutItems( items , isInstant );
30920 _verticalLayoutItems : function ( items , isInstant)
30922 if ( !items || !items.length ) {
30927 ['xs', 'xs', 'xs', 'tall'],
30928 ['xs', 'xs', 'tall'],
30929 ['xs', 'xs', 'sm'],
30930 ['xs', 'xs', 'xs'],
30936 ['sm', 'xs', 'xs'],
30940 ['tall', 'xs', 'xs', 'xs'],
30941 ['tall', 'xs', 'xs'],
30953 Roo.each(items, function(item, k){
30955 switch (item.size) {
30956 // these layouts take up a full box,
30967 boxes.push([item]);
30990 var filterPattern = function(box, length)
30998 var pattern = box.slice(0, length);
31002 Roo.each(pattern, function(i){
31003 format.push(i.size);
31006 Roo.each(standard, function(s){
31008 if(String(s) != String(format)){
31017 if(!match && length == 1){
31022 filterPattern(box, length - 1);
31026 queue.push(pattern);
31028 box = box.slice(length, box.length);
31030 filterPattern(box, 4);
31036 Roo.each(boxes, function(box, k){
31042 if(box.length == 1){
31047 filterPattern(box, 4);
31051 this._processVerticalLayoutQueue( queue, isInstant );
31055 // _verticalAlternativeLayoutItems : function( items , isInstant )
31057 // if ( !items || !items.length ) {
31061 // this._processVerticalAlternativeLayoutQueue( items, isInstant );
31065 _horizontalLayoutItems : function ( items , isInstant)
31067 if ( !items || !items.length || items.length < 3) {
31073 var eItems = items.slice(0, 3);
31075 items = items.slice(3, items.length);
31078 ['xs', 'xs', 'xs', 'wide'],
31079 ['xs', 'xs', 'wide'],
31080 ['xs', 'xs', 'sm'],
31081 ['xs', 'xs', 'xs'],
31087 ['sm', 'xs', 'xs'],
31091 ['wide', 'xs', 'xs', 'xs'],
31092 ['wide', 'xs', 'xs'],
31105 Roo.each(items, function(item, k){
31107 switch (item.size) {
31118 boxes.push([item]);
31142 var filterPattern = function(box, length)
31150 var pattern = box.slice(0, length);
31154 Roo.each(pattern, function(i){
31155 format.push(i.size);
31158 Roo.each(standard, function(s){
31160 if(String(s) != String(format)){
31169 if(!match && length == 1){
31174 filterPattern(box, length - 1);
31178 queue.push(pattern);
31180 box = box.slice(length, box.length);
31182 filterPattern(box, 4);
31188 Roo.each(boxes, function(box, k){
31194 if(box.length == 1){
31199 filterPattern(box, 4);
31206 var pos = this.el.getBox(true);
31210 var maxX = pos.right - this.unitWidth * 3 - this.gutter * 2 - this.padWidth;
31212 var hit_end = false;
31214 Roo.each(queue, function(box){
31218 Roo.each(box, function(b){
31220 b.el.setVisibilityMode(Roo.Element.DISPLAY);
31230 Roo.each(box, function(b){
31232 b.el.setVisibilityMode(Roo.Element.DISPLAY);
31235 mx = Math.max(mx, b.x);
31239 maxX = maxX - this.unitWidth * mx - this.gutter * (mx - 1) - this.padWidth;
31243 Roo.each(box, function(b){
31245 b.el.setVisibilityMode(Roo.Element.DISPLAY);
31259 this._processHorizontalLayoutQueue( prune, eItems, isInstant );
31262 /** Sets position of item in DOM
31263 * @param {Element} item
31264 * @param {Number} x - horizontal position
31265 * @param {Number} y - vertical position
31266 * @param {Boolean} isInstant - disables transitions
31268 _processVerticalLayoutQueue : function( queue, isInstant )
31270 var pos = this.el.getBox(true);
31275 for (var i = 0; i < this.cols; i++){
31279 Roo.each(queue, function(box, k){
31281 var col = k % this.cols;
31283 Roo.each(box, function(b,kk){
31285 b.el.position('absolute');
31287 var width = Math.floor(this.unitWidth * b.x + (this.gutter * (b.x - 1)) + b.el.getPadding('lr'));
31288 var height = Math.floor(this.unitHeight * b.y + (this.gutter * (b.y - 1)) + b.el.getPadding('tb'));
31290 if(b.size == 'md-left' || b.size == 'md-right'){
31291 width = Math.floor(this.unitWidth * (b.x - 1) + (this.gutter * (b.x - 2)) + b.el.getPadding('lr'));
31292 height = Math.floor(this.unitHeight * (b.y - 1) + (this.gutter * (b.y - 2)) + b.el.getPadding('tb'));
31295 b.el.setWidth(width);
31296 b.el.setHeight(height);
31298 b.el.select('iframe',true).setSize(width,height);
31302 for (var i = 0; i < this.cols; i++){
31304 if(maxY[i] < maxY[col]){
31309 col = Math.min(col, i);
31313 x = pos.x + col * (this.colWidth + this.padWidth);
31317 var positions = [];
31319 switch (box.length){
31321 positions = this.getVerticalOneBoxColPositions(x, y, box);
31324 positions = this.getVerticalTwoBoxColPositions(x, y, box);
31327 positions = this.getVerticalThreeBoxColPositions(x, y, box);
31330 positions = this.getVerticalFourBoxColPositions(x, y, box);
31336 Roo.each(box, function(b,kk){
31338 b.el.setXY([positions[kk].x, positions[kk].y], isInstant ? false : true);
31340 var sz = b.el.getSize();
31342 maxY[col] = Math.max(maxY[col], positions[kk].y + sz.height + this.padWidth);
31350 for (var i = 0; i < this.cols; i++){
31351 mY = Math.max(mY, maxY[i]);
31354 this.el.setHeight(mY - pos.y);
31358 // _processVerticalAlternativeLayoutQueue : function( items, isInstant )
31360 // var pos = this.el.getBox(true);
31363 // var maxX = pos.right;
31365 // var maxHeight = 0;
31367 // Roo.each(items, function(item, k){
31371 // item.el.position('absolute');
31373 // var width = Math.floor(this.colWidth + item.el.getPadding('lr'));
31375 // item.el.setWidth(width);
31377 // var height = Math.floor(this.colWidth * item.y / item.x + item.el.getPadding('tb'));
31379 // item.el.setHeight(height);
31382 // item.el.setXY([x, y], isInstant ? false : true);
31384 // item.el.setXY([maxX - width, y], isInstant ? false : true);
31387 // y = y + height + this.alternativePadWidth;
31389 // maxHeight = maxHeight + height + this.alternativePadWidth;
31393 // this.el.setHeight(maxHeight);
31397 _processHorizontalLayoutQueue : function( queue, eItems, isInstant )
31399 var pos = this.el.getBox(true);
31404 var maxX = pos.right;
31406 this._processHorizontalEndItem(eItems, maxX, minX, minY, isInstant);
31408 var maxX = maxX - this.unitWidth * 3 - this.gutter * 2 - this.padWidth;
31410 Roo.each(queue, function(box, k){
31412 Roo.each(box, function(b, kk){
31414 b.el.position('absolute');
31416 var width = Math.floor(this.unitWidth * b.x + (this.gutter * (b.x - 1)) + b.el.getPadding('lr'));
31417 var height = Math.floor(this.unitWidth * b.y + (this.gutter * (b.y - 1)) + b.el.getPadding('tb'));
31419 if(b.size == 'md-left' || b.size == 'md-right'){
31420 width = Math.floor(this.unitWidth * (b.x - 1) + (this.gutter * (b.x - 2)) + b.el.getPadding('lr'));
31421 height = Math.floor(this.unitWidth * (b.y - 1) + (this.gutter * (b.y - 2)) + b.el.getPadding('tb'));
31424 b.el.setWidth(width);
31425 b.el.setHeight(height);
31433 var positions = [];
31435 switch (box.length){
31437 positions = this.getHorizontalOneBoxColPositions(maxX, minY, box);
31440 positions = this.getHorizontalTwoBoxColPositions(maxX, minY, box);
31443 positions = this.getHorizontalThreeBoxColPositions(maxX, minY, box);
31446 positions = this.getHorizontalFourBoxColPositions(maxX, minY, box);
31452 Roo.each(box, function(b,kk){
31454 b.el.setXY([positions[kk].x, positions[kk].y], isInstant ? false : true);
31456 maxX = Math.min(maxX, positions[kk].x - this.padWidth);
31464 _processHorizontalEndItem : function(eItems, maxX, minX, minY, isInstant)
31466 Roo.each(eItems, function(b,k){
31468 b.size = (k == 0) ? 'sm' : 'xs';
31469 b.x = (k == 0) ? 2 : 1;
31470 b.y = (k == 0) ? 2 : 1;
31472 b.el.position('absolute');
31474 var width = Math.floor(this.unitWidth * b.x + (this.gutter * (b.x - 1)) + b.el.getPadding('lr'));
31476 b.el.setWidth(width);
31478 var height = Math.floor(this.unitWidth * b.y + (this.gutter * (b.y - 1)) + b.el.getPadding('tb'));
31480 b.el.setHeight(height);
31484 var positions = [];
31487 x : maxX - this.unitWidth * 2 - this.gutter,
31492 x : maxX - this.unitWidth,
31493 y : minY + (this.unitWidth + this.gutter) * 2
31497 x : maxX - this.unitWidth * 3 - this.gutter * 2,
31501 Roo.each(eItems, function(b,k){
31503 b.el.setXY([positions[k].x, positions[k].y], isInstant ? false : true);
31509 getVerticalOneBoxColPositions : function(x, y, box)
31513 var rand = Math.floor(Math.random() * ((4 - box[0].x)));
31515 if(box[0].size == 'md-left'){
31519 if(box[0].size == 'md-right'){
31524 x : x + (this.unitWidth + this.gutter) * rand,
31531 getVerticalTwoBoxColPositions : function(x, y, box)
31535 if(box[0].size == 'xs'){
31539 y : y + ((this.unitHeight + this.gutter) * Math.floor(Math.random() * box[1].y))
31543 x : x + (this.unitWidth + this.gutter) * (3 - box[1].x),
31557 x : x + (this.unitWidth + this.gutter) * 2,
31558 y : y + ((this.unitHeight + this.gutter) * Math.floor(Math.random() * box[0].y))
31565 getVerticalThreeBoxColPositions : function(x, y, box)
31569 if(box[0].size == 'xs' && box[1].size == 'xs' && box[2].size == 'xs'){
31577 x : x + (this.unitWidth + this.gutter) * 1,
31582 x : x + (this.unitWidth + this.gutter) * 2,
31590 if(box[0].size == 'xs' && box[1].size == 'xs'){
31599 y : y + ((this.unitHeight + this.gutter) * (box[2].y - 1))
31603 x : x + (this.unitWidth + this.gutter) * 1,
31617 x : x + (this.unitWidth + this.gutter) * 2,
31622 x : x + (this.unitWidth + this.gutter) * 2,
31623 y : y + (this.unitHeight + this.gutter) * (box[0].y - 1)
31630 getVerticalFourBoxColPositions : function(x, y, box)
31634 if(box[0].size == 'xs'){
31643 y : y + (this.unitHeight + this.gutter) * 1
31648 y : y + (this.unitHeight + this.gutter) * 2
31652 x : x + (this.unitWidth + this.gutter) * 1,
31666 x : x + (this.unitWidth + this.gutter) * 2,
31671 x : x + (this.unitHeightunitWidth + this.gutter) * 2,
31672 y : y + (this.unitHeight + this.gutter) * 1
31676 x : x + (this.unitWidth + this.gutter) * 2,
31677 y : y + (this.unitWidth + this.gutter) * 2
31684 getHorizontalOneBoxColPositions : function(maxX, minY, box)
31688 if(box[0].size == 'md-left'){
31690 x : maxX - this.unitWidth * (box[0].x - 1) - this.gutter * (box[0].x - 2),
31697 if(box[0].size == 'md-right'){
31699 x : maxX - this.unitWidth * (box[0].x - 1) - this.gutter * (box[0].x - 2),
31700 y : minY + (this.unitWidth + this.gutter) * 1
31706 var rand = Math.floor(Math.random() * (4 - box[0].y));
31709 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
31710 y : minY + (this.unitWidth + this.gutter) * rand
31717 getHorizontalTwoBoxColPositions : function(maxX, minY, box)
31721 if(box[0].size == 'xs'){
31724 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
31729 x : maxX - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1),
31730 y : minY + (this.unitWidth + this.gutter) * (3 - box[1].y)
31738 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
31743 x : maxX - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1),
31744 y : minY + (this.unitWidth + this.gutter) * 2
31751 getHorizontalThreeBoxColPositions : function(maxX, minY, box)
31755 if(box[0].size == 'xs' && box[1].size == 'xs' && box[2].size == 'xs'){
31758 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
31763 x : maxX - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1),
31764 y : minY + (this.unitWidth + this.gutter) * 1
31768 x : maxX - this.unitWidth * box[2].x - this.gutter * (box[2].x - 1),
31769 y : minY + (this.unitWidth + this.gutter) * 2
31776 if(box[0].size == 'xs' && box[1].size == 'xs'){
31779 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
31784 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1) - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1),
31789 x : maxX - this.unitWidth * box[2].x - this.gutter * (box[2].x - 1),
31790 y : minY + (this.unitWidth + this.gutter) * 1
31798 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
31803 x : maxX - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1),
31804 y : minY + (this.unitWidth + this.gutter) * 2
31808 x : maxX - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1) - this.unitWidth * box[2].x - this.gutter * (box[2].x - 1),
31809 y : minY + (this.unitWidth + this.gutter) * 2
31816 getHorizontalFourBoxColPositions : function(maxX, minY, box)
31820 if(box[0].size == 'xs'){
31823 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
31828 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1) - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1),
31833 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),
31838 x : maxX - this.unitWidth * box[3].x - this.gutter * (box[3].x - 1),
31839 y : minY + (this.unitWidth + this.gutter) * 1
31847 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
31852 x : maxX - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1),
31853 y : minY + (this.unitWidth + this.gutter) * 2
31857 x : maxX - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1) - this.unitWidth * box[2].x - this.gutter * (box[2].x - 1),
31858 y : minY + (this.unitWidth + this.gutter) * 2
31862 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),
31863 y : minY + (this.unitWidth + this.gutter) * 2
31871 * remove a Masonry Brick
31872 * @param {Roo.bootstrap.MasonryBrick} the masonry brick to remove
31874 removeBrick : function(brick_id)
31880 for (var i = 0; i<this.bricks.length; i++) {
31881 if (this.bricks[i].id == brick_id) {
31882 this.bricks.splice(i,1);
31883 this.el.dom.removeChild(Roo.get(brick_id).dom);
31890 * adds a Masonry Brick
31891 * @param {Roo.bootstrap.MasonryBrick} the masonry brick to add
31893 addBrick : function(cfg)
31895 var cn = new Roo.bootstrap.MasonryBrick(cfg);
31896 //this.register(cn);
31897 cn.parentId = this.id;
31898 cn.onRender(this.el, null);
31903 * register a Masonry Brick
31904 * @param {Roo.bootstrap.MasonryBrick} the masonry brick to add
31907 register : function(brick)
31909 this.bricks.push(brick);
31910 brick.masonryId = this.id;
31914 * clear all the Masonry Brick
31916 clearAll : function()
31919 //this.getChildContainer().dom.innerHTML = "";
31920 this.el.dom.innerHTML = '';
31923 getSelected : function()
31925 if (!this.selectedBrick) {
31929 return this.selectedBrick;
31933 Roo.apply(Roo.bootstrap.LayoutMasonry, {
31937 * register a Masonry Layout
31938 * @param {Roo.bootstrap.LayoutMasonry} the masonry layout to add
31941 register : function(layout)
31943 this.groups[layout.id] = layout;
31946 * fetch a Masonry Layout based on the masonry layout ID
31947 * @param {string} the masonry layout to add
31948 * @returns {Roo.bootstrap.LayoutMasonry} the masonry layout
31951 get: function(layout_id) {
31952 if (typeof(this.groups[layout_id]) == 'undefined') {
31955 return this.groups[layout_id] ;
31967 * http://masonry.desandro.com
31969 * The idea is to render all the bricks based on vertical width...
31971 * The original code extends 'outlayer' - we might need to use that....
31977 * @class Roo.bootstrap.LayoutMasonryAuto
31978 * @extends Roo.bootstrap.Component
31979 * Bootstrap Layout Masonry class
31982 * Create a new Element
31983 * @param {Object} config The config object
31986 Roo.bootstrap.LayoutMasonryAuto = function(config){
31987 Roo.bootstrap.LayoutMasonryAuto.superclass.constructor.call(this, config);
31990 Roo.extend(Roo.bootstrap.LayoutMasonryAuto, Roo.bootstrap.Component, {
31993 * @cfg {Boolean} isFitWidth - resize the width..
31995 isFitWidth : false, // options..
31997 * @cfg {Boolean} isOriginLeft = left align?
31999 isOriginLeft : true,
32001 * @cfg {Boolean} isOriginTop = top align?
32003 isOriginTop : false,
32005 * @cfg {Boolean} isLayoutInstant = no animation?
32007 isLayoutInstant : false, // needed?
32009 * @cfg {Boolean} isResizingContainer = not sure if this is used..
32011 isResizingContainer : true,
32013 * @cfg {Number} columnWidth width of the columns
32019 * @cfg {Number} maxCols maximum number of columns
32024 * @cfg {Number} padHeight padding below box..
32030 * @cfg {Boolean} isAutoInitial defalut true
32033 isAutoInitial : true,
32039 initialColumnWidth : 0,
32040 currentSize : null,
32042 colYs : null, // array.
32049 bricks: null, //CompositeElement
32050 cols : 0, // array?
32051 // element : null, // wrapped now this.el
32052 _isLayoutInited : null,
32055 getAutoCreate : function(){
32059 cls: 'blog-masonary-wrapper ' + this.cls,
32061 cls : 'mas-boxes masonary'
32068 getChildContainer: function( )
32070 if (this.boxesEl) {
32071 return this.boxesEl;
32074 this.boxesEl = this.el.select('.mas-boxes').first();
32076 return this.boxesEl;
32080 initEvents : function()
32084 if(this.isAutoInitial){
32085 Roo.log('hook children rendered');
32086 this.on('childrenrendered', function() {
32087 Roo.log('children rendered');
32094 initial : function()
32096 this.reloadItems();
32098 this.currentSize = this.el.getBox(true);
32100 /// was window resize... - let's see if this works..
32101 Roo.EventManager.onWindowResize(this.resize, this);
32103 if(!this.isAutoInitial){
32108 this.layout.defer(500,this);
32111 reloadItems: function()
32113 this.bricks = this.el.select('.masonry-brick', true);
32115 this.bricks.each(function(b) {
32116 //Roo.log(b.getSize());
32117 if (!b.attr('originalwidth')) {
32118 b.attr('originalwidth', b.getSize().width);
32123 Roo.log(this.bricks.elements.length);
32126 resize : function()
32129 var cs = this.el.getBox(true);
32131 if (this.currentSize.width == cs.width && this.currentSize.x == cs.x ) {
32132 Roo.log("no change in with or X");
32135 this.currentSize = cs;
32139 layout : function()
32142 this._resetLayout();
32143 //this._manageStamps();
32145 // don't animate first layout
32146 var isInstant = this.isLayoutInstant !== undefined ? this.isLayoutInstant : !this._isLayoutInited;
32147 this.layoutItems( isInstant );
32149 // flag for initalized
32150 this._isLayoutInited = true;
32153 layoutItems : function( isInstant )
32155 //var items = this._getItemsForLayout( this.items );
32156 // original code supports filtering layout items.. we just ignore it..
32158 this._layoutItems( this.bricks , isInstant );
32160 this._postLayout();
32162 _layoutItems : function ( items , isInstant)
32164 //this.fireEvent( 'layout', this, items );
32167 if ( !items || !items.elements.length ) {
32168 // no items, emit event with empty array
32173 items.each(function(item) {
32174 Roo.log("layout item");
32176 // get x/y object from method
32177 var position = this._getItemLayoutPosition( item );
32179 position.item = item;
32180 position.isInstant = isInstant; // || item.isLayoutInstant; << not set yet...
32181 queue.push( position );
32184 this._processLayoutQueue( queue );
32186 /** Sets position of item in DOM
32187 * @param {Element} item
32188 * @param {Number} x - horizontal position
32189 * @param {Number} y - vertical position
32190 * @param {Boolean} isInstant - disables transitions
32192 _processLayoutQueue : function( queue )
32194 for ( var i=0, len = queue.length; i < len; i++ ) {
32195 var obj = queue[i];
32196 obj.item.position('absolute');
32197 obj.item.setXY([obj.x,obj.y], obj.isInstant ? false : true);
32203 * Any logic you want to do after each layout,
32204 * i.e. size the container
32206 _postLayout : function()
32208 this.resizeContainer();
32211 resizeContainer : function()
32213 if ( !this.isResizingContainer ) {
32216 var size = this._getContainerSize();
32218 this.el.setSize(size.width,size.height);
32219 this.boxesEl.setSize(size.width,size.height);
32225 _resetLayout : function()
32227 //this.getSize(); // -- does not really do anything.. it probably applies left/right etc. to obuject but not used
32228 this.colWidth = this.el.getWidth();
32229 //this.gutter = this.el.getWidth();
32231 this.measureColumns();
32237 this.colYs.push( 0 );
32243 measureColumns : function()
32245 this.getContainerWidth();
32246 // if columnWidth is 0, default to outerWidth of first item
32247 if ( !this.columnWidth ) {
32248 var firstItem = this.bricks.first();
32249 Roo.log(firstItem);
32250 this.columnWidth = this.containerWidth;
32251 if (firstItem && firstItem.attr('originalwidth') ) {
32252 this.columnWidth = 1* (firstItem.attr('originalwidth') || firstItem.getWidth());
32254 // columnWidth fall back to item of first element
32255 Roo.log("set column width?");
32256 this.initialColumnWidth = this.columnWidth ;
32258 // if first elem has no width, default to size of container
32263 if (this.initialColumnWidth) {
32264 this.columnWidth = this.initialColumnWidth;
32269 // column width is fixed at the top - however if container width get's smaller we should
32272 // this bit calcs how man columns..
32274 var columnWidth = this.columnWidth += this.gutter;
32276 // calculate columns
32277 var containerWidth = this.containerWidth + this.gutter;
32279 var cols = (containerWidth - this.padWidth) / (columnWidth - this.padWidth);
32280 // fix rounding errors, typically with gutters
32281 var excess = columnWidth - containerWidth % columnWidth;
32284 // if overshoot is less than a pixel, round up, otherwise floor it
32285 var mathMethod = excess && excess < 1 ? 'round' : 'floor';
32286 cols = Math[ mathMethod ]( cols );
32287 this.cols = Math.max( cols, 1 );
32288 this.cols = this.maxCols > 0 ? Math.min( this.cols, this.maxCols ) : this.cols;
32290 // padding positioning..
32291 var totalColWidth = this.cols * this.columnWidth;
32292 var padavail = this.containerWidth - totalColWidth;
32293 // so for 2 columns - we need 3 'pads'
32295 var padNeeded = (1+this.cols) * this.padWidth;
32297 var padExtra = Math.floor((padavail - padNeeded) / this.cols);
32299 this.columnWidth += padExtra
32300 //this.padWidth = Math.floor(padavail / ( this.cols));
32302 // adjust colum width so that padding is fixed??
32304 // we have 3 columns ... total = width * 3
32305 // we have X left over... that should be used by
32307 //if (this.expandC) {
32315 getContainerWidth : function()
32317 /* // container is parent if fit width
32318 var container = this.isFitWidth ? this.element.parentNode : this.element;
32319 // check that this.size and size are there
32320 // IE8 triggers resize on body size change, so they might not be
32322 var size = getSize( container ); //FIXME
32323 this.containerWidth = size && size.innerWidth; //FIXME
32326 this.containerWidth = this.el.getBox(true).width; //maybe use getComputedWidth
32330 _getItemLayoutPosition : function( item ) // what is item?
32332 // we resize the item to our columnWidth..
32334 item.setWidth(this.columnWidth);
32335 item.autoBoxAdjust = false;
32337 var sz = item.getSize();
32339 // how many columns does this brick span
32340 var remainder = this.containerWidth % this.columnWidth;
32342 var mathMethod = remainder && remainder < 1 ? 'round' : 'ceil';
32343 // round if off by 1 pixel, otherwise use ceil
32344 var colSpan = Math[ mathMethod ]( sz.width / this.columnWidth );
32345 colSpan = Math.min( colSpan, this.cols );
32347 // normally this should be '1' as we dont' currently allow multi width columns..
32349 var colGroup = this._getColGroup( colSpan );
32350 // get the minimum Y value from the columns
32351 var minimumY = Math.min.apply( Math, colGroup );
32352 Roo.log([ 'setHeight', minimumY, sz.height, setHeight ]);
32354 var shortColIndex = colGroup.indexOf( minimumY ); // broken on ie8..?? probably...
32356 // position the brick
32358 x: this.currentSize.x + (this.padWidth /2) + ((this.columnWidth + this.padWidth )* shortColIndex),
32359 y: this.currentSize.y + minimumY + this.padHeight
32363 // apply setHeight to necessary columns
32364 var setHeight = minimumY + sz.height + this.padHeight;
32365 //Roo.log([ 'setHeight', minimumY, sz.height, setHeight ]);
32367 var setSpan = this.cols + 1 - colGroup.length;
32368 for ( var i = 0; i < setSpan; i++ ) {
32369 this.colYs[ shortColIndex + i ] = setHeight ;
32376 * @param {Number} colSpan - number of columns the element spans
32377 * @returns {Array} colGroup
32379 _getColGroup : function( colSpan )
32381 if ( colSpan < 2 ) {
32382 // if brick spans only one column, use all the column Ys
32387 // how many different places could this brick fit horizontally
32388 var groupCount = this.cols + 1 - colSpan;
32389 // for each group potential horizontal position
32390 for ( var i = 0; i < groupCount; i++ ) {
32391 // make an array of colY values for that one group
32392 var groupColYs = this.colYs.slice( i, i + colSpan );
32393 // and get the max value of the array
32394 colGroup[i] = Math.max.apply( Math, groupColYs );
32399 _manageStamp : function( stamp )
32401 var stampSize = stamp.getSize();
32402 var offset = stamp.getBox();
32403 // get the columns that this stamp affects
32404 var firstX = this.isOriginLeft ? offset.x : offset.right;
32405 var lastX = firstX + stampSize.width;
32406 var firstCol = Math.floor( firstX / this.columnWidth );
32407 firstCol = Math.max( 0, firstCol );
32409 var lastCol = Math.floor( lastX / this.columnWidth );
32410 // lastCol should not go over if multiple of columnWidth #425
32411 lastCol -= lastX % this.columnWidth ? 0 : 1;
32412 lastCol = Math.min( this.cols - 1, lastCol );
32414 // set colYs to bottom of the stamp
32415 var stampMaxY = ( this.isOriginTop ? offset.y : offset.bottom ) +
32418 for ( var i = firstCol; i <= lastCol; i++ ) {
32419 this.colYs[i] = Math.max( stampMaxY, this.colYs[i] );
32424 _getContainerSize : function()
32426 this.maxY = Math.max.apply( Math, this.colYs );
32431 if ( this.isFitWidth ) {
32432 size.width = this._getContainerFitWidth();
32438 _getContainerFitWidth : function()
32440 var unusedCols = 0;
32441 // count unused columns
32444 if ( this.colYs[i] !== 0 ) {
32449 // fit container to columns that have been used
32450 return ( this.cols - unusedCols ) * this.columnWidth - this.gutter;
32453 needsResizeLayout : function()
32455 var previousWidth = this.containerWidth;
32456 this.getContainerWidth();
32457 return previousWidth !== this.containerWidth;
32472 * @class Roo.bootstrap.MasonryBrick
32473 * @extends Roo.bootstrap.Component
32474 * Bootstrap MasonryBrick class
32477 * Create a new MasonryBrick
32478 * @param {Object} config The config object
32481 Roo.bootstrap.MasonryBrick = function(config){
32483 Roo.bootstrap.MasonryBrick.superclass.constructor.call(this, config);
32485 Roo.bootstrap.MasonryBrick.register(this);
32491 * When a MasonryBrick is clcik
32492 * @param {Roo.bootstrap.MasonryBrick} this
32493 * @param {Roo.EventObject} e
32499 Roo.extend(Roo.bootstrap.MasonryBrick, Roo.bootstrap.Component, {
32502 * @cfg {String} title
32506 * @cfg {String} html
32510 * @cfg {String} bgimage
32514 * @cfg {String} videourl
32518 * @cfg {String} cls
32522 * @cfg {String} href
32526 * @cfg {String} size (xs|sm|md|md-left|md-right|tall|wide)
32531 * @cfg {String} placetitle (center|bottom)
32536 * @cfg {Boolean} isFitContainer defalut true
32538 isFitContainer : true,
32541 * @cfg {Boolean} preventDefault defalut false
32543 preventDefault : false,
32546 * @cfg {Boolean} inverse defalut false
32548 maskInverse : false,
32550 getAutoCreate : function()
32552 if(!this.isFitContainer){
32553 return this.getSplitAutoCreate();
32556 var cls = 'masonry-brick masonry-brick-full';
32558 if(this.href.length){
32559 cls += ' masonry-brick-link';
32562 if(this.bgimage.length){
32563 cls += ' masonry-brick-image';
32566 if(this.maskInverse){
32567 cls += ' mask-inverse';
32570 if(!this.html.length && !this.maskInverse && !this.videourl.length){
32571 cls += ' enable-mask';
32575 cls += ' masonry-' + this.size + '-brick';
32578 if(this.placetitle.length){
32580 switch (this.placetitle) {
32582 cls += ' masonry-center-title';
32585 cls += ' masonry-bottom-title';
32592 if(!this.html.length && !this.bgimage.length){
32593 cls += ' masonry-center-title';
32596 if(!this.html.length && this.bgimage.length){
32597 cls += ' masonry-bottom-title';
32602 cls += ' ' + this.cls;
32606 tag: (this.href.length) ? 'a' : 'div',
32611 cls: 'masonry-brick-mask'
32615 cls: 'masonry-brick-paragraph',
32621 if(this.href.length){
32622 cfg.href = this.href;
32625 var cn = cfg.cn[1].cn;
32627 if(this.title.length){
32630 cls: 'masonry-brick-title',
32635 if(this.html.length){
32638 cls: 'masonry-brick-text',
32643 if (!this.title.length && !this.html.length) {
32644 cfg.cn[1].cls += ' hide';
32647 if(this.bgimage.length){
32650 cls: 'masonry-brick-image-view',
32655 if(this.videourl.length){
32656 var vurl = this.videourl.replace(/https:\/\/youtu\.be/, 'https://www.youtube.com/embed/');
32657 // youtube support only?
32660 cls: 'masonry-brick-image-view',
32663 allowfullscreen : true
32671 getSplitAutoCreate : function()
32673 var cls = 'masonry-brick masonry-brick-split';
32675 if(this.href.length){
32676 cls += ' masonry-brick-link';
32679 if(this.bgimage.length){
32680 cls += ' masonry-brick-image';
32684 cls += ' masonry-' + this.size + '-brick';
32687 switch (this.placetitle) {
32689 cls += ' masonry-center-title';
32692 cls += ' masonry-bottom-title';
32695 if(!this.bgimage.length){
32696 cls += ' masonry-center-title';
32699 if(this.bgimage.length){
32700 cls += ' masonry-bottom-title';
32706 cls += ' ' + this.cls;
32710 tag: (this.href.length) ? 'a' : 'div',
32715 cls: 'masonry-brick-split-head',
32719 cls: 'masonry-brick-paragraph',
32726 cls: 'masonry-brick-split-body',
32732 if(this.href.length){
32733 cfg.href = this.href;
32736 if(this.title.length){
32737 cfg.cn[0].cn[0].cn.push({
32739 cls: 'masonry-brick-title',
32744 if(this.html.length){
32745 cfg.cn[1].cn.push({
32747 cls: 'masonry-brick-text',
32752 if(this.bgimage.length){
32753 cfg.cn[0].cn.push({
32755 cls: 'masonry-brick-image-view',
32760 if(this.videourl.length){
32761 var vurl = this.videourl.replace(/https:\/\/youtu\.be/, 'https://www.youtube.com/embed/');
32762 // youtube support only?
32763 cfg.cn[0].cn.cn.push({
32765 cls: 'masonry-brick-image-view',
32768 allowfullscreen : true
32775 initEvents: function()
32777 switch (this.size) {
32810 this.el.on('touchstart', this.onTouchStart, this);
32811 this.el.on('touchmove', this.onTouchMove, this);
32812 this.el.on('touchend', this.onTouchEnd, this);
32813 this.el.on('contextmenu', this.onContextMenu, this);
32815 this.el.on('mouseenter' ,this.enter, this);
32816 this.el.on('mouseleave', this.leave, this);
32817 this.el.on('click', this.onClick, this);
32820 if (typeof(this.parent().bricks) == 'object' && this.parent().bricks != null) {
32821 this.parent().bricks.push(this);
32826 onClick: function(e, el)
32828 var time = this.endTimer - this.startTimer;
32829 // Roo.log(e.preventDefault());
32832 e.preventDefault();
32837 if(!this.preventDefault){
32841 e.preventDefault();
32843 if (this.activeClass != '') {
32844 this.selectBrick();
32847 this.fireEvent('click', this, e);
32850 enter: function(e, el)
32852 e.preventDefault();
32854 if(!this.isFitContainer || this.maskInverse || this.videourl.length){
32858 if(this.bgimage.length && this.html.length){
32859 this.el.select('.masonry-brick-paragraph', true).first().setOpacity(0.9, true);
32863 leave: function(e, el)
32865 e.preventDefault();
32867 if(!this.isFitContainer || this.maskInverse || this.videourl.length){
32871 if(this.bgimage.length && this.html.length){
32872 this.el.select('.masonry-brick-paragraph', true).first().setOpacity(0, true);
32876 onTouchStart: function(e, el)
32878 // e.preventDefault();
32880 this.touchmoved = false;
32882 if(!this.isFitContainer){
32886 if(!this.bgimage.length || !this.html.length){
32890 this.el.select('.masonry-brick-paragraph', true).first().setOpacity(0.9, true);
32892 this.timer = new Date().getTime();
32896 onTouchMove: function(e, el)
32898 this.touchmoved = true;
32901 onContextMenu : function(e,el)
32903 e.preventDefault();
32904 e.stopPropagation();
32908 onTouchEnd: function(e, el)
32910 // e.preventDefault();
32912 if((new Date().getTime() - this.timer > 1000) || !this.href.length || this.touchmoved){
32919 if(!this.bgimage.length || !this.html.length){
32921 if(this.href.length){
32922 window.location.href = this.href;
32928 if(!this.isFitContainer){
32932 this.el.select('.masonry-brick-paragraph', true).first().setOpacity(0, true);
32934 window.location.href = this.href;
32937 //selection on single brick only
32938 selectBrick : function() {
32940 if (!this.parentId) {
32944 var m = Roo.bootstrap.LayoutMasonry.get(this.parentId);
32945 var index = m.selectedBrick.indexOf(this.id);
32948 m.selectedBrick.splice(index,1);
32949 this.el.removeClass(this.activeClass);
32953 for(var i = 0; i < m.selectedBrick.length; i++) {
32954 var b = Roo.bootstrap.MasonryBrick.get(m.selectedBrick[i]);
32955 b.el.removeClass(b.activeClass);
32958 m.selectedBrick = [];
32960 m.selectedBrick.push(this.id);
32961 this.el.addClass(this.activeClass);
32965 isSelected : function(){
32966 return this.el.hasClass(this.activeClass);
32971 Roo.apply(Roo.bootstrap.MasonryBrick, {
32974 groups : new Roo.util.MixedCollection(false, function(o) { return o.el.id; }),
32976 * register a Masonry Brick
32977 * @param {Roo.bootstrap.MasonryBrick} the masonry brick to add
32980 register : function(brick)
32982 //this.groups[brick.id] = brick;
32983 this.groups.add(brick.id, brick);
32986 * fetch a masonry brick based on the masonry brick ID
32987 * @param {string} the masonry brick to add
32988 * @returns {Roo.bootstrap.MasonryBrick} the masonry brick
32991 get: function(brick_id)
32993 // if (typeof(this.groups[brick_id]) == 'undefined') {
32996 // return this.groups[brick_id] ;
32998 if(this.groups.key(brick_id)) {
32999 return this.groups.key(brick_id);
33017 * @class Roo.bootstrap.Brick
33018 * @extends Roo.bootstrap.Component
33019 * Bootstrap Brick class
33022 * Create a new Brick
33023 * @param {Object} config The config object
33026 Roo.bootstrap.Brick = function(config){
33027 Roo.bootstrap.Brick.superclass.constructor.call(this, config);
33033 * When a Brick is click
33034 * @param {Roo.bootstrap.Brick} this
33035 * @param {Roo.EventObject} e
33041 Roo.extend(Roo.bootstrap.Brick, Roo.bootstrap.Component, {
33044 * @cfg {String} title
33048 * @cfg {String} html
33052 * @cfg {String} bgimage
33056 * @cfg {String} cls
33060 * @cfg {String} href
33064 * @cfg {String} video
33068 * @cfg {Boolean} square
33072 getAutoCreate : function()
33074 var cls = 'roo-brick';
33076 if(this.href.length){
33077 cls += ' roo-brick-link';
33080 if(this.bgimage.length){
33081 cls += ' roo-brick-image';
33084 if(!this.html.length && !this.bgimage.length){
33085 cls += ' roo-brick-center-title';
33088 if(!this.html.length && this.bgimage.length){
33089 cls += ' roo-brick-bottom-title';
33093 cls += ' ' + this.cls;
33097 tag: (this.href.length) ? 'a' : 'div',
33102 cls: 'roo-brick-paragraph',
33108 if(this.href.length){
33109 cfg.href = this.href;
33112 var cn = cfg.cn[0].cn;
33114 if(this.title.length){
33117 cls: 'roo-brick-title',
33122 if(this.html.length){
33125 cls: 'roo-brick-text',
33132 if(this.bgimage.length){
33135 cls: 'roo-brick-image-view',
33143 initEvents: function()
33145 if(this.title.length || this.html.length){
33146 this.el.on('mouseenter' ,this.enter, this);
33147 this.el.on('mouseleave', this.leave, this);
33150 Roo.EventManager.onWindowResize(this.resize, this);
33152 if(this.bgimage.length){
33153 this.imageEl = this.el.select('.roo-brick-image-view', true).first();
33154 this.imageEl.on('load', this.onImageLoad, this);
33161 onImageLoad : function()
33166 resize : function()
33168 var paragraph = this.el.select('.roo-brick-paragraph', true).first();
33170 paragraph.setHeight(paragraph.getWidth() + paragraph.getPadding('tb'));
33172 if(this.bgimage.length){
33173 var image = this.el.select('.roo-brick-image-view', true).first();
33175 image.setWidth(paragraph.getWidth());
33178 image.setHeight(paragraph.getWidth());
33181 this.el.setHeight(image.getHeight());
33182 paragraph.setHeight(image.getHeight());
33188 enter: function(e, el)
33190 e.preventDefault();
33192 if(this.bgimage.length){
33193 this.el.select('.roo-brick-paragraph', true).first().setOpacity(0.9, true);
33194 this.el.select('.roo-brick-image-view', true).first().setOpacity(0.1, true);
33198 leave: function(e, el)
33200 e.preventDefault();
33202 if(this.bgimage.length){
33203 this.el.select('.roo-brick-paragraph', true).first().setOpacity(0, true);
33204 this.el.select('.roo-brick-image-view', true).first().setOpacity(1, true);
33219 * @class Roo.bootstrap.NumberField
33220 * @extends Roo.bootstrap.Input
33221 * Bootstrap NumberField class
33227 * Create a new NumberField
33228 * @param {Object} config The config object
33231 Roo.bootstrap.NumberField = function(config){
33232 Roo.bootstrap.NumberField.superclass.constructor.call(this, config);
33235 Roo.extend(Roo.bootstrap.NumberField, Roo.bootstrap.Input, {
33238 * @cfg {Boolean} allowDecimals False to disallow decimal values (defaults to true)
33240 allowDecimals : true,
33242 * @cfg {String} decimalSeparator Character(s) to allow as the decimal separator (defaults to '.')
33244 decimalSeparator : ".",
33246 * @cfg {Number} decimalPrecision The maximum precision to display after the decimal separator (defaults to 2)
33248 decimalPrecision : 2,
33250 * @cfg {Boolean} allowNegative False to prevent entering a negative sign (defaults to true)
33252 allowNegative : true,
33255 * @cfg {Boolean} allowZero False to blank out if the user enters '0' (defaults to true)
33259 * @cfg {Number} minValue The minimum allowed value (defaults to Number.NEGATIVE_INFINITY)
33261 minValue : Number.NEGATIVE_INFINITY,
33263 * @cfg {Number} maxValue The maximum allowed value (defaults to Number.MAX_VALUE)
33265 maxValue : Number.MAX_VALUE,
33267 * @cfg {String} minText Error text to display if the minimum value validation fails (defaults to "The minimum value for this field is {minValue}")
33269 minText : "The minimum value for this field is {0}",
33271 * @cfg {String} maxText Error text to display if the maximum value validation fails (defaults to "The maximum value for this field is {maxValue}")
33273 maxText : "The maximum value for this field is {0}",
33275 * @cfg {String} nanText Error text to display if the value is not a valid number. For example, this can happen
33276 * if a valid character like '.' or '-' is left in the field with no number (defaults to "{value} is not a valid number")
33278 nanText : "{0} is not a valid number",
33280 * @cfg {String} thousandsDelimiter Symbol of thousandsDelimiter
33282 thousandsDelimiter : false,
33284 * @cfg {String} valueAlign alignment of value
33286 valueAlign : "left",
33288 getAutoCreate : function()
33290 var hiddenInput = {
33294 cls: 'hidden-number-input'
33298 hiddenInput.name = this.name;
33303 var cfg = Roo.bootstrap.NumberField.superclass.getAutoCreate.call(this);
33305 this.name = hiddenInput.name;
33307 if(cfg.cn.length > 0) {
33308 cfg.cn.push(hiddenInput);
33315 initEvents : function()
33317 Roo.bootstrap.NumberField.superclass.initEvents.call(this);
33319 var allowed = "0123456789";
33321 if(this.allowDecimals){
33322 allowed += this.decimalSeparator;
33325 if(this.allowNegative){
33329 if(this.thousandsDelimiter) {
33333 this.stripCharsRe = new RegExp('[^'+allowed+']', 'gi');
33335 var keyPress = function(e){
33337 var k = e.getKey();
33339 var c = e.getCharCode();
33342 (String.fromCharCode(c) == '.' || String.fromCharCode(c) == '-') &&
33343 allowed.indexOf(String.fromCharCode(c)) === -1
33349 if(!Roo.isIE && (e.isSpecialKey() || k == e.BACKSPACE || k == e.DELETE)){
33353 if(allowed.indexOf(String.fromCharCode(c)) === -1){
33358 this.el.on("keypress", keyPress, this);
33361 validateValue : function(value)
33364 if(!Roo.bootstrap.NumberField.superclass.validateValue.call(this, value)){
33368 var num = this.parseValue(value);
33371 this.markInvalid(String.format(this.nanText, value));
33375 if(num < this.minValue){
33376 this.markInvalid(String.format(this.minText, this.minValue));
33380 if(num > this.maxValue){
33381 this.markInvalid(String.format(this.maxText, this.maxValue));
33388 getValue : function()
33390 var v = this.hiddenEl().getValue();
33392 return this.fixPrecision(this.parseValue(v));
33395 parseValue : function(value)
33397 if(this.thousandsDelimiter) {
33399 r = new RegExp(",", "g");
33400 value = value.replace(r, "");
33403 value = parseFloat(String(value).replace(this.decimalSeparator, "."));
33404 return isNaN(value) ? '' : value;
33407 fixPrecision : function(value)
33409 if(this.thousandsDelimiter) {
33411 r = new RegExp(",", "g");
33412 value = value.replace(r, "");
33415 var nan = isNaN(value);
33417 if(!this.allowDecimals || this.decimalPrecision == -1 || nan || !value){
33418 return nan ? '' : value;
33420 return parseFloat(value).toFixed(this.decimalPrecision);
33423 setValue : function(v)
33425 v = String(this.fixPrecision(v)).replace(".", this.decimalSeparator);
33431 this.hiddenEl().dom.value = (v === null || v === undefined ? '' : v);
33433 this.inputEl().dom.value = (v == '') ? '' :
33434 Roo.util.Format.number(v, this.decimalPrecision, this.thousandsDelimiter || '');
33436 if(!this.allowZero && v === '0') {
33437 this.hiddenEl().dom.value = '';
33438 this.inputEl().dom.value = '';
33445 decimalPrecisionFcn : function(v)
33447 return Math.floor(v);
33450 beforeBlur : function()
33452 var v = this.parseValue(this.getRawValue());
33454 if(v || v === 0 || v === ''){
33459 hiddenEl : function()
33461 return this.el.select('input.hidden-number-input',true).first();
33473 * @class Roo.bootstrap.DocumentSlider
33474 * @extends Roo.bootstrap.Component
33475 * Bootstrap DocumentSlider class
33478 * Create a new DocumentViewer
33479 * @param {Object} config The config object
33482 Roo.bootstrap.DocumentSlider = function(config){
33483 Roo.bootstrap.DocumentSlider.superclass.constructor.call(this, config);
33490 * Fire after initEvent
33491 * @param {Roo.bootstrap.DocumentSlider} this
33496 * Fire after update
33497 * @param {Roo.bootstrap.DocumentSlider} this
33503 * @param {Roo.bootstrap.DocumentSlider} this
33509 Roo.extend(Roo.bootstrap.DocumentSlider, Roo.bootstrap.Component, {
33515 getAutoCreate : function()
33519 cls : 'roo-document-slider',
33523 cls : 'roo-document-slider-header',
33527 cls : 'roo-document-slider-header-title'
33533 cls : 'roo-document-slider-body',
33537 cls : 'roo-document-slider-prev',
33541 cls : 'fa fa-chevron-left'
33547 cls : 'roo-document-slider-thumb',
33551 cls : 'roo-document-slider-image'
33557 cls : 'roo-document-slider-next',
33561 cls : 'fa fa-chevron-right'
33573 initEvents : function()
33575 this.headerEl = this.el.select('.roo-document-slider-header', true).first();
33576 this.headerEl.setVisibilityMode(Roo.Element.DISPLAY);
33578 this.titleEl = this.el.select('.roo-document-slider-header .roo-document-slider-header-title', true).first();
33579 this.titleEl.setVisibilityMode(Roo.Element.DISPLAY);
33581 this.bodyEl = this.el.select('.roo-document-slider-body', true).first();
33582 this.bodyEl.setVisibilityMode(Roo.Element.DISPLAY);
33584 this.thumbEl = this.el.select('.roo-document-slider-thumb', true).first();
33585 this.thumbEl.setVisibilityMode(Roo.Element.DISPLAY);
33587 this.imageEl = this.el.select('.roo-document-slider-image', true).first();
33588 this.imageEl.setVisibilityMode(Roo.Element.DISPLAY);
33590 this.prevIndicator = this.el.select('.roo-document-slider-prev i', true).first();
33591 this.prevIndicator.setVisibilityMode(Roo.Element.DISPLAY);
33593 this.nextIndicator = this.el.select('.roo-document-slider-next i', true).first();
33594 this.nextIndicator.setVisibilityMode(Roo.Element.DISPLAY);
33596 this.thumbEl.on('click', this.onClick, this);
33598 this.prevIndicator.on('click', this.prev, this);
33600 this.nextIndicator.on('click', this.next, this);
33604 initial : function()
33606 if(this.files.length){
33607 this.indicator = 1;
33611 this.fireEvent('initial', this);
33614 update : function()
33616 this.imageEl.attr('src', this.files[this.indicator - 1]);
33618 this.titleEl.dom.innerHTML = String.format('{0} / {1}', this.indicator, this.files.length);
33620 this.prevIndicator.show();
33622 if(this.indicator == 1){
33623 this.prevIndicator.hide();
33626 this.nextIndicator.show();
33628 if(this.indicator == this.files.length){
33629 this.nextIndicator.hide();
33632 this.thumbEl.scrollTo('top');
33634 this.fireEvent('update', this);
33637 onClick : function(e)
33639 e.preventDefault();
33641 this.fireEvent('click', this);
33646 e.preventDefault();
33648 this.indicator = Math.max(1, this.indicator - 1);
33655 e.preventDefault();
33657 this.indicator = Math.min(this.files.length, this.indicator + 1);
33671 * @class Roo.bootstrap.RadioSet
33672 * @extends Roo.bootstrap.Input
33673 * Bootstrap RadioSet class
33674 * @cfg {String} indicatorpos (left|right) default left
33675 * @cfg {Boolean} inline (true|false) inline the element (default true)
33676 * @cfg {String} weight (primary|warning|info|danger|success) The text that appears beside the radio
33678 * Create a new RadioSet
33679 * @param {Object} config The config object
33682 Roo.bootstrap.RadioSet = function(config){
33684 Roo.bootstrap.RadioSet.superclass.constructor.call(this, config);
33688 Roo.bootstrap.RadioSet.register(this);
33693 * Fires when the element is checked or unchecked.
33694 * @param {Roo.bootstrap.RadioSet} this This radio
33695 * @param {Roo.bootstrap.Radio} item The checked item
33700 * Fires when the element is click.
33701 * @param {Roo.bootstrap.RadioSet} this This radio set
33702 * @param {Roo.bootstrap.Radio} item The checked item
33703 * @param {Roo.EventObject} e The event object
33710 Roo.extend(Roo.bootstrap.RadioSet, Roo.bootstrap.Input, {
33718 indicatorpos : 'left',
33720 getAutoCreate : function()
33724 cls : 'roo-radio-set-label',
33728 html : this.fieldLabel
33733 if(this.indicatorpos == 'left'){
33736 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
33737 tooltip : 'This field is required'
33742 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
33743 tooltip : 'This field is required'
33749 cls : 'roo-radio-set-items'
33752 var align = (!this.labelAlign) ? this.parentLabelAlign() : this.labelAlign;
33754 if (align === 'left' && this.fieldLabel.length) {
33757 cls : "roo-radio-set-right",
33763 if(this.labelWidth > 12){
33764 label.style = "width: " + this.labelWidth + 'px';
33767 if(this.labelWidth < 13 && this.labelmd == 0){
33768 this.labelmd = this.labelWidth;
33771 if(this.labellg > 0){
33772 label.cls += ' col-lg-' + this.labellg;
33773 items.cls += ' col-lg-' + (12 - this.labellg);
33776 if(this.labelmd > 0){
33777 label.cls += ' col-md-' + this.labelmd;
33778 items.cls += ' col-md-' + (12 - this.labelmd);
33781 if(this.labelsm > 0){
33782 label.cls += ' col-sm-' + this.labelsm;
33783 items.cls += ' col-sm-' + (12 - this.labelsm);
33786 if(this.labelxs > 0){
33787 label.cls += ' col-xs-' + this.labelxs;
33788 items.cls += ' col-xs-' + (12 - this.labelxs);
33794 cls : 'roo-radio-set',
33798 cls : 'roo-radio-set-input',
33801 value : this.value ? this.value : ''
33808 if(this.weight.length){
33809 cfg.cls += ' roo-radio-' + this.weight;
33813 cfg.cls += ' roo-radio-set-inline';
33817 ['xs','sm','md','lg'].map(function(size){
33818 if (settings[size]) {
33819 cfg.cls += ' col-' + size + '-' + settings[size];
33827 initEvents : function()
33829 this.labelEl = this.el.select('.roo-radio-set-label', true).first();
33830 this.labelEl.setVisibilityMode(Roo.Element.DISPLAY);
33832 if(!this.fieldLabel.length){
33833 this.labelEl.hide();
33836 this.itemsEl = this.el.select('.roo-radio-set-items', true).first();
33837 this.itemsEl.setVisibilityMode(Roo.Element.DISPLAY);
33839 this.indicator = this.indicatorEl();
33841 if(this.indicator){
33842 this.indicator.addClass('invisible');
33845 this.originalValue = this.getValue();
33849 inputEl: function ()
33851 return this.el.select('.roo-radio-set-input', true).first();
33854 getChildContainer : function()
33856 return this.itemsEl;
33859 register : function(item)
33861 this.radioes.push(item);
33865 validate : function()
33867 if(this.getVisibilityEl().hasClass('hidden')){
33873 Roo.each(this.radioes, function(i){
33882 if(this.allowBlank) {
33886 if(this.disabled || valid){
33891 this.markInvalid();
33896 markValid : function()
33898 if(this.labelEl.isVisible(true)){
33899 this.indicatorEl().removeClass('visible');
33900 this.indicatorEl().addClass('invisible');
33903 this.el.removeClass([this.invalidClass, this.validClass]);
33904 this.el.addClass(this.validClass);
33906 this.fireEvent('valid', this);
33909 markInvalid : function(msg)
33911 if(this.allowBlank || this.disabled){
33915 if(this.labelEl.isVisible(true)){
33916 this.indicatorEl().removeClass('invisible');
33917 this.indicatorEl().addClass('visible');
33920 this.el.removeClass([this.invalidClass, this.validClass]);
33921 this.el.addClass(this.invalidClass);
33923 this.fireEvent('invalid', this, msg);
33927 setValue : function(v, suppressEvent)
33929 if(this.value === v){
33936 this.inputEl().dom.value = (v === null || v === undefined ? '' : v);
33939 Roo.each(this.radioes, function(i){
33941 i.el.removeClass('checked');
33944 Roo.each(this.radioes, function(i){
33946 if(i.value === v || i.value.toString() === v.toString()){
33948 i.el.addClass('checked');
33950 if(suppressEvent !== true){
33951 this.fireEvent('check', this, i);
33962 clearInvalid : function(){
33964 if(!this.el || this.preventMark){
33968 this.el.removeClass([this.invalidClass]);
33970 this.fireEvent('valid', this);
33975 Roo.apply(Roo.bootstrap.RadioSet, {
33979 register : function(set)
33981 this.groups[set.name] = set;
33984 get: function(name)
33986 if (typeof(this.groups[name]) == 'undefined') {
33990 return this.groups[name] ;
33996 * Ext JS Library 1.1.1
33997 * Copyright(c) 2006-2007, Ext JS, LLC.
33999 * Originally Released Under LGPL - original licence link has changed is not relivant.
34002 * <script type="text/javascript">
34007 * @class Roo.bootstrap.SplitBar
34008 * @extends Roo.util.Observable
34009 * Creates draggable splitter bar functionality from two elements (element to be dragged and element to be resized).
34013 var split = new Roo.bootstrap.SplitBar("elementToDrag", "elementToSize",
34014 Roo.bootstrap.SplitBar.HORIZONTAL, Roo.bootstrap.SplitBar.LEFT);
34015 split.setAdapter(new Roo.bootstrap.SplitBar.AbsoluteLayoutAdapter("container"));
34016 split.minSize = 100;
34017 split.maxSize = 600;
34018 split.animate = true;
34019 split.on('moved', splitterMoved);
34022 * Create a new SplitBar
34023 * @config {String/HTMLElement/Roo.Element} dragElement The element to be dragged and act as the SplitBar.
34024 * @config {String/HTMLElement/Roo.Element} resizingElement The element to be resized based on where the SplitBar element is dragged
34025 * @config {Number} orientation (optional) Either Roo.bootstrap.SplitBar.HORIZONTAL or Roo.bootstrap.SplitBar.VERTICAL. (Defaults to HORIZONTAL)
34026 * @config {Number} placement (optional) Either Roo.bootstrap.SplitBar.LEFT or Roo.bootstrap.SplitBar.RIGHT for horizontal or
34027 Roo.bootstrap.SplitBar.TOP or Roo.bootstrap.SplitBar.BOTTOM for vertical. (By default, this is determined automatically by the initial
34028 position of the SplitBar).
34030 Roo.bootstrap.SplitBar = function(cfg){
34035 // dragElement : elm
34036 // resizingElement: el,
34038 // orientation : Either Roo.bootstrap.SplitBar.HORIZONTAL
34039 // placement : Roo.bootstrap.SplitBar.LEFT ,
34040 // existingProxy ???
34043 this.el = Roo.get(cfg.dragElement, true);
34044 this.el.dom.unselectable = "on";
34046 this.resizingEl = Roo.get(cfg.resizingElement, true);
34050 * The orientation of the split. Either Roo.bootstrap.SplitBar.HORIZONTAL or Roo.bootstrap.SplitBar.VERTICAL. (Defaults to HORIZONTAL)
34051 * Note: If this is changed after creating the SplitBar, the placement property must be manually updated
34054 this.orientation = cfg.orientation || Roo.bootstrap.SplitBar.HORIZONTAL;
34057 * The minimum size of the resizing element. (Defaults to 0)
34063 * The maximum size of the resizing element. (Defaults to 2000)
34066 this.maxSize = 2000;
34069 * Whether to animate the transition to the new size
34072 this.animate = false;
34075 * Whether to create a transparent shim that overlays the page when dragging, enables dragging across iframes.
34078 this.useShim = false;
34083 if(!cfg.existingProxy){
34085 this.proxy = Roo.bootstrap.SplitBar.createProxy(this.orientation);
34087 this.proxy = Roo.get(cfg.existingProxy).dom;
34090 this.dd = new Roo.dd.DDProxy(this.el.dom.id, "XSplitBars", {dragElId : this.proxy.id});
34093 this.dd.b4StartDrag = this.onStartProxyDrag.createDelegate(this);
34096 this.dd.endDrag = this.onEndProxyDrag.createDelegate(this);
34099 this.dragSpecs = {};
34102 * @private The adapter to use to positon and resize elements
34104 this.adapter = new Roo.bootstrap.SplitBar.BasicLayoutAdapter();
34105 this.adapter.init(this);
34107 if(this.orientation == Roo.bootstrap.SplitBar.HORIZONTAL){
34109 this.placement = cfg.placement || (this.el.getX() > this.resizingEl.getX() ? Roo.bootstrap.SplitBar.LEFT : Roo.bootstrap.SplitBar.RIGHT);
34110 this.el.addClass("roo-splitbar-h");
34113 this.placement = cfg.placement || (this.el.getY() > this.resizingEl.getY() ? Roo.bootstrap.SplitBar.TOP : Roo.bootstrap.SplitBar.BOTTOM);
34114 this.el.addClass("roo-splitbar-v");
34120 * Fires when the splitter is moved (alias for {@link #event-moved})
34121 * @param {Roo.bootstrap.SplitBar} this
34122 * @param {Number} newSize the new width or height
34127 * Fires when the splitter is moved
34128 * @param {Roo.bootstrap.SplitBar} this
34129 * @param {Number} newSize the new width or height
34133 * @event beforeresize
34134 * Fires before the splitter is dragged
34135 * @param {Roo.bootstrap.SplitBar} this
34137 "beforeresize" : true,
34139 "beforeapply" : true
34142 Roo.util.Observable.call(this);
34145 Roo.extend(Roo.bootstrap.SplitBar, Roo.util.Observable, {
34146 onStartProxyDrag : function(x, y){
34147 this.fireEvent("beforeresize", this);
34149 var o = Roo.DomHelper.insertFirst(document.body, {cls: "roo-drag-overlay", html: " "}, true);
34151 o.enableDisplayMode("block");
34152 // all splitbars share the same overlay
34153 Roo.bootstrap.SplitBar.prototype.overlay = o;
34155 this.overlay.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
34156 this.overlay.show();
34157 Roo.get(this.proxy).setDisplayed("block");
34158 var size = this.adapter.getElementSize(this);
34159 this.activeMinSize = this.getMinimumSize();;
34160 this.activeMaxSize = this.getMaximumSize();;
34161 var c1 = size - this.activeMinSize;
34162 var c2 = Math.max(this.activeMaxSize - size, 0);
34163 if(this.orientation == Roo.bootstrap.SplitBar.HORIZONTAL){
34164 this.dd.resetConstraints();
34165 this.dd.setXConstraint(
34166 this.placement == Roo.bootstrap.SplitBar.LEFT ? c1 : c2,
34167 this.placement == Roo.bootstrap.SplitBar.LEFT ? c2 : c1
34169 this.dd.setYConstraint(0, 0);
34171 this.dd.resetConstraints();
34172 this.dd.setXConstraint(0, 0);
34173 this.dd.setYConstraint(
34174 this.placement == Roo.bootstrap.SplitBar.TOP ? c1 : c2,
34175 this.placement == Roo.bootstrap.SplitBar.TOP ? c2 : c1
34178 this.dragSpecs.startSize = size;
34179 this.dragSpecs.startPoint = [x, y];
34180 Roo.dd.DDProxy.prototype.b4StartDrag.call(this.dd, x, y);
34184 * @private Called after the drag operation by the DDProxy
34186 onEndProxyDrag : function(e){
34187 Roo.get(this.proxy).setDisplayed(false);
34188 var endPoint = Roo.lib.Event.getXY(e);
34190 this.overlay.hide();
34193 if(this.orientation == Roo.bootstrap.SplitBar.HORIZONTAL){
34194 newSize = this.dragSpecs.startSize +
34195 (this.placement == Roo.bootstrap.SplitBar.LEFT ?
34196 endPoint[0] - this.dragSpecs.startPoint[0] :
34197 this.dragSpecs.startPoint[0] - endPoint[0]
34200 newSize = this.dragSpecs.startSize +
34201 (this.placement == Roo.bootstrap.SplitBar.TOP ?
34202 endPoint[1] - this.dragSpecs.startPoint[1] :
34203 this.dragSpecs.startPoint[1] - endPoint[1]
34206 newSize = Math.min(Math.max(newSize, this.activeMinSize), this.activeMaxSize);
34207 if(newSize != this.dragSpecs.startSize){
34208 if(this.fireEvent('beforeapply', this, newSize) !== false){
34209 this.adapter.setElementSize(this, newSize);
34210 this.fireEvent("moved", this, newSize);
34211 this.fireEvent("resize", this, newSize);
34217 * Get the adapter this SplitBar uses
34218 * @return The adapter object
34220 getAdapter : function(){
34221 return this.adapter;
34225 * Set the adapter this SplitBar uses
34226 * @param {Object} adapter A SplitBar adapter object
34228 setAdapter : function(adapter){
34229 this.adapter = adapter;
34230 this.adapter.init(this);
34234 * Gets the minimum size for the resizing element
34235 * @return {Number} The minimum size
34237 getMinimumSize : function(){
34238 return this.minSize;
34242 * Sets the minimum size for the resizing element
34243 * @param {Number} minSize The minimum size
34245 setMinimumSize : function(minSize){
34246 this.minSize = minSize;
34250 * Gets the maximum size for the resizing element
34251 * @return {Number} The maximum size
34253 getMaximumSize : function(){
34254 return this.maxSize;
34258 * Sets the maximum size for the resizing element
34259 * @param {Number} maxSize The maximum size
34261 setMaximumSize : function(maxSize){
34262 this.maxSize = maxSize;
34266 * Sets the initialize size for the resizing element
34267 * @param {Number} size The initial size
34269 setCurrentSize : function(size){
34270 var oldAnimate = this.animate;
34271 this.animate = false;
34272 this.adapter.setElementSize(this, size);
34273 this.animate = oldAnimate;
34277 * Destroy this splitbar.
34278 * @param {Boolean} removeEl True to remove the element
34280 destroy : function(removeEl){
34282 this.shim.remove();
34285 this.proxy.parentNode.removeChild(this.proxy);
34293 * @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.
34295 Roo.bootstrap.SplitBar.createProxy = function(dir){
34296 var proxy = new Roo.Element(document.createElement("div"));
34297 proxy.unselectable();
34298 var cls = 'roo-splitbar-proxy';
34299 proxy.addClass(cls + ' ' + (dir == Roo.bootstrap.SplitBar.HORIZONTAL ? cls +'-h' : cls + '-v'));
34300 document.body.appendChild(proxy.dom);
34305 * @class Roo.bootstrap.SplitBar.BasicLayoutAdapter
34306 * Default Adapter. It assumes the splitter and resizing element are not positioned
34307 * elements and only gets/sets the width of the element. Generally used for table based layouts.
34309 Roo.bootstrap.SplitBar.BasicLayoutAdapter = function(){
34312 Roo.bootstrap.SplitBar.BasicLayoutAdapter.prototype = {
34313 // do nothing for now
34314 init : function(s){
34318 * Called before drag operations to get the current size of the resizing element.
34319 * @param {Roo.bootstrap.SplitBar} s The SplitBar using this adapter
34321 getElementSize : function(s){
34322 if(s.orientation == Roo.bootstrap.SplitBar.HORIZONTAL){
34323 return s.resizingEl.getWidth();
34325 return s.resizingEl.getHeight();
34330 * Called after drag operations to set the size of the resizing element.
34331 * @param {Roo.bootstrap.SplitBar} s The SplitBar using this adapter
34332 * @param {Number} newSize The new size to set
34333 * @param {Function} onComplete A function to be invoked when resizing is complete
34335 setElementSize : function(s, newSize, onComplete){
34336 if(s.orientation == Roo.bootstrap.SplitBar.HORIZONTAL){
34338 s.resizingEl.setWidth(newSize);
34340 onComplete(s, newSize);
34343 s.resizingEl.setWidth(newSize, true, .1, onComplete, 'easeOut');
34348 s.resizingEl.setHeight(newSize);
34350 onComplete(s, newSize);
34353 s.resizingEl.setHeight(newSize, true, .1, onComplete, 'easeOut');
34360 *@class Roo.bootstrap.SplitBar.AbsoluteLayoutAdapter
34361 * @extends Roo.bootstrap.SplitBar.BasicLayoutAdapter
34362 * Adapter that moves the splitter element to align with the resized sizing element.
34363 * Used with an absolute positioned SplitBar.
34364 * @param {String/HTMLElement/Roo.Element} container The container that wraps around the absolute positioned content. If it's
34365 * document.body, make sure you assign an id to the body element.
34367 Roo.bootstrap.SplitBar.AbsoluteLayoutAdapter = function(container){
34368 this.basic = new Roo.bootstrap.SplitBar.BasicLayoutAdapter();
34369 this.container = Roo.get(container);
34372 Roo.bootstrap.SplitBar.AbsoluteLayoutAdapter.prototype = {
34373 init : function(s){
34374 this.basic.init(s);
34377 getElementSize : function(s){
34378 return this.basic.getElementSize(s);
34381 setElementSize : function(s, newSize, onComplete){
34382 this.basic.setElementSize(s, newSize, this.moveSplitter.createDelegate(this, [s]));
34385 moveSplitter : function(s){
34386 var yes = Roo.bootstrap.SplitBar;
34387 switch(s.placement){
34389 s.el.setX(s.resizingEl.getRight());
34392 s.el.setStyle("right", (this.container.getWidth() - s.resizingEl.getLeft()) + "px");
34395 s.el.setY(s.resizingEl.getBottom());
34398 s.el.setY(s.resizingEl.getTop() - s.el.getHeight());
34405 * Orientation constant - Create a vertical SplitBar
34409 Roo.bootstrap.SplitBar.VERTICAL = 1;
34412 * Orientation constant - Create a horizontal SplitBar
34416 Roo.bootstrap.SplitBar.HORIZONTAL = 2;
34419 * Placement constant - The resizing element is to the left of the splitter element
34423 Roo.bootstrap.SplitBar.LEFT = 1;
34426 * Placement constant - The resizing element is to the right of the splitter element
34430 Roo.bootstrap.SplitBar.RIGHT = 2;
34433 * Placement constant - The resizing element is positioned above the splitter element
34437 Roo.bootstrap.SplitBar.TOP = 3;
34440 * Placement constant - The resizing element is positioned under splitter element
34444 Roo.bootstrap.SplitBar.BOTTOM = 4;
34445 Roo.namespace("Roo.bootstrap.layout");/*
34447 * Ext JS Library 1.1.1
34448 * Copyright(c) 2006-2007, Ext JS, LLC.
34450 * Originally Released Under LGPL - original licence link has changed is not relivant.
34453 * <script type="text/javascript">
34457 * @class Roo.bootstrap.layout.Manager
34458 * @extends Roo.bootstrap.Component
34459 * Base class for layout managers.
34461 Roo.bootstrap.layout.Manager = function(config)
34463 Roo.bootstrap.layout.Manager.superclass.constructor.call(this,config);
34469 /** false to disable window resize monitoring @type Boolean */
34470 this.monitorWindowResize = true;
34475 * Fires when a layout is performed.
34476 * @param {Roo.LayoutManager} this
34480 * @event regionresized
34481 * Fires when the user resizes a region.
34482 * @param {Roo.LayoutRegion} region The resized region
34483 * @param {Number} newSize The new size (width for east/west, height for north/south)
34485 "regionresized" : true,
34487 * @event regioncollapsed
34488 * Fires when a region is collapsed.
34489 * @param {Roo.LayoutRegion} region The collapsed region
34491 "regioncollapsed" : true,
34493 * @event regionexpanded
34494 * Fires when a region is expanded.
34495 * @param {Roo.LayoutRegion} region The expanded region
34497 "regionexpanded" : true
34499 this.updating = false;
34502 this.el = Roo.get(config.el);
34508 Roo.extend(Roo.bootstrap.layout.Manager, Roo.bootstrap.Component, {
34513 monitorWindowResize : true,
34519 onRender : function(ct, position)
34522 this.el = Roo.get(ct);
34525 //this.fireEvent('render',this);
34529 initEvents: function()
34533 // ie scrollbar fix
34534 if(this.el.dom == document.body && Roo.isIE && !config.allowScroll){
34535 document.body.scroll = "no";
34536 }else if(this.el.dom != document.body && this.el.getStyle('position') == 'static'){
34537 this.el.position('relative');
34539 this.id = this.el.id;
34540 this.el.addClass("roo-layout-container");
34541 Roo.EventManager.onWindowResize(this.onWindowResize, this, true);
34542 if(this.el.dom != document.body ) {
34543 this.el.on('resize', this.layout,this);
34544 this.el.on('show', this.layout,this);
34550 * Returns true if this layout is currently being updated
34551 * @return {Boolean}
34553 isUpdating : function(){
34554 return this.updating;
34558 * Suspend the LayoutManager from doing auto-layouts while
34559 * making multiple add or remove calls
34561 beginUpdate : function(){
34562 this.updating = true;
34566 * Restore auto-layouts and optionally disable the manager from performing a layout
34567 * @param {Boolean} noLayout true to disable a layout update
34569 endUpdate : function(noLayout){
34570 this.updating = false;
34576 layout: function(){
34580 onRegionResized : function(region, newSize){
34581 this.fireEvent("regionresized", region, newSize);
34585 onRegionCollapsed : function(region){
34586 this.fireEvent("regioncollapsed", region);
34589 onRegionExpanded : function(region){
34590 this.fireEvent("regionexpanded", region);
34594 * Returns the size of the current view. This method normalizes document.body and element embedded layouts and
34595 * performs box-model adjustments.
34596 * @return {Object} The size as an object {width: (the width), height: (the height)}
34598 getViewSize : function()
34601 if(this.el.dom != document.body){
34602 size = this.el.getSize();
34604 size = {width: Roo.lib.Dom.getViewWidth(), height: Roo.lib.Dom.getViewHeight()};
34606 size.width -= this.el.getBorderWidth("lr")-this.el.getPadding("lr");
34607 size.height -= this.el.getBorderWidth("tb")-this.el.getPadding("tb");
34612 * Returns the Element this layout is bound to.
34613 * @return {Roo.Element}
34615 getEl : function(){
34620 * Returns the specified region.
34621 * @param {String} target The region key ('center', 'north', 'south', 'east' or 'west')
34622 * @return {Roo.LayoutRegion}
34624 getRegion : function(target){
34625 return this.regions[target.toLowerCase()];
34628 onWindowResize : function(){
34629 if(this.monitorWindowResize){
34636 * Ext JS Library 1.1.1
34637 * Copyright(c) 2006-2007, Ext JS, LLC.
34639 * Originally Released Under LGPL - original licence link has changed is not relivant.
34642 * <script type="text/javascript">
34645 * @class Roo.bootstrap.layout.Border
34646 * @extends Roo.bootstrap.layout.Manager
34647 * This class represents a common layout manager used in desktop applications. For screenshots and more details,
34648 * please see: examples/bootstrap/nested.html<br><br>
34650 <b>The container the layout is rendered into can be either the body element or any other element.
34651 If it is not the body element, the container needs to either be an absolute positioned element,
34652 or you will need to add "position:relative" to the css of the container. You will also need to specify
34653 the container size if it is not the body element.</b>
34656 * Create a new Border
34657 * @param {Object} config Configuration options
34659 Roo.bootstrap.layout.Border = function(config){
34660 config = config || {};
34661 Roo.bootstrap.layout.Border.superclass.constructor.call(this, config);
34665 Roo.each(Roo.bootstrap.layout.Border.regions, function(region) {
34666 if(config[region]){
34667 config[region].region = region;
34668 this.addRegion(config[region]);
34674 Roo.bootstrap.layout.Border.regions = ["north","south","east","west","center"];
34676 Roo.extend(Roo.bootstrap.layout.Border, Roo.bootstrap.layout.Manager, {
34678 * Creates and adds a new region if it doesn't already exist.
34679 * @param {String} target The target region key (north, south, east, west or center).
34680 * @param {Object} config The regions config object
34681 * @return {BorderLayoutRegion} The new region
34683 addRegion : function(config)
34685 if(!this.regions[config.region]){
34686 var r = this.factory(config);
34687 this.bindRegion(r);
34689 return this.regions[config.region];
34693 bindRegion : function(r){
34694 this.regions[r.config.region] = r;
34696 r.on("visibilitychange", this.layout, this);
34697 r.on("paneladded", this.layout, this);
34698 r.on("panelremoved", this.layout, this);
34699 r.on("invalidated", this.layout, this);
34700 r.on("resized", this.onRegionResized, this);
34701 r.on("collapsed", this.onRegionCollapsed, this);
34702 r.on("expanded", this.onRegionExpanded, this);
34706 * Performs a layout update.
34708 layout : function()
34710 if(this.updating) {
34714 // render all the rebions if they have not been done alreayd?
34715 Roo.each(Roo.bootstrap.layout.Border.regions, function(region) {
34716 if(this.regions[region] && !this.regions[region].bodyEl){
34717 this.regions[region].onRender(this.el)
34721 var size = this.getViewSize();
34722 var w = size.width;
34723 var h = size.height;
34728 //var x = 0, y = 0;
34730 var rs = this.regions;
34731 var north = rs["north"];
34732 var south = rs["south"];
34733 var west = rs["west"];
34734 var east = rs["east"];
34735 var center = rs["center"];
34736 //if(this.hideOnLayout){ // not supported anymore
34737 //c.el.setStyle("display", "none");
34739 if(north && north.isVisible()){
34740 var b = north.getBox();
34741 var m = north.getMargins();
34742 b.width = w - (m.left+m.right);
34745 centerY = b.height + b.y + m.bottom;
34746 centerH -= centerY;
34747 north.updateBox(this.safeBox(b));
34749 if(south && south.isVisible()){
34750 var b = south.getBox();
34751 var m = south.getMargins();
34752 b.width = w - (m.left+m.right);
34754 var totalHeight = (b.height + m.top + m.bottom);
34755 b.y = h - totalHeight + m.top;
34756 centerH -= totalHeight;
34757 south.updateBox(this.safeBox(b));
34759 if(west && west.isVisible()){
34760 var b = west.getBox();
34761 var m = west.getMargins();
34762 b.height = centerH - (m.top+m.bottom);
34764 b.y = centerY + m.top;
34765 var totalWidth = (b.width + m.left + m.right);
34766 centerX += totalWidth;
34767 centerW -= totalWidth;
34768 west.updateBox(this.safeBox(b));
34770 if(east && east.isVisible()){
34771 var b = east.getBox();
34772 var m = east.getMargins();
34773 b.height = centerH - (m.top+m.bottom);
34774 var totalWidth = (b.width + m.left + m.right);
34775 b.x = w - totalWidth + m.left;
34776 b.y = centerY + m.top;
34777 centerW -= totalWidth;
34778 east.updateBox(this.safeBox(b));
34781 var m = center.getMargins();
34783 x: centerX + m.left,
34784 y: centerY + m.top,
34785 width: centerW - (m.left+m.right),
34786 height: centerH - (m.top+m.bottom)
34788 //if(this.hideOnLayout){
34789 //center.el.setStyle("display", "block");
34791 center.updateBox(this.safeBox(centerBox));
34794 this.fireEvent("layout", this);
34798 safeBox : function(box){
34799 box.width = Math.max(0, box.width);
34800 box.height = Math.max(0, box.height);
34805 * Adds a ContentPanel (or subclass) to this layout.
34806 * @param {String} target The target region key (north, south, east, west or center).
34807 * @param {Roo.ContentPanel} panel The panel to add
34808 * @return {Roo.ContentPanel} The added panel
34810 add : function(target, panel){
34812 target = target.toLowerCase();
34813 return this.regions[target].add(panel);
34817 * Remove a ContentPanel (or subclass) to this layout.
34818 * @param {String} target The target region key (north, south, east, west or center).
34819 * @param {Number/String/Roo.ContentPanel} panel The index, id or panel to remove
34820 * @return {Roo.ContentPanel} The removed panel
34822 remove : function(target, panel){
34823 target = target.toLowerCase();
34824 return this.regions[target].remove(panel);
34828 * Searches all regions for a panel with the specified id
34829 * @param {String} panelId
34830 * @return {Roo.ContentPanel} The panel or null if it wasn't found
34832 findPanel : function(panelId){
34833 var rs = this.regions;
34834 for(var target in rs){
34835 if(typeof rs[target] != "function"){
34836 var p = rs[target].getPanel(panelId);
34846 * Searches all regions for a panel with the specified id and activates (shows) it.
34847 * @param {String/ContentPanel} panelId The panels id or the panel itself
34848 * @return {Roo.ContentPanel} The shown panel or null
34850 showPanel : function(panelId) {
34851 var rs = this.regions;
34852 for(var target in rs){
34853 var r = rs[target];
34854 if(typeof r != "function"){
34855 if(r.hasPanel(panelId)){
34856 return r.showPanel(panelId);
34864 * Restores this layout's state using Roo.state.Manager or the state provided by the passed provider.
34865 * @param {Roo.state.Provider} provider (optional) An alternate state provider
34868 restoreState : function(provider){
34870 provider = Roo.state.Manager;
34872 var sm = new Roo.LayoutStateManager();
34873 sm.init(this, provider);
34879 * Adds a xtype elements to the layout.
34883 xtype : 'ContentPanel',
34890 xtype : 'NestedLayoutPanel',
34896 items : [ ... list of content panels or nested layout panels.. ]
34900 * @param {Object} cfg Xtype definition of item to add.
34902 addxtype : function(cfg)
34904 // basically accepts a pannel...
34905 // can accept a layout region..!?!?
34906 //Roo.log('Roo.BorderLayout add ' + cfg.xtype)
34909 // theory? children can only be panels??
34911 //if (!cfg.xtype.match(/Panel$/)) {
34916 if (typeof(cfg.region) == 'undefined') {
34917 Roo.log("Failed to add Panel, region was not set");
34921 var region = cfg.region;
34927 xitems = cfg.items;
34934 case 'Content': // ContentPanel (el, cfg)
34935 case 'Scroll': // ContentPanel (el, cfg)
34937 cfg.autoCreate = true;
34938 ret = new cfg.xns[cfg.xtype](cfg); // new panel!!!!!
34940 // var el = this.el.createChild();
34941 // ret = new Roo[cfg.xtype](el, cfg); // new panel!!!!!
34944 this.add(region, ret);
34948 case 'TreePanel': // our new panel!
34949 cfg.el = this.el.createChild();
34950 ret = new Roo[cfg.xtype](cfg); // new panel!!!!!
34951 this.add(region, ret);
34956 // create a new Layout (which is a Border Layout...
34958 var clayout = cfg.layout;
34959 clayout.el = this.el.createChild();
34960 clayout.items = clayout.items || [];
34964 // replace this exitems with the clayout ones..
34965 xitems = clayout.items;
34967 // force background off if it's in center...
34968 if (region == 'center' && this.active && this.getRegion('center').panels.length < 1) {
34969 cfg.background = false;
34971 cfg.layout = new Roo.bootstrap.layout.Border(clayout);
34974 ret = new cfg.xns[cfg.xtype](cfg); // new panel!!!!!
34975 //console.log('adding nested layout panel ' + cfg.toSource());
34976 this.add(region, ret);
34977 nb = {}; /// find first...
34982 // needs grid and region
34984 //var el = this.getRegion(region).el.createChild();
34986 *var el = this.el.createChild();
34987 // create the grid first...
34988 cfg.grid.container = el;
34989 cfg.grid = new cfg.grid.xns[cfg.grid.xtype](cfg.grid);
34992 if (region == 'center' && this.active ) {
34993 cfg.background = false;
34996 ret = new cfg.xns[cfg.xtype](cfg); // new panel!!!!!
34998 this.add(region, ret);
35000 if (cfg.background) {
35001 // render grid on panel activation (if panel background)
35002 ret.on('activate', function(gp) {
35003 if (!gp.grid.rendered) {
35004 // gp.grid.render(el);
35008 // cfg.grid.render(el);
35014 case 'Border': // it can get called on it'self... - might need to check if this is fixed?
35015 // it was the old xcomponent building that caused this before.
35016 // espeically if border is the top element in the tree.
35026 if (typeof(Roo[cfg.xtype]) != 'undefined') {
35028 ret = new Roo[cfg.xtype](cfg); // new panel!!!!!
35029 this.add(region, ret);
35033 throw "Can not add '" + cfg.xtype + "' to Border";
35039 this.beginUpdate();
35043 Roo.each(xitems, function(i) {
35044 region = nb && i.region ? i.region : false;
35046 var add = ret.addxtype(i);
35049 nb[region] = nb[region] == undefined ? 0 : nb[region]+1;
35050 if (!i.background) {
35051 abn[region] = nb[region] ;
35058 // make the last non-background panel active..
35059 //if (nb) { Roo.log(abn); }
35062 for(var r in abn) {
35063 region = this.getRegion(r);
35065 // tried using nb[r], but it does not work..
35067 region.showPanel(abn[r]);
35078 factory : function(cfg)
35081 var validRegions = Roo.bootstrap.layout.Border.regions;
35083 var target = cfg.region;
35086 var r = Roo.bootstrap.layout;
35090 return new r.North(cfg);
35092 return new r.South(cfg);
35094 return new r.East(cfg);
35096 return new r.West(cfg);
35098 return new r.Center(cfg);
35100 throw 'Layout region "'+target+'" not supported.';
35107 * Ext JS Library 1.1.1
35108 * Copyright(c) 2006-2007, Ext JS, LLC.
35110 * Originally Released Under LGPL - original licence link has changed is not relivant.
35113 * <script type="text/javascript">
35117 * @class Roo.bootstrap.layout.Basic
35118 * @extends Roo.util.Observable
35119 * This class represents a lightweight region in a layout manager. This region does not move dom nodes
35120 * and does not have a titlebar, tabs or any other features. All it does is size and position
35121 * panels. To create a BasicLayoutRegion, add lightweight:true or basic:true to your regions config.
35122 * @cfg {Roo.bootstrap.layout.Manager} mgr The manager
35123 * @cfg {string} region the region that it inhabits..
35124 * @cfg {bool} skipConfig skip config?
35128 Roo.bootstrap.layout.Basic = function(config){
35130 this.mgr = config.mgr;
35132 this.position = config.region;
35134 var skipConfig = config.skipConfig;
35138 * @scope Roo.BasicLayoutRegion
35142 * @event beforeremove
35143 * Fires before a panel is removed (or closed). To cancel the removal set "e.cancel = true" on the event argument.
35144 * @param {Roo.LayoutRegion} this
35145 * @param {Roo.ContentPanel} panel The panel
35146 * @param {Object} e The cancel event object
35148 "beforeremove" : true,
35150 * @event invalidated
35151 * Fires when the layout for this region is changed.
35152 * @param {Roo.LayoutRegion} this
35154 "invalidated" : true,
35156 * @event visibilitychange
35157 * Fires when this region is shown or hidden
35158 * @param {Roo.LayoutRegion} this
35159 * @param {Boolean} visibility true or false
35161 "visibilitychange" : true,
35163 * @event paneladded
35164 * Fires when a panel is added.
35165 * @param {Roo.LayoutRegion} this
35166 * @param {Roo.ContentPanel} panel The panel
35168 "paneladded" : true,
35170 * @event panelremoved
35171 * Fires when a panel is removed.
35172 * @param {Roo.LayoutRegion} this
35173 * @param {Roo.ContentPanel} panel The panel
35175 "panelremoved" : true,
35177 * @event beforecollapse
35178 * Fires when this region before collapse.
35179 * @param {Roo.LayoutRegion} this
35181 "beforecollapse" : true,
35184 * Fires when this region is collapsed.
35185 * @param {Roo.LayoutRegion} this
35187 "collapsed" : true,
35190 * Fires when this region is expanded.
35191 * @param {Roo.LayoutRegion} this
35196 * Fires when this region is slid into view.
35197 * @param {Roo.LayoutRegion} this
35199 "slideshow" : true,
35202 * Fires when this region slides out of view.
35203 * @param {Roo.LayoutRegion} this
35205 "slidehide" : true,
35207 * @event panelactivated
35208 * Fires when a panel is activated.
35209 * @param {Roo.LayoutRegion} this
35210 * @param {Roo.ContentPanel} panel The activated panel
35212 "panelactivated" : true,
35215 * Fires when the user resizes this region.
35216 * @param {Roo.LayoutRegion} this
35217 * @param {Number} newSize The new size (width for east/west, height for north/south)
35221 /** A collection of panels in this region. @type Roo.util.MixedCollection */
35222 this.panels = new Roo.util.MixedCollection();
35223 this.panels.getKey = this.getPanelId.createDelegate(this);
35225 this.activePanel = null;
35226 // ensure listeners are added...
35228 if (config.listeners || config.events) {
35229 Roo.bootstrap.layout.Basic.superclass.constructor.call(this, {
35230 listeners : config.listeners || {},
35231 events : config.events || {}
35235 if(skipConfig !== true){
35236 this.applyConfig(config);
35240 Roo.extend(Roo.bootstrap.layout.Basic, Roo.util.Observable,
35242 getPanelId : function(p){
35246 applyConfig : function(config){
35247 this.margins = config.margins || this.margins || {top: 0, left: 0, right:0, bottom: 0};
35248 this.config = config;
35253 * Resizes the region to the specified size. For vertical regions (west, east) this adjusts
35254 * the width, for horizontal (north, south) the height.
35255 * @param {Number} newSize The new width or height
35257 resizeTo : function(newSize){
35258 var el = this.el ? this.el :
35259 (this.activePanel ? this.activePanel.getEl() : null);
35261 switch(this.position){
35264 el.setWidth(newSize);
35265 this.fireEvent("resized", this, newSize);
35269 el.setHeight(newSize);
35270 this.fireEvent("resized", this, newSize);
35276 getBox : function(){
35277 return this.activePanel ? this.activePanel.getEl().getBox(false, true) : null;
35280 getMargins : function(){
35281 return this.margins;
35284 updateBox : function(box){
35286 var el = this.activePanel.getEl();
35287 el.dom.style.left = box.x + "px";
35288 el.dom.style.top = box.y + "px";
35289 this.activePanel.setSize(box.width, box.height);
35293 * Returns the container element for this region.
35294 * @return {Roo.Element}
35296 getEl : function(){
35297 return this.activePanel;
35301 * Returns true if this region is currently visible.
35302 * @return {Boolean}
35304 isVisible : function(){
35305 return this.activePanel ? true : false;
35308 setActivePanel : function(panel){
35309 panel = this.getPanel(panel);
35310 if(this.activePanel && this.activePanel != panel){
35311 this.activePanel.setActiveState(false);
35312 this.activePanel.getEl().setLeftTop(-10000,-10000);
35314 this.activePanel = panel;
35315 panel.setActiveState(true);
35317 panel.setSize(this.box.width, this.box.height);
35319 this.fireEvent("panelactivated", this, panel);
35320 this.fireEvent("invalidated");
35324 * Show the specified panel.
35325 * @param {Number/String/ContentPanel} panelId The panels index, id or the panel itself
35326 * @return {Roo.ContentPanel} The shown panel or null
35328 showPanel : function(panel){
35329 panel = this.getPanel(panel);
35331 this.setActivePanel(panel);
35337 * Get the active panel for this region.
35338 * @return {Roo.ContentPanel} The active panel or null
35340 getActivePanel : function(){
35341 return this.activePanel;
35345 * Add the passed ContentPanel(s)
35346 * @param {ContentPanel...} panel The ContentPanel(s) to add (you can pass more than one)
35347 * @return {Roo.ContentPanel} The panel added (if only one was added)
35349 add : function(panel){
35350 if(arguments.length > 1){
35351 for(var i = 0, len = arguments.length; i < len; i++) {
35352 this.add(arguments[i]);
35356 if(this.hasPanel(panel)){
35357 this.showPanel(panel);
35360 var el = panel.getEl();
35361 if(el.dom.parentNode != this.mgr.el.dom){
35362 this.mgr.el.dom.appendChild(el.dom);
35364 if(panel.setRegion){
35365 panel.setRegion(this);
35367 this.panels.add(panel);
35368 el.setStyle("position", "absolute");
35369 if(!panel.background){
35370 this.setActivePanel(panel);
35371 if(this.config.initialSize && this.panels.getCount()==1){
35372 this.resizeTo(this.config.initialSize);
35375 this.fireEvent("paneladded", this, panel);
35380 * Returns true if the panel is in this region.
35381 * @param {Number/String/ContentPanel} panel The panels index, id or the panel itself
35382 * @return {Boolean}
35384 hasPanel : function(panel){
35385 if(typeof panel == "object"){ // must be panel obj
35386 panel = panel.getId();
35388 return this.getPanel(panel) ? true : false;
35392 * Removes the specified panel. If preservePanel is not true (either here or in the config), the panel is destroyed.
35393 * @param {Number/String/ContentPanel} panel The panels index, id or the panel itself
35394 * @param {Boolean} preservePanel Overrides the config preservePanel option
35395 * @return {Roo.ContentPanel} The panel that was removed
35397 remove : function(panel, preservePanel){
35398 panel = this.getPanel(panel);
35403 this.fireEvent("beforeremove", this, panel, e);
35404 if(e.cancel === true){
35407 var panelId = panel.getId();
35408 this.panels.removeKey(panelId);
35413 * Returns the panel specified or null if it's not in this region.
35414 * @param {Number/String/ContentPanel} panel The panels index, id or the panel itself
35415 * @return {Roo.ContentPanel}
35417 getPanel : function(id){
35418 if(typeof id == "object"){ // must be panel obj
35421 return this.panels.get(id);
35425 * Returns this regions position (north/south/east/west/center).
35428 getPosition: function(){
35429 return this.position;
35433 * Ext JS Library 1.1.1
35434 * Copyright(c) 2006-2007, Ext JS, LLC.
35436 * Originally Released Under LGPL - original licence link has changed is not relivant.
35439 * <script type="text/javascript">
35443 * @class Roo.bootstrap.layout.Region
35444 * @extends Roo.bootstrap.layout.Basic
35445 * This class represents a region in a layout manager.
35447 * @cfg {Object} margins Margins for the element (defaults to {top: 0, left: 0, right:0, bottom: 0})
35448 * @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})
35449 * @cfg {String} tabPosition (top|bottom) "top" or "bottom" (defaults to "bottom")
35450 * @cfg {Boolean} alwaysShowTabs True to always display tabs even when there is only 1 panel (defaults to false)
35451 * @cfg {Boolean} autoScroll True to enable overflow scrolling (defaults to false)
35452 * @cfg {Boolean} titlebar True to display a title bar (defaults to true)
35453 * @cfg {String} title The title for the region (overrides panel titles)
35454 * @cfg {Boolean} animate True to animate expand/collapse (defaults to false)
35455 * @cfg {Boolean} autoHide False to disable auto hiding when the mouse leaves the "floated" region (defaults to true)
35456 * @cfg {Boolean} preservePanels True to preserve removed panels so they can be readded later (defaults to false)
35457 * @cfg {Boolean} closeOnTab True to place the close icon on the tabs instead of the region titlebar (defaults to false)
35458 * @cfg {Boolean} hideTabs True to hide the tab strip (defaults to false)
35459 * @cfg {Boolean} resizeTabs True to enable automatic tab resizing. This will resize the tabs so they are all the same size and fit within
35460 * the space available, similar to FireFox 1.5 tabs (defaults to false)
35461 * @cfg {Number} minTabWidth The minimum tab width (defaults to 40)
35462 * @cfg {Number} preferredTabWidth The preferred tab width (defaults to 150)
35463 * @cfg {String} overflow (hidden|visible) if you have menus in the region, then you need to set this to visible.
35465 * @cfg {Boolean} hidden True to start the region hidden (defaults to false)
35466 * @cfg {Boolean} hideWhenEmpty True to hide the region when it has no panels
35467 * @cfg {Boolean} disableTabTips True to disable tab tooltips
35468 * @cfg {Number} width For East/West panels
35469 * @cfg {Number} height For North/South panels
35470 * @cfg {Boolean} split To show the splitter
35471 * @cfg {Boolean} toolbar xtype configuration for a toolbar - shows on right of tabbar
35473 * @cfg {string} cls Extra CSS classes to add to region
35475 * @cfg {Roo.bootstrap.layout.Manager} mgr The manager
35476 * @cfg {string} region the region that it inhabits..
35479 * @xxxcfg {Boolean} collapsible DISABLED False to disable collapsing (defaults to true)
35480 * @xxxcfg {Boolean} collapsed DISABLED True to set the initial display to collapsed (defaults to false)
35482 * @xxxcfg {String} collapsedTitle DISABLED Optional string message to display in the collapsed block of a north or south region
35483 * @xxxxcfg {Boolean} floatable DISABLED False to disable floating (defaults to true)
35484 * @xxxxcfg {Boolean} showPin True to show a pin button NOT SUPPORTED YET
35486 Roo.bootstrap.layout.Region = function(config)
35488 this.applyConfig(config);
35490 var mgr = config.mgr;
35491 var pos = config.region;
35492 config.skipConfig = true;
35493 Roo.bootstrap.layout.Region.superclass.constructor.call(this, config);
35496 this.onRender(mgr.el);
35499 this.visible = true;
35500 this.collapsed = false;
35501 this.unrendered_panels = [];
35504 Roo.extend(Roo.bootstrap.layout.Region, Roo.bootstrap.layout.Basic, {
35506 position: '', // set by wrapper (eg. north/south etc..)
35507 unrendered_panels : null, // unrendered panels.
35508 createBody : function(){
35509 /** This region's body element
35510 * @type Roo.Element */
35511 this.bodyEl = this.el.createChild({
35513 cls: "roo-layout-panel-body tab-content" // bootstrap added...
35517 onRender: function(ctr, pos)
35519 var dh = Roo.DomHelper;
35520 /** This region's container element
35521 * @type Roo.Element */
35522 this.el = dh.append(ctr.dom, {
35524 cls: (this.config.cls || '') + " roo-layout-region roo-layout-panel roo-layout-panel-" + this.position
35526 /** This region's title element
35527 * @type Roo.Element */
35529 this.titleEl = dh.append(this.el.dom,
35532 unselectable: "on",
35533 cls: "roo-unselectable roo-layout-panel-hd breadcrumb roo-layout-title-" + this.position,
35535 {tag: "span", cls: "roo-unselectable roo-layout-panel-hd-text", unselectable: "on", html: " "},
35536 {tag: "div", cls: "roo-unselectable roo-layout-panel-hd-tools", unselectable: "on"}
35539 this.titleEl.enableDisplayMode();
35540 /** This region's title text element
35541 * @type HTMLElement */
35542 this.titleTextEl = this.titleEl.dom.firstChild;
35543 this.tools = Roo.get(this.titleEl.dom.childNodes[1], true);
35545 this.closeBtn = this.createTool(this.tools.dom, "roo-layout-close");
35546 this.closeBtn.enableDisplayMode();
35547 this.closeBtn.on("click", this.closeClicked, this);
35548 this.closeBtn.hide();
35550 this.createBody(this.config);
35551 if(this.config.hideWhenEmpty){
35553 this.on("paneladded", this.validateVisibility, this);
35554 this.on("panelremoved", this.validateVisibility, this);
35556 if(this.autoScroll){
35557 this.bodyEl.setStyle("overflow", "auto");
35559 this.bodyEl.setStyle("overflow", this.config.overflow || 'hidden');
35561 //if(c.titlebar !== false){
35562 if((!this.config.titlebar && !this.config.title) || this.config.titlebar === false){
35563 this.titleEl.hide();
35565 this.titleEl.show();
35566 if(this.config.title){
35567 this.titleTextEl.innerHTML = this.config.title;
35571 if(this.config.collapsed){
35572 this.collapse(true);
35574 if(this.config.hidden){
35578 if (this.unrendered_panels && this.unrendered_panels.length) {
35579 for (var i =0;i< this.unrendered_panels.length; i++) {
35580 this.add(this.unrendered_panels[i]);
35582 this.unrendered_panels = null;
35588 applyConfig : function(c)
35591 *if(c.collapsible && this.position != "center" && !this.collapsedEl){
35592 var dh = Roo.DomHelper;
35593 if(c.titlebar !== false){
35594 this.collapseBtn = this.createTool(this.tools.dom, "roo-layout-collapse-"+this.position);
35595 this.collapseBtn.on("click", this.collapse, this);
35596 this.collapseBtn.enableDisplayMode();
35598 if(c.showPin === true || this.showPin){
35599 this.stickBtn = this.createTool(this.tools.dom, "roo-layout-stick");
35600 this.stickBtn.enableDisplayMode();
35601 this.stickBtn.on("click", this.expand, this);
35602 this.stickBtn.hide();
35607 /** This region's collapsed element
35608 * @type Roo.Element */
35611 this.collapsedEl = dh.append(this.mgr.el.dom, {cls: "x-layout-collapsed x-layout-collapsed-"+this.position, children:[
35612 {cls: "x-layout-collapsed-tools", children:[{cls: "x-layout-ctools-inner"}]}
35615 if(c.floatable !== false){
35616 this.collapsedEl.addClassOnOver("x-layout-collapsed-over");
35617 this.collapsedEl.on("click", this.collapseClick, this);
35620 if(c.collapsedTitle && (this.position == "north" || this.position== "south")) {
35621 this.collapsedTitleTextEl = dh.append(this.collapsedEl.dom, {tag: "div", cls: "x-unselectable x-layout-panel-hd-text",
35622 id: "message", unselectable: "on", style:{"float":"left"}});
35623 this.collapsedTitleTextEl.innerHTML = c.collapsedTitle;
35625 this.expandBtn = this.createTool(this.collapsedEl.dom.firstChild.firstChild, "x-layout-expand-"+this.position);
35626 this.expandBtn.on("click", this.expand, this);
35630 if(this.collapseBtn){
35631 this.collapseBtn.setVisible(c.collapsible == true);
35634 this.cmargins = c.cmargins || this.cmargins ||
35635 (this.position == "west" || this.position == "east" ?
35636 {top: 0, left: 2, right:2, bottom: 0} :
35637 {top: 2, left: 0, right:0, bottom: 2});
35639 this.margins = c.margins || this.margins || {top: 0, left: 0, right:0, bottom: 0};
35642 this.bottomTabs = c.tabPosition != "top";
35644 this.autoScroll = c.autoScroll || false;
35649 this.duration = c.duration || .30;
35650 this.slideDuration = c.slideDuration || .45;
35655 * Returns true if this region is currently visible.
35656 * @return {Boolean}
35658 isVisible : function(){
35659 return this.visible;
35663 * Updates the title for collapsed north/south regions (used with {@link #collapsedTitle} config option)
35664 * @param {String} title (optional) The title text (accepts HTML markup, defaults to the numeric character reference for a non-breaking space, "&#160;")
35666 //setCollapsedTitle : function(title){
35667 // title = title || " ";
35668 // if(this.collapsedTitleTextEl){
35669 // this.collapsedTitleTextEl.innerHTML = title;
35673 getBox : function(){
35675 // if(!this.collapsed){
35676 b = this.el.getBox(false, true);
35678 // b = this.collapsedEl.getBox(false, true);
35683 getMargins : function(){
35684 return this.margins;
35685 //return this.collapsed ? this.cmargins : this.margins;
35688 highlight : function(){
35689 this.el.addClass("x-layout-panel-dragover");
35692 unhighlight : function(){
35693 this.el.removeClass("x-layout-panel-dragover");
35696 updateBox : function(box)
35698 if (!this.bodyEl) {
35699 return; // not rendered yet..
35703 if(!this.collapsed){
35704 this.el.dom.style.left = box.x + "px";
35705 this.el.dom.style.top = box.y + "px";
35706 this.updateBody(box.width, box.height);
35708 this.collapsedEl.dom.style.left = box.x + "px";
35709 this.collapsedEl.dom.style.top = box.y + "px";
35710 this.collapsedEl.setSize(box.width, box.height);
35713 this.tabs.autoSizeTabs();
35717 updateBody : function(w, h)
35720 this.el.setWidth(w);
35721 w -= this.el.getBorderWidth("rl");
35722 if(this.config.adjustments){
35723 w += this.config.adjustments[0];
35726 if(h !== null && h > 0){
35727 this.el.setHeight(h);
35728 h = this.titleEl && this.titleEl.isDisplayed() ? h - (this.titleEl.getHeight()||0) : h;
35729 h -= this.el.getBorderWidth("tb");
35730 if(this.config.adjustments){
35731 h += this.config.adjustments[1];
35733 this.bodyEl.setHeight(h);
35735 h = this.tabs.syncHeight(h);
35738 if(this.panelSize){
35739 w = w !== null ? w : this.panelSize.width;
35740 h = h !== null ? h : this.panelSize.height;
35742 if(this.activePanel){
35743 var el = this.activePanel.getEl();
35744 w = w !== null ? w : el.getWidth();
35745 h = h !== null ? h : el.getHeight();
35746 this.panelSize = {width: w, height: h};
35747 this.activePanel.setSize(w, h);
35749 if(Roo.isIE && this.tabs){
35750 this.tabs.el.repaint();
35755 * Returns the container element for this region.
35756 * @return {Roo.Element}
35758 getEl : function(){
35763 * Hides this region.
35766 //if(!this.collapsed){
35767 this.el.dom.style.left = "-2000px";
35770 // this.collapsedEl.dom.style.left = "-2000px";
35771 // this.collapsedEl.hide();
35773 this.visible = false;
35774 this.fireEvent("visibilitychange", this, false);
35778 * Shows this region if it was previously hidden.
35781 //if(!this.collapsed){
35784 // this.collapsedEl.show();
35786 this.visible = true;
35787 this.fireEvent("visibilitychange", this, true);
35790 closeClicked : function(){
35791 if(this.activePanel){
35792 this.remove(this.activePanel);
35796 collapseClick : function(e){
35798 e.stopPropagation();
35801 e.stopPropagation();
35807 * Collapses this region.
35808 * @param {Boolean} skipAnim (optional) true to collapse the element without animation (if animate is true)
35811 collapse : function(skipAnim, skipCheck = false){
35812 if(this.collapsed) {
35816 if(skipCheck || this.fireEvent("beforecollapse", this) != false){
35818 this.collapsed = true;
35820 this.split.el.hide();
35822 if(this.config.animate && skipAnim !== true){
35823 this.fireEvent("invalidated", this);
35824 this.animateCollapse();
35826 this.el.setLocation(-20000,-20000);
35828 this.collapsedEl.show();
35829 this.fireEvent("collapsed", this);
35830 this.fireEvent("invalidated", this);
35836 animateCollapse : function(){
35841 * Expands this region if it was previously collapsed.
35842 * @param {Roo.EventObject} e The event that triggered the expand (or null if calling manually)
35843 * @param {Boolean} skipAnim (optional) true to expand the element without animation (if animate is true)
35846 expand : function(e, skipAnim){
35848 e.stopPropagation();
35850 if(!this.collapsed || this.el.hasActiveFx()) {
35854 this.afterSlideIn();
35857 this.collapsed = false;
35858 if(this.config.animate && skipAnim !== true){
35859 this.animateExpand();
35863 this.split.el.show();
35865 this.collapsedEl.setLocation(-2000,-2000);
35866 this.collapsedEl.hide();
35867 this.fireEvent("invalidated", this);
35868 this.fireEvent("expanded", this);
35872 animateExpand : function(){
35876 initTabs : function()
35878 //this.bodyEl.setStyle("overflow", "hidden"); -- this is set in render?
35880 var ts = new Roo.bootstrap.panel.Tabs({
35881 el: this.bodyEl.dom,
35882 tabPosition: this.bottomTabs ? 'bottom' : 'top',
35883 disableTooltips: this.config.disableTabTips,
35884 toolbar : this.config.toolbar
35887 if(this.config.hideTabs){
35888 ts.stripWrap.setDisplayed(false);
35891 ts.resizeTabs = this.config.resizeTabs === true;
35892 ts.minTabWidth = this.config.minTabWidth || 40;
35893 ts.maxTabWidth = this.config.maxTabWidth || 250;
35894 ts.preferredTabWidth = this.config.preferredTabWidth || 150;
35895 ts.monitorResize = false;
35896 //ts.bodyEl.setStyle("overflow", this.config.autoScroll ? "auto" : "hidden"); // this is set in render?
35897 ts.bodyEl.addClass('roo-layout-tabs-body');
35898 this.panels.each(this.initPanelAsTab, this);
35901 initPanelAsTab : function(panel){
35902 var ti = this.tabs.addTab(
35906 this.config.closeOnTab && panel.isClosable(),
35909 if(panel.tabTip !== undefined){
35910 ti.setTooltip(panel.tabTip);
35912 ti.on("activate", function(){
35913 this.setActivePanel(panel);
35916 if(this.config.closeOnTab){
35917 ti.on("beforeclose", function(t, e){
35919 this.remove(panel);
35923 panel.tabItem = ti;
35928 updatePanelTitle : function(panel, title)
35930 if(this.activePanel == panel){
35931 this.updateTitle(title);
35934 var ti = this.tabs.getTab(panel.getEl().id);
35936 if(panel.tabTip !== undefined){
35937 ti.setTooltip(panel.tabTip);
35942 updateTitle : function(title){
35943 if(this.titleTextEl && !this.config.title){
35944 this.titleTextEl.innerHTML = (typeof title != "undefined" && title.length > 0 ? title : " ");
35948 setActivePanel : function(panel)
35950 panel = this.getPanel(panel);
35951 if(this.activePanel && this.activePanel != panel){
35952 if(this.activePanel.setActiveState(false) === false){
35956 this.activePanel = panel;
35957 panel.setActiveState(true);
35958 if(this.panelSize){
35959 panel.setSize(this.panelSize.width, this.panelSize.height);
35962 this.closeBtn.setVisible(!this.config.closeOnTab && !this.isSlid && panel.isClosable());
35964 this.updateTitle(panel.getTitle());
35966 this.fireEvent("invalidated", this);
35968 this.fireEvent("panelactivated", this, panel);
35972 * Shows the specified panel.
35973 * @param {Number/String/ContentPanel} panelId The panel's index, id or the panel itself
35974 * @return {Roo.ContentPanel} The shown panel, or null if a panel could not be found from panelId
35976 showPanel : function(panel)
35978 panel = this.getPanel(panel);
35981 var tab = this.tabs.getTab(panel.getEl().id);
35982 if(tab.isHidden()){
35983 this.tabs.unhideTab(tab.id);
35987 this.setActivePanel(panel);
35994 * Get the active panel for this region.
35995 * @return {Roo.ContentPanel} The active panel or null
35997 getActivePanel : function(){
35998 return this.activePanel;
36001 validateVisibility : function(){
36002 if(this.panels.getCount() < 1){
36003 this.updateTitle(" ");
36004 this.closeBtn.hide();
36007 if(!this.isVisible()){
36014 * Adds the passed ContentPanel(s) to this region.
36015 * @param {ContentPanel...} panel The ContentPanel(s) to add (you can pass more than one)
36016 * @return {Roo.ContentPanel} The panel added (if only one was added; null otherwise)
36018 add : function(panel)
36020 if(arguments.length > 1){
36021 for(var i = 0, len = arguments.length; i < len; i++) {
36022 this.add(arguments[i]);
36027 // if we have not been rendered yet, then we can not really do much of this..
36028 if (!this.bodyEl) {
36029 this.unrendered_panels.push(panel);
36036 if(this.hasPanel(panel)){
36037 this.showPanel(panel);
36040 panel.setRegion(this);
36041 this.panels.add(panel);
36042 /* if(this.panels.getCount() == 1 && !this.config.alwaysShowTabs){
36043 // sinle panel - no tab...?? would it not be better to render it with the tabs,
36044 // and hide them... ???
36045 this.bodyEl.dom.appendChild(panel.getEl().dom);
36046 if(panel.background !== true){
36047 this.setActivePanel(panel);
36049 this.fireEvent("paneladded", this, panel);
36056 this.initPanelAsTab(panel);
36060 if(panel.background !== true){
36061 this.tabs.activate(panel.getEl().id);
36063 this.fireEvent("paneladded", this, panel);
36068 * Hides the tab for the specified panel.
36069 * @param {Number/String/ContentPanel} panel The panel's index, id or the panel itself
36071 hidePanel : function(panel){
36072 if(this.tabs && (panel = this.getPanel(panel))){
36073 this.tabs.hideTab(panel.getEl().id);
36078 * Unhides the tab for a previously hidden panel.
36079 * @param {Number/String/ContentPanel} panel The panel's index, id or the panel itself
36081 unhidePanel : function(panel){
36082 if(this.tabs && (panel = this.getPanel(panel))){
36083 this.tabs.unhideTab(panel.getEl().id);
36087 clearPanels : function(){
36088 while(this.panels.getCount() > 0){
36089 this.remove(this.panels.first());
36094 * Removes the specified panel. If preservePanel is not true (either here or in the config), the panel is destroyed.
36095 * @param {Number/String/ContentPanel} panel The panel's index, id or the panel itself
36096 * @param {Boolean} preservePanel Overrides the config preservePanel option
36097 * @return {Roo.ContentPanel} The panel that was removed
36099 remove : function(panel, preservePanel)
36101 panel = this.getPanel(panel);
36106 this.fireEvent("beforeremove", this, panel, e);
36107 if(e.cancel === true){
36110 preservePanel = (typeof preservePanel != "undefined" ? preservePanel : (this.config.preservePanels === true || panel.preserve === true));
36111 var panelId = panel.getId();
36112 this.panels.removeKey(panelId);
36114 document.body.appendChild(panel.getEl().dom);
36117 this.tabs.removeTab(panel.getEl().id);
36118 }else if (!preservePanel){
36119 this.bodyEl.dom.removeChild(panel.getEl().dom);
36121 if(this.panels.getCount() == 1 && this.tabs && !this.config.alwaysShowTabs){
36122 var p = this.panels.first();
36123 var tempEl = document.createElement("div"); // temp holder to keep IE from deleting the node
36124 tempEl.appendChild(p.getEl().dom);
36125 this.bodyEl.update("");
36126 this.bodyEl.dom.appendChild(p.getEl().dom);
36128 this.updateTitle(p.getTitle());
36130 this.bodyEl.setStyle("overflow", this.config.autoScroll ? "auto" : "hidden");
36131 this.setActivePanel(p);
36133 panel.setRegion(null);
36134 if(this.activePanel == panel){
36135 this.activePanel = null;
36137 if(this.config.autoDestroy !== false && preservePanel !== true){
36138 try{panel.destroy();}catch(e){}
36140 this.fireEvent("panelremoved", this, panel);
36145 * Returns the TabPanel component used by this region
36146 * @return {Roo.TabPanel}
36148 getTabs : function(){
36152 createTool : function(parentEl, className){
36153 var btn = Roo.DomHelper.append(parentEl, {
36155 cls: "x-layout-tools-button",
36158 cls: "roo-layout-tools-button-inner " + className,
36162 btn.addClassOnOver("roo-layout-tools-button-over");
36167 * Ext JS Library 1.1.1
36168 * Copyright(c) 2006-2007, Ext JS, LLC.
36170 * Originally Released Under LGPL - original licence link has changed is not relivant.
36173 * <script type="text/javascript">
36179 * @class Roo.SplitLayoutRegion
36180 * @extends Roo.LayoutRegion
36181 * Adds a splitbar and other (private) useful functionality to a {@link Roo.LayoutRegion}.
36183 Roo.bootstrap.layout.Split = function(config){
36184 this.cursor = config.cursor;
36185 Roo.bootstrap.layout.Split.superclass.constructor.call(this, config);
36188 Roo.extend(Roo.bootstrap.layout.Split, Roo.bootstrap.layout.Region,
36190 splitTip : "Drag to resize.",
36191 collapsibleSplitTip : "Drag to resize. Double click to hide.",
36192 useSplitTips : false,
36194 applyConfig : function(config){
36195 Roo.bootstrap.layout.Split.superclass.applyConfig.call(this, config);
36198 onRender : function(ctr,pos) {
36200 Roo.bootstrap.layout.Split.superclass.onRender.call(this, ctr,pos);
36201 if(!this.config.split){
36206 var splitEl = Roo.DomHelper.append(ctr.dom, {
36208 id: this.el.id + "-split",
36209 cls: "roo-layout-split roo-layout-split-"+this.position,
36212 /** The SplitBar for this region
36213 * @type Roo.SplitBar */
36214 // does not exist yet...
36215 Roo.log([this.position, this.orientation]);
36217 this.split = new Roo.bootstrap.SplitBar({
36218 dragElement : splitEl,
36219 resizingElement: this.el,
36220 orientation : this.orientation
36223 this.split.on("moved", this.onSplitMove, this);
36224 this.split.useShim = this.config.useShim === true;
36225 this.split.getMaximumSize = this[this.position == 'north' || this.position == 'south' ? 'getVMaxSize' : 'getHMaxSize'].createDelegate(this);
36226 if(this.useSplitTips){
36227 this.split.el.dom.title = this.config.collapsible ? this.collapsibleSplitTip : this.splitTip;
36229 //if(config.collapsible){
36230 // this.split.el.on("dblclick", this.collapse, this);
36233 if(typeof this.config.minSize != "undefined"){
36234 this.split.minSize = this.config.minSize;
36236 if(typeof this.config.maxSize != "undefined"){
36237 this.split.maxSize = this.config.maxSize;
36239 if(this.config.hideWhenEmpty || this.config.hidden || this.config.collapsed){
36240 this.hideSplitter();
36245 getHMaxSize : function(){
36246 var cmax = this.config.maxSize || 10000;
36247 var center = this.mgr.getRegion("center");
36248 return Math.min(cmax, (this.el.getWidth()+center.getEl().getWidth())-center.getMinWidth());
36251 getVMaxSize : function(){
36252 var cmax = this.config.maxSize || 10000;
36253 var center = this.mgr.getRegion("center");
36254 return Math.min(cmax, (this.el.getHeight()+center.getEl().getHeight())-center.getMinHeight());
36257 onSplitMove : function(split, newSize){
36258 this.fireEvent("resized", this, newSize);
36262 * Returns the {@link Roo.SplitBar} for this region.
36263 * @return {Roo.SplitBar}
36265 getSplitBar : function(){
36270 this.hideSplitter();
36271 Roo.bootstrap.layout.Split.superclass.hide.call(this);
36274 hideSplitter : function(){
36276 this.split.el.setLocation(-2000,-2000);
36277 this.split.el.hide();
36283 this.split.el.show();
36285 Roo.bootstrap.layout.Split.superclass.show.call(this);
36288 beforeSlide: function(){
36289 if(Roo.isGecko){// firefox overflow auto bug workaround
36290 this.bodyEl.clip();
36292 this.tabs.bodyEl.clip();
36294 if(this.activePanel){
36295 this.activePanel.getEl().clip();
36297 if(this.activePanel.beforeSlide){
36298 this.activePanel.beforeSlide();
36304 afterSlide : function(){
36305 if(Roo.isGecko){// firefox overflow auto bug workaround
36306 this.bodyEl.unclip();
36308 this.tabs.bodyEl.unclip();
36310 if(this.activePanel){
36311 this.activePanel.getEl().unclip();
36312 if(this.activePanel.afterSlide){
36313 this.activePanel.afterSlide();
36319 initAutoHide : function(){
36320 if(this.autoHide !== false){
36321 if(!this.autoHideHd){
36322 var st = new Roo.util.DelayedTask(this.slideIn, this);
36323 this.autoHideHd = {
36324 "mouseout": function(e){
36325 if(!e.within(this.el, true)){
36329 "mouseover" : function(e){
36335 this.el.on(this.autoHideHd);
36339 clearAutoHide : function(){
36340 if(this.autoHide !== false){
36341 this.el.un("mouseout", this.autoHideHd.mouseout);
36342 this.el.un("mouseover", this.autoHideHd.mouseover);
36346 clearMonitor : function(){
36347 Roo.get(document).un("click", this.slideInIf, this);
36350 // these names are backwards but not changed for compat
36351 slideOut : function(){
36352 if(this.isSlid || this.el.hasActiveFx()){
36355 this.isSlid = true;
36356 if(this.collapseBtn){
36357 this.collapseBtn.hide();
36359 this.closeBtnState = this.closeBtn.getStyle('display');
36360 this.closeBtn.hide();
36362 this.stickBtn.show();
36365 this.el.alignTo(this.collapsedEl, this.getCollapseAnchor());
36366 this.beforeSlide();
36367 this.el.setStyle("z-index", 10001);
36368 this.el.slideIn(this.getSlideAnchor(), {
36369 callback: function(){
36371 this.initAutoHide();
36372 Roo.get(document).on("click", this.slideInIf, this);
36373 this.fireEvent("slideshow", this);
36380 afterSlideIn : function(){
36381 this.clearAutoHide();
36382 this.isSlid = false;
36383 this.clearMonitor();
36384 this.el.setStyle("z-index", "");
36385 if(this.collapseBtn){
36386 this.collapseBtn.show();
36388 this.closeBtn.setStyle('display', this.closeBtnState);
36390 this.stickBtn.hide();
36392 this.fireEvent("slidehide", this);
36395 slideIn : function(cb){
36396 if(!this.isSlid || this.el.hasActiveFx()){
36400 this.isSlid = false;
36401 this.beforeSlide();
36402 this.el.slideOut(this.getSlideAnchor(), {
36403 callback: function(){
36404 this.el.setLeftTop(-10000, -10000);
36406 this.afterSlideIn();
36414 slideInIf : function(e){
36415 if(!e.within(this.el)){
36420 animateCollapse : function(){
36421 this.beforeSlide();
36422 this.el.setStyle("z-index", 20000);
36423 var anchor = this.getSlideAnchor();
36424 this.el.slideOut(anchor, {
36425 callback : function(){
36426 this.el.setStyle("z-index", "");
36427 this.collapsedEl.slideIn(anchor, {duration:.3});
36429 this.el.setLocation(-10000,-10000);
36431 this.fireEvent("collapsed", this);
36438 animateExpand : function(){
36439 this.beforeSlide();
36440 this.el.alignTo(this.collapsedEl, this.getCollapseAnchor(), this.getExpandAdj());
36441 this.el.setStyle("z-index", 20000);
36442 this.collapsedEl.hide({
36445 this.el.slideIn(this.getSlideAnchor(), {
36446 callback : function(){
36447 this.el.setStyle("z-index", "");
36450 this.split.el.show();
36452 this.fireEvent("invalidated", this);
36453 this.fireEvent("expanded", this);
36481 getAnchor : function(){
36482 return this.anchors[this.position];
36485 getCollapseAnchor : function(){
36486 return this.canchors[this.position];
36489 getSlideAnchor : function(){
36490 return this.sanchors[this.position];
36493 getAlignAdj : function(){
36494 var cm = this.cmargins;
36495 switch(this.position){
36511 getExpandAdj : function(){
36512 var c = this.collapsedEl, cm = this.cmargins;
36513 switch(this.position){
36515 return [-(cm.right+c.getWidth()+cm.left), 0];
36518 return [cm.right+c.getWidth()+cm.left, 0];
36521 return [0, -(cm.top+cm.bottom+c.getHeight())];
36524 return [0, cm.top+cm.bottom+c.getHeight()];
36530 * Ext JS Library 1.1.1
36531 * Copyright(c) 2006-2007, Ext JS, LLC.
36533 * Originally Released Under LGPL - original licence link has changed is not relivant.
36536 * <script type="text/javascript">
36539 * These classes are private internal classes
36541 Roo.bootstrap.layout.Center = function(config){
36542 config.region = "center";
36543 Roo.bootstrap.layout.Region.call(this, config);
36544 this.visible = true;
36545 this.minWidth = config.minWidth || 20;
36546 this.minHeight = config.minHeight || 20;
36549 Roo.extend(Roo.bootstrap.layout.Center, Roo.bootstrap.layout.Region, {
36551 // center panel can't be hidden
36555 // center panel can't be hidden
36558 getMinWidth: function(){
36559 return this.minWidth;
36562 getMinHeight: function(){
36563 return this.minHeight;
36576 Roo.bootstrap.layout.North = function(config)
36578 config.region = 'north';
36579 config.cursor = 'n-resize';
36581 Roo.bootstrap.layout.Split.call(this, config);
36585 this.split.placement = Roo.bootstrap.SplitBar.TOP;
36586 this.split.orientation = Roo.bootstrap.SplitBar.VERTICAL;
36587 this.split.el.addClass("roo-layout-split-v");
36589 var size = config.initialSize || config.height;
36590 if(typeof size != "undefined"){
36591 this.el.setHeight(size);
36594 Roo.extend(Roo.bootstrap.layout.North, Roo.bootstrap.layout.Split,
36596 orientation: Roo.bootstrap.SplitBar.VERTICAL,
36600 getBox : function(){
36601 if(this.collapsed){
36602 return this.collapsedEl.getBox();
36604 var box = this.el.getBox();
36606 box.height += this.split.el.getHeight();
36611 updateBox : function(box){
36612 if(this.split && !this.collapsed){
36613 box.height -= this.split.el.getHeight();
36614 this.split.el.setLeft(box.x);
36615 this.split.el.setTop(box.y+box.height);
36616 this.split.el.setWidth(box.width);
36618 if(this.collapsed){
36619 this.updateBody(box.width, null);
36621 Roo.bootstrap.layout.Region.prototype.updateBox.call(this, box);
36629 Roo.bootstrap.layout.South = function(config){
36630 config.region = 'south';
36631 config.cursor = 's-resize';
36632 Roo.bootstrap.layout.Split.call(this, config);
36634 this.split.placement = Roo.bootstrap.SplitBar.BOTTOM;
36635 this.split.orientation = Roo.bootstrap.SplitBar.VERTICAL;
36636 this.split.el.addClass("roo-layout-split-v");
36638 var size = config.initialSize || config.height;
36639 if(typeof size != "undefined"){
36640 this.el.setHeight(size);
36644 Roo.extend(Roo.bootstrap.layout.South, Roo.bootstrap.layout.Split, {
36645 orientation: Roo.bootstrap.SplitBar.VERTICAL,
36646 getBox : function(){
36647 if(this.collapsed){
36648 return this.collapsedEl.getBox();
36650 var box = this.el.getBox();
36652 var sh = this.split.el.getHeight();
36659 updateBox : function(box){
36660 if(this.split && !this.collapsed){
36661 var sh = this.split.el.getHeight();
36664 this.split.el.setLeft(box.x);
36665 this.split.el.setTop(box.y-sh);
36666 this.split.el.setWidth(box.width);
36668 if(this.collapsed){
36669 this.updateBody(box.width, null);
36671 Roo.bootstrap.layout.Region.prototype.updateBox.call(this, box);
36675 Roo.bootstrap.layout.East = function(config){
36676 config.region = "east";
36677 config.cursor = "e-resize";
36678 Roo.bootstrap.layout.Split.call(this, config);
36680 this.split.placement = Roo.bootstrap.SplitBar.RIGHT;
36681 this.split.orientation = Roo.bootstrap.SplitBar.HORIZONTAL;
36682 this.split.el.addClass("roo-layout-split-h");
36684 var size = config.initialSize || config.width;
36685 if(typeof size != "undefined"){
36686 this.el.setWidth(size);
36689 Roo.extend(Roo.bootstrap.layout.East, Roo.bootstrap.layout.Split, {
36690 orientation: Roo.bootstrap.SplitBar.HORIZONTAL,
36691 getBox : function(){
36692 if(this.collapsed){
36693 return this.collapsedEl.getBox();
36695 var box = this.el.getBox();
36697 var sw = this.split.el.getWidth();
36704 updateBox : function(box){
36705 if(this.split && !this.collapsed){
36706 var sw = this.split.el.getWidth();
36708 this.split.el.setLeft(box.x);
36709 this.split.el.setTop(box.y);
36710 this.split.el.setHeight(box.height);
36713 if(this.collapsed){
36714 this.updateBody(null, box.height);
36716 Roo.bootstrap.layout.Region.prototype.updateBox.call(this, box);
36720 Roo.bootstrap.layout.West = function(config){
36721 config.region = "west";
36722 config.cursor = "w-resize";
36724 Roo.bootstrap.layout.Split.call(this, config);
36726 this.split.placement = Roo.bootstrap.SplitBar.LEFT;
36727 this.split.orientation = Roo.bootstrap.SplitBar.HORIZONTAL;
36728 this.split.el.addClass("roo-layout-split-h");
36732 Roo.extend(Roo.bootstrap.layout.West, Roo.bootstrap.layout.Split, {
36733 orientation: Roo.bootstrap.SplitBar.HORIZONTAL,
36735 onRender: function(ctr, pos)
36737 Roo.bootstrap.layout.West.superclass.onRender.call(this, ctr,pos);
36738 var size = this.config.initialSize || this.config.width;
36739 if(typeof size != "undefined"){
36740 this.el.setWidth(size);
36744 getBox : function(){
36745 if(this.collapsed){
36746 return this.collapsedEl.getBox();
36748 var box = this.el.getBox();
36750 box.width += this.split.el.getWidth();
36755 updateBox : function(box){
36756 if(this.split && !this.collapsed){
36757 var sw = this.split.el.getWidth();
36759 this.split.el.setLeft(box.x+box.width);
36760 this.split.el.setTop(box.y);
36761 this.split.el.setHeight(box.height);
36763 if(this.collapsed){
36764 this.updateBody(null, box.height);
36766 Roo.bootstrap.layout.Region.prototype.updateBox.call(this, box);
36769 Roo.namespace("Roo.bootstrap.panel");/*
36771 * Ext JS Library 1.1.1
36772 * Copyright(c) 2006-2007, Ext JS, LLC.
36774 * Originally Released Under LGPL - original licence link has changed is not relivant.
36777 * <script type="text/javascript">
36780 * @class Roo.ContentPanel
36781 * @extends Roo.util.Observable
36782 * A basic ContentPanel element.
36783 * @cfg {Boolean} fitToFrame True for this panel to adjust its size to fit when the region resizes (defaults to false)
36784 * @cfg {Boolean} fitContainer When using {@link #fitToFrame} and {@link #resizeEl}, you can also fit the parent container (defaults to false)
36785 * @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
36786 * @cfg {Boolean} closable True if the panel can be closed/removed
36787 * @cfg {Boolean} background True if the panel should not be activated when it is added (defaults to false)
36788 * @cfg {String/HTMLElement/Element} resizeEl An element to resize if {@link #fitToFrame} is true (instead of this panel's element)
36789 * @cfg {Toolbar} toolbar A toolbar for this panel
36790 * @cfg {Boolean} autoScroll True to scroll overflow in this panel (use with {@link #fitToFrame})
36791 * @cfg {String} title The title for this panel
36792 * @cfg {Array} adjustments Values to <b>add</b> to the width/height when doing a {@link #fitToFrame} (default is [0, 0])
36793 * @cfg {String} url Calls {@link #setUrl} with this value
36794 * @cfg {String} region (center|north|south|east|west) which region to put this panel on (when used with xtype constructors)
36795 * @cfg {String/Object} params When used with {@link #url}, calls {@link #setUrl} with this value
36796 * @cfg {Boolean} loadOnce When used with {@link #url}, calls {@link #setUrl} with this value
36797 * @cfg {String} content Raw content to fill content panel with (uses setContent on construction.)
36798 * @cfg {Boolean} badges render the badges
36801 * Create a new ContentPanel.
36802 * @param {String/HTMLElement/Roo.Element} el The container element for this panel
36803 * @param {String/Object} config A string to set only the title or a config object
36804 * @param {String} content (optional) Set the HTML content for this panel
36805 * @param {String} region (optional) Used by xtype constructors to add to regions. (values center,east,west,south,north)
36807 Roo.bootstrap.panel.Content = function( config){
36809 this.tpl = config.tpl || false;
36811 var el = config.el;
36812 var content = config.content;
36814 if(config.autoCreate){ // xtype is available if this is called from factory
36817 this.el = Roo.get(el);
36818 if(!this.el && config && config.autoCreate){
36819 if(typeof config.autoCreate == "object"){
36820 if(!config.autoCreate.id){
36821 config.autoCreate.id = config.id||el;
36823 this.el = Roo.DomHelper.append(document.body,
36824 config.autoCreate, true);
36826 var elcfg = { tag: "div",
36827 cls: "roo-layout-inactive-content",
36831 elcfg.html = config.html;
36835 this.el = Roo.DomHelper.append(document.body, elcfg , true);
36838 this.closable = false;
36839 this.loaded = false;
36840 this.active = false;
36843 if (config.toolbar && !config.toolbar.el && config.toolbar.xtype) {
36845 this.toolbar = new config.toolbar.xns[config.toolbar.xtype](config.toolbar);
36847 this.wrapEl = this.el; //this.el.wrap();
36849 if (config.toolbar.items) {
36850 ti = config.toolbar.items ;
36851 delete config.toolbar.items ;
36855 this.toolbar.render(this.wrapEl, 'before');
36856 for(var i =0;i < ti.length;i++) {
36857 // Roo.log(['add child', items[i]]);
36858 nitems.push(this.toolbar.addxtype(Roo.apply({}, ti[i])));
36860 this.toolbar.items = nitems;
36861 this.toolbar.el.insertBefore(this.wrapEl.dom.firstChild);
36862 delete config.toolbar;
36866 // xtype created footer. - not sure if will work as we normally have to render first..
36867 if (this.footer && !this.footer.el && this.footer.xtype) {
36868 if (!this.wrapEl) {
36869 this.wrapEl = this.el.wrap();
36872 this.footer.container = this.wrapEl.createChild();
36874 this.footer = Roo.factory(this.footer, Roo);
36879 if(typeof config == "string"){
36880 this.title = config;
36882 Roo.apply(this, config);
36886 this.resizeEl = Roo.get(this.resizeEl, true);
36888 this.resizeEl = this.el;
36890 // handle view.xtype
36898 * Fires when this panel is activated.
36899 * @param {Roo.ContentPanel} this
36903 * @event deactivate
36904 * Fires when this panel is activated.
36905 * @param {Roo.ContentPanel} this
36907 "deactivate" : true,
36911 * Fires when this panel is resized if fitToFrame is true.
36912 * @param {Roo.ContentPanel} this
36913 * @param {Number} width The width after any component adjustments
36914 * @param {Number} height The height after any component adjustments
36920 * Fires when this tab is created
36921 * @param {Roo.ContentPanel} this
36932 if(this.autoScroll){
36933 this.resizeEl.setStyle("overflow", "auto");
36935 // fix randome scrolling
36936 //this.el.on('scroll', function() {
36937 // Roo.log('fix random scolling');
36938 // this.scrollTo('top',0);
36941 content = content || this.content;
36943 this.setContent(content);
36945 if(config && config.url){
36946 this.setUrl(this.url, this.params, this.loadOnce);
36951 Roo.bootstrap.panel.Content.superclass.constructor.call(this);
36953 if (this.view && typeof(this.view.xtype) != 'undefined') {
36954 this.view.el = this.el.appendChild(document.createElement("div"));
36955 this.view = Roo.factory(this.view);
36956 this.view.render && this.view.render(false, '');
36960 this.fireEvent('render', this);
36963 Roo.extend(Roo.bootstrap.panel.Content, Roo.bootstrap.Component, {
36967 setRegion : function(region){
36968 this.region = region;
36969 this.setActiveClass(region && !this.background);
36973 setActiveClass: function(state)
36976 this.el.replaceClass("roo-layout-inactive-content", "roo-layout-active-content");
36977 this.el.setStyle('position','relative');
36979 this.el.replaceClass("roo-layout-active-content", "roo-layout-inactive-content");
36980 this.el.setStyle('position', 'absolute');
36985 * Returns the toolbar for this Panel if one was configured.
36986 * @return {Roo.Toolbar}
36988 getToolbar : function(){
36989 return this.toolbar;
36992 setActiveState : function(active)
36994 this.active = active;
36995 this.setActiveClass(active);
36997 if(this.fireEvent("deactivate", this) === false){
37002 this.fireEvent("activate", this);
37006 * Updates this panel's element
37007 * @param {String} content The new content
37008 * @param {Boolean} loadScripts (optional) true to look for and process scripts
37010 setContent : function(content, loadScripts){
37011 this.el.update(content, loadScripts);
37014 ignoreResize : function(w, h){
37015 if(this.lastSize && this.lastSize.width == w && this.lastSize.height == h){
37018 this.lastSize = {width: w, height: h};
37023 * Get the {@link Roo.UpdateManager} for this panel. Enables you to perform Ajax updates.
37024 * @return {Roo.UpdateManager} The UpdateManager
37026 getUpdateManager : function(){
37027 return this.el.getUpdateManager();
37030 * Loads this content panel immediately with content from XHR. Note: to delay loading until the panel is activated, use {@link #setUrl}.
37031 * @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:
37034 url: "your-url.php",
37035 params: {param1: "foo", param2: "bar"}, // or a URL encoded string
37036 callback: yourFunction,
37037 scope: yourObject, //(optional scope)
37040 text: "Loading...",
37045 * The only required property is <i>url</i>. The optional properties <i>nocache</i>, <i>text</i> and <i>scripts</i>
37046 * 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.
37047 * @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}
37048 * @param {Function} callback (optional) Callback when transaction is complete -- called with signature (oElement, bSuccess, oResponse)
37049 * @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.
37050 * @return {Roo.ContentPanel} this
37053 var um = this.el.getUpdateManager();
37054 um.update.apply(um, arguments);
37060 * 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.
37061 * @param {String/Function} url The URL to load the content from or a function to call to get the URL
37062 * @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)
37063 * @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)
37064 * @return {Roo.UpdateManager} The UpdateManager
37066 setUrl : function(url, params, loadOnce){
37067 if(this.refreshDelegate){
37068 this.removeListener("activate", this.refreshDelegate);
37070 this.refreshDelegate = this._handleRefresh.createDelegate(this, [url, params, loadOnce]);
37071 this.on("activate", this.refreshDelegate);
37072 return this.el.getUpdateManager();
37075 _handleRefresh : function(url, params, loadOnce){
37076 if(!loadOnce || !this.loaded){
37077 var updater = this.el.getUpdateManager();
37078 updater.update(url, params, this._setLoaded.createDelegate(this));
37082 _setLoaded : function(){
37083 this.loaded = true;
37087 * Returns this panel's id
37090 getId : function(){
37095 * Returns this panel's element - used by regiosn to add.
37096 * @return {Roo.Element}
37098 getEl : function(){
37099 return this.wrapEl || this.el;
37104 adjustForComponents : function(width, height)
37106 //Roo.log('adjustForComponents ');
37107 if(this.resizeEl != this.el){
37108 width -= this.el.getFrameWidth('lr');
37109 height -= this.el.getFrameWidth('tb');
37112 var te = this.toolbar.getEl();
37113 te.setWidth(width);
37114 height -= te.getHeight();
37117 var te = this.footer.getEl();
37118 te.setWidth(width);
37119 height -= te.getHeight();
37123 if(this.adjustments){
37124 width += this.adjustments[0];
37125 height += this.adjustments[1];
37127 return {"width": width, "height": height};
37130 setSize : function(width, height){
37131 if(this.fitToFrame && !this.ignoreResize(width, height)){
37132 if(this.fitContainer && this.resizeEl != this.el){
37133 this.el.setSize(width, height);
37135 var size = this.adjustForComponents(width, height);
37136 this.resizeEl.setSize(this.autoWidth ? "auto" : size.width, this.autoHeight ? "auto" : size.height);
37137 this.fireEvent('resize', this, size.width, size.height);
37142 * Returns this panel's title
37145 getTitle : function(){
37147 if (typeof(this.title) != 'object') {
37152 for (var k in this.title) {
37153 if (!this.title.hasOwnProperty(k)) {
37157 if (k.indexOf('-') >= 0) {
37158 var s = k.split('-');
37159 for (var i = 0; i<s.length; i++) {
37160 t += "<span class='visible-"+s[i]+"'>"+this.title[k]+"</span>";
37163 t += "<span class='visible-"+k+"'>"+this.title[k]+"</span>";
37170 * Set this panel's title
37171 * @param {String} title
37173 setTitle : function(title){
37174 this.title = title;
37176 this.region.updatePanelTitle(this, title);
37181 * Returns true is this panel was configured to be closable
37182 * @return {Boolean}
37184 isClosable : function(){
37185 return this.closable;
37188 beforeSlide : function(){
37190 this.resizeEl.clip();
37193 afterSlide : function(){
37195 this.resizeEl.unclip();
37199 * Force a content refresh from the URL specified in the {@link #setUrl} method.
37200 * Will fail silently if the {@link #setUrl} method has not been called.
37201 * This does not activate the panel, just updates its content.
37203 refresh : function(){
37204 if(this.refreshDelegate){
37205 this.loaded = false;
37206 this.refreshDelegate();
37211 * Destroys this panel
37213 destroy : function(){
37214 this.el.removeAllListeners();
37215 var tempEl = document.createElement("span");
37216 tempEl.appendChild(this.el.dom);
37217 tempEl.innerHTML = "";
37223 * form - if the content panel contains a form - this is a reference to it.
37224 * @type {Roo.form.Form}
37228 * view - if the content panel contains a view (Roo.DatePicker / Roo.View / Roo.JsonView)
37229 * This contains a reference to it.
37235 * Adds a xtype elements to the panel - currently only supports Forms, View, JsonView.
37245 * @param {Object} cfg Xtype definition of item to add.
37249 getChildContainer: function () {
37250 return this.getEl();
37255 var ret = new Roo.factory(cfg);
37260 if (cfg.xtype.match(/^Form$/)) {
37263 //if (this.footer) {
37264 // el = this.footer.container.insertSibling(false, 'before');
37266 el = this.el.createChild();
37269 this.form = new Roo.form.Form(cfg);
37272 if ( this.form.allItems.length) {
37273 this.form.render(el.dom);
37277 // should only have one of theses..
37278 if ([ 'View', 'JsonView', 'DatePicker'].indexOf(cfg.xtype) > -1) {
37279 // views.. should not be just added - used named prop 'view''
37281 cfg.el = this.el.appendChild(document.createElement("div"));
37284 var ret = new Roo.factory(cfg);
37286 ret.render && ret.render(false, ''); // render blank..
37296 * @class Roo.bootstrap.panel.Grid
37297 * @extends Roo.bootstrap.panel.Content
37299 * Create a new GridPanel.
37300 * @cfg {Roo.bootstrap.Table} grid The grid for this panel
37301 * @param {Object} config A the config object
37307 Roo.bootstrap.panel.Grid = function(config)
37311 this.wrapper = Roo.DomHelper.append(document.body, // wrapper for IE7 strict & safari scroll issue
37312 {tag: "div", cls: "roo-layout-grid-wrapper roo-layout-inactive-content"}, true);
37314 config.el = this.wrapper;
37315 //this.el = this.wrapper;
37317 if (config.container) {
37318 // ctor'ed from a Border/panel.grid
37321 this.wrapper.setStyle("overflow", "hidden");
37322 this.wrapper.addClass('roo-grid-container');
37327 if(config.toolbar){
37328 var tool_el = this.wrapper.createChild();
37329 this.toolbar = Roo.factory(config.toolbar);
37331 if (config.toolbar.items) {
37332 ti = config.toolbar.items ;
37333 delete config.toolbar.items ;
37337 this.toolbar.render(tool_el);
37338 for(var i =0;i < ti.length;i++) {
37339 // Roo.log(['add child', items[i]]);
37340 nitems.push(this.toolbar.addxtype(Roo.apply({}, ti[i])));
37342 this.toolbar.items = nitems;
37344 delete config.toolbar;
37347 Roo.bootstrap.panel.Grid.superclass.constructor.call(this, config);
37348 config.grid.scrollBody = true;;
37349 config.grid.monitorWindowResize = false; // turn off autosizing
37350 config.grid.autoHeight = false;
37351 config.grid.autoWidth = false;
37353 this.grid = new config.grid.xns[config.grid.xtype](config.grid);
37355 if (config.background) {
37356 // render grid on panel activation (if panel background)
37357 this.on('activate', function(gp) {
37358 if (!gp.grid.rendered) {
37359 gp.grid.render(this.wrapper);
37360 gp.grid.getGridEl().replaceClass("roo-layout-inactive-content", "roo-layout-component-panel");
37365 this.grid.render(this.wrapper);
37366 this.grid.getGridEl().replaceClass("roo-layout-inactive-content", "roo-layout-component-panel");
37369 //this.wrapper.dom.appendChild(config.grid.getGridEl().dom);
37370 // ??? needed ??? config.el = this.wrapper;
37375 // xtype created footer. - not sure if will work as we normally have to render first..
37376 if (this.footer && !this.footer.el && this.footer.xtype) {
37378 var ctr = this.grid.getView().getFooterPanel(true);
37379 this.footer.dataSource = this.grid.dataSource;
37380 this.footer = Roo.factory(this.footer, Roo);
37381 this.footer.render(ctr);
37391 Roo.extend(Roo.bootstrap.panel.Grid, Roo.bootstrap.panel.Content, {
37392 getId : function(){
37393 return this.grid.id;
37397 * Returns the grid for this panel
37398 * @return {Roo.bootstrap.Table}
37400 getGrid : function(){
37404 setSize : function(width, height){
37405 if(!this.ignoreResize(width, height)){
37406 var grid = this.grid;
37407 var size = this.adjustForComponents(width, height);
37408 var gridel = grid.getGridEl();
37409 gridel.setSize(size.width, size.height);
37411 var thd = grid.getGridEl().select('thead',true).first();
37412 var tbd = grid.getGridEl().select('tbody', true).first();
37414 tbd.setSize(width, height - thd.getHeight());
37423 beforeSlide : function(){
37424 this.grid.getView().scroller.clip();
37427 afterSlide : function(){
37428 this.grid.getView().scroller.unclip();
37431 destroy : function(){
37432 this.grid.destroy();
37434 Roo.bootstrap.panel.Grid.superclass.destroy.call(this);
37439 * @class Roo.bootstrap.panel.Nest
37440 * @extends Roo.bootstrap.panel.Content
37442 * Create a new Panel, that can contain a layout.Border.
37445 * @param {Roo.BorderLayout} layout The layout for this panel
37446 * @param {String/Object} config A string to set only the title or a config object
37448 Roo.bootstrap.panel.Nest = function(config)
37450 // construct with only one argument..
37451 /* FIXME - implement nicer consturctors
37452 if (layout.layout) {
37454 layout = config.layout;
37455 delete config.layout;
37457 if (layout.xtype && !layout.getEl) {
37458 // then layout needs constructing..
37459 layout = Roo.factory(layout, Roo);
37463 config.el = config.layout.getEl();
37465 Roo.bootstrap.panel.Nest.superclass.constructor.call(this, config);
37467 config.layout.monitorWindowResize = false; // turn off autosizing
37468 this.layout = config.layout;
37469 this.layout.getEl().addClass("roo-layout-nested-layout");
37476 Roo.extend(Roo.bootstrap.panel.Nest, Roo.bootstrap.panel.Content, {
37478 setSize : function(width, height){
37479 if(!this.ignoreResize(width, height)){
37480 var size = this.adjustForComponents(width, height);
37481 var el = this.layout.getEl();
37482 if (size.height < 1) {
37483 el.setWidth(size.width);
37485 el.setSize(size.width, size.height);
37487 var touch = el.dom.offsetWidth;
37488 this.layout.layout();
37489 // ie requires a double layout on the first pass
37490 if(Roo.isIE && !this.initialized){
37491 this.initialized = true;
37492 this.layout.layout();
37497 // activate all subpanels if not currently active..
37499 setActiveState : function(active){
37500 this.active = active;
37501 this.setActiveClass(active);
37504 this.fireEvent("deactivate", this);
37508 this.fireEvent("activate", this);
37509 // not sure if this should happen before or after..
37510 if (!this.layout) {
37511 return; // should not happen..
37514 for (var r in this.layout.regions) {
37515 reg = this.layout.getRegion(r);
37516 if (reg.getActivePanel()) {
37517 //reg.showPanel(reg.getActivePanel()); // force it to activate..
37518 reg.setActivePanel(reg.getActivePanel());
37521 if (!reg.panels.length) {
37524 reg.showPanel(reg.getPanel(0));
37533 * Returns the nested BorderLayout for this panel
37534 * @return {Roo.BorderLayout}
37536 getLayout : function(){
37537 return this.layout;
37541 * Adds a xtype elements to the layout of the nested panel
37545 xtype : 'ContentPanel',
37552 xtype : 'NestedLayoutPanel',
37558 items : [ ... list of content panels or nested layout panels.. ]
37562 * @param {Object} cfg Xtype definition of item to add.
37564 addxtype : function(cfg) {
37565 return this.layout.addxtype(cfg);
37570 * Ext JS Library 1.1.1
37571 * Copyright(c) 2006-2007, Ext JS, LLC.
37573 * Originally Released Under LGPL - original licence link has changed is not relivant.
37576 * <script type="text/javascript">
37579 * @class Roo.TabPanel
37580 * @extends Roo.util.Observable
37581 * A lightweight tab container.
37585 // basic tabs 1, built from existing content
37586 var tabs = new Roo.TabPanel("tabs1");
37587 tabs.addTab("script", "View Script");
37588 tabs.addTab("markup", "View Markup");
37589 tabs.activate("script");
37591 // more advanced tabs, built from javascript
37592 var jtabs = new Roo.TabPanel("jtabs");
37593 jtabs.addTab("jtabs-1", "Normal Tab", "My content was added during construction.");
37595 // set up the UpdateManager
37596 var tab2 = jtabs.addTab("jtabs-2", "Ajax Tab 1");
37597 var updater = tab2.getUpdateManager();
37598 updater.setDefaultUrl("ajax1.htm");
37599 tab2.on('activate', updater.refresh, updater, true);
37601 // Use setUrl for Ajax loading
37602 var tab3 = jtabs.addTab("jtabs-3", "Ajax Tab 2");
37603 tab3.setUrl("ajax2.htm", null, true);
37606 var tab4 = jtabs.addTab("tabs1-5", "Disabled Tab", "Can't see me cause I'm disabled");
37609 jtabs.activate("jtabs-1");
37612 * Create a new TabPanel.
37613 * @param {String/HTMLElement/Roo.Element} container The id, DOM element or Roo.Element container where this TabPanel is to be rendered.
37614 * @param {Object/Boolean} config Config object to set any properties for this TabPanel, or true to render the tabs on the bottom.
37616 Roo.bootstrap.panel.Tabs = function(config){
37618 * The container element for this TabPanel.
37619 * @type Roo.Element
37621 this.el = Roo.get(config.el);
37624 if(typeof config == "boolean"){
37625 this.tabPosition = config ? "bottom" : "top";
37627 Roo.apply(this, config);
37631 if(this.tabPosition == "bottom"){
37632 this.bodyEl = Roo.get(this.createBody(this.el.dom));
37633 this.el.addClass("roo-tabs-bottom");
37635 this.stripWrap = Roo.get(this.createStrip(this.el.dom), true);
37636 this.stripEl = Roo.get(this.createStripList(this.stripWrap.dom), true);
37637 this.stripBody = Roo.get(this.stripWrap.dom.firstChild.firstChild, true);
37639 Roo.fly(this.stripWrap.dom.firstChild).setStyle("overflow-x", "hidden");
37641 if(this.tabPosition != "bottom"){
37642 /** The body element that contains {@link Roo.TabPanelItem} bodies. +
37643 * @type Roo.Element
37645 this.bodyEl = Roo.get(this.createBody(this.el.dom));
37646 this.el.addClass("roo-tabs-top");
37650 this.bodyEl.setStyle("position", "relative");
37652 this.active = null;
37653 this.activateDelegate = this.activate.createDelegate(this);
37658 * Fires when the active tab changes
37659 * @param {Roo.TabPanel} this
37660 * @param {Roo.TabPanelItem} activePanel The new active tab
37664 * @event beforetabchange
37665 * Fires before the active tab changes, set cancel to true on the "e" parameter to cancel the change
37666 * @param {Roo.TabPanel} this
37667 * @param {Object} e Set cancel to true on this object to cancel the tab change
37668 * @param {Roo.TabPanelItem} tab The tab being changed to
37670 "beforetabchange" : true
37673 Roo.EventManager.onWindowResize(this.onResize, this);
37674 this.cpad = this.el.getPadding("lr");
37675 this.hiddenCount = 0;
37678 // toolbar on the tabbar support...
37679 if (this.toolbar) {
37680 alert("no toolbar support yet");
37681 this.toolbar = false;
37683 var tcfg = this.toolbar;
37684 tcfg.container = this.stripEl.child('td.x-tab-strip-toolbar');
37685 this.toolbar = new Roo.Toolbar(tcfg);
37686 if (Roo.isSafari) {
37687 var tbl = tcfg.container.child('table', true);
37688 tbl.setAttribute('width', '100%');
37696 Roo.bootstrap.panel.Tabs.superclass.constructor.call(this);
37699 Roo.extend(Roo.bootstrap.panel.Tabs, Roo.util.Observable, {
37701 *@cfg {String} tabPosition "top" or "bottom" (defaults to "top")
37703 tabPosition : "top",
37705 *@cfg {Number} currentTabWidth The width of the current tab (defaults to 0)
37707 currentTabWidth : 0,
37709 *@cfg {Number} minTabWidth The minimum width of a tab (defaults to 40) (ignored if {@link #resizeTabs} is not true)
37713 *@cfg {Number} maxTabWidth The maximum width of a tab (defaults to 250) (ignored if {@link #resizeTabs} is not true)
37717 *@cfg {Number} preferredTabWidth The preferred (default) width of a tab (defaults to 175) (ignored if {@link #resizeTabs} is not true)
37719 preferredTabWidth : 175,
37721 *@cfg {Boolean} resizeTabs True to enable dynamic tab resizing (defaults to false)
37723 resizeTabs : false,
37725 *@cfg {Boolean} monitorResize Set this to true to turn on window resize monitoring (ignored if {@link #resizeTabs} is not true) (defaults to true)
37727 monitorResize : true,
37729 *@cfg {Object} toolbar xtype description of toolbar to show at the right of the tab bar.
37734 * Creates a new {@link Roo.TabPanelItem} by looking for an existing element with the provided id -- if it's not found it creates one.
37735 * @param {String} id The id of the div to use <b>or create</b>
37736 * @param {String} text The text for the tab
37737 * @param {String} content (optional) Content to put in the TabPanelItem body
37738 * @param {Boolean} closable (optional) True to create a close icon on the tab
37739 * @return {Roo.TabPanelItem} The created TabPanelItem
37741 addTab : function(id, text, content, closable, tpl)
37743 var item = new Roo.bootstrap.panel.TabItem({
37747 closable : closable,
37750 this.addTabItem(item);
37752 item.setContent(content);
37758 * Returns the {@link Roo.TabPanelItem} with the specified id/index
37759 * @param {String/Number} id The id or index of the TabPanelItem to fetch.
37760 * @return {Roo.TabPanelItem}
37762 getTab : function(id){
37763 return this.items[id];
37767 * Hides the {@link Roo.TabPanelItem} with the specified id/index
37768 * @param {String/Number} id The id or index of the TabPanelItem to hide.
37770 hideTab : function(id){
37771 var t = this.items[id];
37774 this.hiddenCount++;
37775 this.autoSizeTabs();
37780 * "Unhides" the {@link Roo.TabPanelItem} with the specified id/index.
37781 * @param {String/Number} id The id or index of the TabPanelItem to unhide.
37783 unhideTab : function(id){
37784 var t = this.items[id];
37786 t.setHidden(false);
37787 this.hiddenCount--;
37788 this.autoSizeTabs();
37793 * Adds an existing {@link Roo.TabPanelItem}.
37794 * @param {Roo.TabPanelItem} item The TabPanelItem to add
37796 addTabItem : function(item){
37797 this.items[item.id] = item;
37798 this.items.push(item);
37799 // if(this.resizeTabs){
37800 // item.setWidth(this.currentTabWidth || this.preferredTabWidth);
37801 // this.autoSizeTabs();
37803 // item.autoSize();
37808 * Removes a {@link Roo.TabPanelItem}.
37809 * @param {String/Number} id The id or index of the TabPanelItem to remove.
37811 removeTab : function(id){
37812 var items = this.items;
37813 var tab = items[id];
37814 if(!tab) { return; }
37815 var index = items.indexOf(tab);
37816 if(this.active == tab && items.length > 1){
37817 var newTab = this.getNextAvailable(index);
37822 this.stripEl.dom.removeChild(tab.pnode.dom);
37823 if(tab.bodyEl.dom.parentNode == this.bodyEl.dom){ // if it was moved already prevent error
37824 this.bodyEl.dom.removeChild(tab.bodyEl.dom);
37826 items.splice(index, 1);
37827 delete this.items[tab.id];
37828 tab.fireEvent("close", tab);
37829 tab.purgeListeners();
37830 this.autoSizeTabs();
37833 getNextAvailable : function(start){
37834 var items = this.items;
37836 // look for a next tab that will slide over to
37837 // replace the one being removed
37838 while(index < items.length){
37839 var item = items[++index];
37840 if(item && !item.isHidden()){
37844 // if one isn't found select the previous tab (on the left)
37847 var item = items[--index];
37848 if(item && !item.isHidden()){
37856 * Disables a {@link Roo.TabPanelItem}. It cannot be the active tab, if it is this call is ignored.
37857 * @param {String/Number} id The id or index of the TabPanelItem to disable.
37859 disableTab : function(id){
37860 var tab = this.items[id];
37861 if(tab && this.active != tab){
37867 * Enables a {@link Roo.TabPanelItem} that is disabled.
37868 * @param {String/Number} id The id or index of the TabPanelItem to enable.
37870 enableTab : function(id){
37871 var tab = this.items[id];
37876 * Activates a {@link Roo.TabPanelItem}. The currently active one will be deactivated.
37877 * @param {String/Number} id The id or index of the TabPanelItem to activate.
37878 * @return {Roo.TabPanelItem} The TabPanelItem.
37880 activate : function(id){
37881 var tab = this.items[id];
37885 if(tab == this.active || tab.disabled){
37889 this.fireEvent("beforetabchange", this, e, tab);
37890 if(e.cancel !== true && !tab.disabled){
37892 this.active.hide();
37894 this.active = this.items[id];
37895 this.active.show();
37896 this.fireEvent("tabchange", this, this.active);
37902 * Gets the active {@link Roo.TabPanelItem}.
37903 * @return {Roo.TabPanelItem} The active TabPanelItem or null if none are active.
37905 getActiveTab : function(){
37906 return this.active;
37910 * Updates the tab body element to fit the height of the container element
37911 * for overflow scrolling
37912 * @param {Number} targetHeight (optional) Override the starting height from the elements height
37914 syncHeight : function(targetHeight){
37915 var height = (targetHeight || this.el.getHeight())-this.el.getBorderWidth("tb")-this.el.getPadding("tb");
37916 var bm = this.bodyEl.getMargins();
37917 var newHeight = height-(this.stripWrap.getHeight()||0)-(bm.top+bm.bottom);
37918 this.bodyEl.setHeight(newHeight);
37922 onResize : function(){
37923 if(this.monitorResize){
37924 this.autoSizeTabs();
37929 * Disables tab resizing while tabs are being added (if {@link #resizeTabs} is false this does nothing)
37931 beginUpdate : function(){
37932 this.updating = true;
37936 * Stops an update and resizes the tabs (if {@link #resizeTabs} is false this does nothing)
37938 endUpdate : function(){
37939 this.updating = false;
37940 this.autoSizeTabs();
37944 * Manual call to resize the tabs (if {@link #resizeTabs} is false this does nothing)
37946 autoSizeTabs : function(){
37947 var count = this.items.length;
37948 var vcount = count - this.hiddenCount;
37949 if(!this.resizeTabs || count < 1 || vcount < 1 || this.updating) {
37952 var w = Math.max(this.el.getWidth() - this.cpad, 10);
37953 var availWidth = Math.floor(w / vcount);
37954 var b = this.stripBody;
37955 if(b.getWidth() > w){
37956 var tabs = this.items;
37957 this.setTabWidth(Math.max(availWidth, this.minTabWidth)-2);
37958 if(availWidth < this.minTabWidth){
37959 /*if(!this.sleft){ // incomplete scrolling code
37960 this.createScrollButtons();
37963 this.stripClip.setWidth(w - (this.sleft.getWidth()+this.sright.getWidth()));*/
37966 if(this.currentTabWidth < this.preferredTabWidth){
37967 this.setTabWidth(Math.min(availWidth, this.preferredTabWidth)-2);
37973 * Returns the number of tabs in this TabPanel.
37976 getCount : function(){
37977 return this.items.length;
37981 * Resizes all the tabs to the passed width
37982 * @param {Number} The new width
37984 setTabWidth : function(width){
37985 this.currentTabWidth = width;
37986 for(var i = 0, len = this.items.length; i < len; i++) {
37987 if(!this.items[i].isHidden()) {
37988 this.items[i].setWidth(width);
37994 * Destroys this TabPanel
37995 * @param {Boolean} removeEl (optional) True to remove the element from the DOM as well (defaults to undefined)
37997 destroy : function(removeEl){
37998 Roo.EventManager.removeResizeListener(this.onResize, this);
37999 for(var i = 0, len = this.items.length; i < len; i++){
38000 this.items[i].purgeListeners();
38002 if(removeEl === true){
38003 this.el.update("");
38008 createStrip : function(container)
38010 var strip = document.createElement("nav");
38011 strip.className = "navbar navbar-default"; //"x-tabs-wrap";
38012 container.appendChild(strip);
38016 createStripList : function(strip)
38018 // div wrapper for retard IE
38019 // returns the "tr" element.
38020 strip.innerHTML = '<ul class="nav nav-tabs" role="tablist"></ul>';
38021 //'<div class="x-tabs-strip-wrap">'+
38022 // '<table class="x-tabs-strip" cellspacing="0" cellpadding="0" border="0"><tbody><tr>'+
38023 // '<td class="x-tab-strip-toolbar"></td></tr></tbody></table></div>';
38024 return strip.firstChild; //.firstChild.firstChild.firstChild;
38026 createBody : function(container)
38028 var body = document.createElement("div");
38029 Roo.id(body, "tab-body");
38030 //Roo.fly(body).addClass("x-tabs-body");
38031 Roo.fly(body).addClass("tab-content");
38032 container.appendChild(body);
38035 createItemBody :function(bodyEl, id){
38036 var body = Roo.getDom(id);
38038 body = document.createElement("div");
38041 //Roo.fly(body).addClass("x-tabs-item-body");
38042 Roo.fly(body).addClass("tab-pane");
38043 bodyEl.insertBefore(body, bodyEl.firstChild);
38047 createStripElements : function(stripEl, text, closable, tpl)
38049 var td = document.createElement("li"); // was td..
38052 //stripEl.insertBefore(td, stripEl.childNodes[stripEl.childNodes.length-1]);
38055 stripEl.appendChild(td);
38057 td.className = "x-tabs-closable";
38058 if(!this.closeTpl){
38059 this.closeTpl = new Roo.Template(
38060 '<a href="#" class="x-tabs-right"><span class="x-tabs-left"><em class="x-tabs-inner">' +
38061 '<span unselectable="on"' + (this.disableTooltips ? '' : ' title="{text}"') +' class="x-tabs-text">{text}</span>' +
38062 '<div unselectable="on" class="close-icon"> </div></em></span></a>'
38065 var el = this.closeTpl.overwrite(td, {"text": text});
38066 var close = el.getElementsByTagName("div")[0];
38067 var inner = el.getElementsByTagName("em")[0];
38068 return {"el": el, "close": close, "inner": inner};
38071 // not sure what this is..
38072 // if(!this.tabTpl){
38073 //this.tabTpl = new Roo.Template(
38074 // '<a href="#" class="x-tabs-right"><span class="x-tabs-left"><em class="x-tabs-inner">' +
38075 // '<span unselectable="on"' + (this.disableTooltips ? '' : ' title="{text}"') +' class="x-tabs-text">{text}</span></em></span></a>'
38077 // this.tabTpl = new Roo.Template(
38078 // '<a href="#">' +
38079 // '<span unselectable="on"' +
38080 // (this.disableTooltips ? '' : ' title="{text}"') +
38081 // ' >{text}</span></a>'
38087 var template = tpl || this.tabTpl || false;
38091 template = new Roo.Template(
38093 '<span unselectable="on"' +
38094 (this.disableTooltips ? '' : ' title="{text}"') +
38095 ' >{text}</span></a>'
38099 switch (typeof(template)) {
38103 template = new Roo.Template(template);
38109 var el = template.overwrite(td, {"text": text});
38111 var inner = el.getElementsByTagName("span")[0];
38113 return {"el": el, "inner": inner};
38121 * @class Roo.TabPanelItem
38122 * @extends Roo.util.Observable
38123 * Represents an individual item (tab plus body) in a TabPanel.
38124 * @param {Roo.TabPanel} tabPanel The {@link Roo.TabPanel} this TabPanelItem belongs to
38125 * @param {String} id The id of this TabPanelItem
38126 * @param {String} text The text for the tab of this TabPanelItem
38127 * @param {Boolean} closable True to allow this TabPanelItem to be closable (defaults to false)
38129 Roo.bootstrap.panel.TabItem = function(config){
38131 * The {@link Roo.TabPanel} this TabPanelItem belongs to
38132 * @type Roo.TabPanel
38134 this.tabPanel = config.panel;
38136 * The id for this TabPanelItem
38139 this.id = config.id;
38141 this.disabled = false;
38143 this.text = config.text;
38145 this.loaded = false;
38146 this.closable = config.closable;
38149 * The body element for this TabPanelItem.
38150 * @type Roo.Element
38152 this.bodyEl = Roo.get(this.tabPanel.createItemBody(this.tabPanel.bodyEl.dom, config.id));
38153 this.bodyEl.setVisibilityMode(Roo.Element.VISIBILITY);
38154 this.bodyEl.setStyle("display", "block");
38155 this.bodyEl.setStyle("zoom", "1");
38156 //this.hideAction();
38158 var els = this.tabPanel.createStripElements(this.tabPanel.stripEl.dom, config.text, config.closable, config.tpl);
38160 this.el = Roo.get(els.el);
38161 this.inner = Roo.get(els.inner, true);
38162 this.textEl = Roo.get(this.el.dom.firstChild, true);
38163 this.pnode = Roo.get(els.el.parentNode, true);
38164 // this.el.on("mousedown", this.onTabMouseDown, this);
38165 this.el.on("click", this.onTabClick, this);
38167 if(config.closable){
38168 var c = Roo.get(els.close, true);
38169 c.dom.title = this.closeText;
38170 c.addClassOnOver("close-over");
38171 c.on("click", this.closeClick, this);
38177 * Fires when this tab becomes the active tab.
38178 * @param {Roo.TabPanel} tabPanel The parent TabPanel
38179 * @param {Roo.TabPanelItem} this
38183 * @event beforeclose
38184 * Fires before this tab is closed. To cancel the close, set cancel to true on e (e.cancel = true).
38185 * @param {Roo.TabPanelItem} this
38186 * @param {Object} e Set cancel to true on this object to cancel the close.
38188 "beforeclose": true,
38191 * Fires when this tab is closed.
38192 * @param {Roo.TabPanelItem} this
38196 * @event deactivate
38197 * Fires when this tab is no longer the active tab.
38198 * @param {Roo.TabPanel} tabPanel The parent TabPanel
38199 * @param {Roo.TabPanelItem} this
38201 "deactivate" : true
38203 this.hidden = false;
38205 Roo.bootstrap.panel.TabItem.superclass.constructor.call(this);
38208 Roo.extend(Roo.bootstrap.panel.TabItem, Roo.util.Observable,
38210 purgeListeners : function(){
38211 Roo.util.Observable.prototype.purgeListeners.call(this);
38212 this.el.removeAllListeners();
38215 * Shows this TabPanelItem -- this <b>does not</b> deactivate the currently active TabPanelItem.
38218 this.pnode.addClass("active");
38221 this.tabPanel.stripWrap.repaint();
38223 this.fireEvent("activate", this.tabPanel, this);
38227 * Returns true if this tab is the active tab.
38228 * @return {Boolean}
38230 isActive : function(){
38231 return this.tabPanel.getActiveTab() == this;
38235 * Hides this TabPanelItem -- if you don't activate another TabPanelItem this could look odd.
38238 this.pnode.removeClass("active");
38240 this.fireEvent("deactivate", this.tabPanel, this);
38243 hideAction : function(){
38244 this.bodyEl.hide();
38245 this.bodyEl.setStyle("position", "absolute");
38246 this.bodyEl.setLeft("-20000px");
38247 this.bodyEl.setTop("-20000px");
38250 showAction : function(){
38251 this.bodyEl.setStyle("position", "relative");
38252 this.bodyEl.setTop("");
38253 this.bodyEl.setLeft("");
38254 this.bodyEl.show();
38258 * Set the tooltip for the tab.
38259 * @param {String} tooltip The tab's tooltip
38261 setTooltip : function(text){
38262 if(Roo.QuickTips && Roo.QuickTips.isEnabled()){
38263 this.textEl.dom.qtip = text;
38264 this.textEl.dom.removeAttribute('title');
38266 this.textEl.dom.title = text;
38270 onTabClick : function(e){
38271 e.preventDefault();
38272 this.tabPanel.activate(this.id);
38275 onTabMouseDown : function(e){
38276 e.preventDefault();
38277 this.tabPanel.activate(this.id);
38280 getWidth : function(){
38281 return this.inner.getWidth();
38284 setWidth : function(width){
38285 var iwidth = width - this.pnode.getPadding("lr");
38286 this.inner.setWidth(iwidth);
38287 this.textEl.setWidth(iwidth-this.inner.getPadding("lr"));
38288 this.pnode.setWidth(width);
38292 * Show or hide the tab
38293 * @param {Boolean} hidden True to hide or false to show.
38295 setHidden : function(hidden){
38296 this.hidden = hidden;
38297 this.pnode.setStyle("display", hidden ? "none" : "");
38301 * Returns true if this tab is "hidden"
38302 * @return {Boolean}
38304 isHidden : function(){
38305 return this.hidden;
38309 * Returns the text for this tab
38312 getText : function(){
38316 autoSize : function(){
38317 //this.el.beginMeasure();
38318 this.textEl.setWidth(1);
38320 * #2804 [new] Tabs in Roojs
38321 * increase the width by 2-4 pixels to prevent the ellipssis showing in chrome
38323 //this.setWidth(this.textEl.dom.scrollWidth+this.pnode.getPadding("lr")+this.inner.getPadding("lr") + 2);
38324 //this.el.endMeasure();
38328 * Sets the text for the tab (Note: this also sets the tooltip text)
38329 * @param {String} text The tab's text and tooltip
38331 setText : function(text){
38333 this.textEl.update(text);
38334 this.setTooltip(text);
38335 //if(!this.tabPanel.resizeTabs){
38336 // this.autoSize();
38340 * Activates this TabPanelItem -- this <b>does</b> deactivate the currently active TabPanelItem.
38342 activate : function(){
38343 this.tabPanel.activate(this.id);
38347 * Disables this TabPanelItem -- this does nothing if this is the active TabPanelItem.
38349 disable : function(){
38350 if(this.tabPanel.active != this){
38351 this.disabled = true;
38352 this.pnode.addClass("disabled");
38357 * Enables this TabPanelItem if it was previously disabled.
38359 enable : function(){
38360 this.disabled = false;
38361 this.pnode.removeClass("disabled");
38365 * Sets the content for this TabPanelItem.
38366 * @param {String} content The content
38367 * @param {Boolean} loadScripts true to look for and load scripts
38369 setContent : function(content, loadScripts){
38370 this.bodyEl.update(content, loadScripts);
38374 * Gets the {@link Roo.UpdateManager} for the body of this TabPanelItem. Enables you to perform Ajax updates.
38375 * @return {Roo.UpdateManager} The UpdateManager
38377 getUpdateManager : function(){
38378 return this.bodyEl.getUpdateManager();
38382 * Set a URL to be used to load the content for this TabPanelItem.
38383 * @param {String/Function} url The URL to load the content from, or a function to call to get the URL
38384 * @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)
38385 * @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)
38386 * @return {Roo.UpdateManager} The UpdateManager
38388 setUrl : function(url, params, loadOnce){
38389 if(this.refreshDelegate){
38390 this.un('activate', this.refreshDelegate);
38392 this.refreshDelegate = this._handleRefresh.createDelegate(this, [url, params, loadOnce]);
38393 this.on("activate", this.refreshDelegate);
38394 return this.bodyEl.getUpdateManager();
38398 _handleRefresh : function(url, params, loadOnce){
38399 if(!loadOnce || !this.loaded){
38400 var updater = this.bodyEl.getUpdateManager();
38401 updater.update(url, params, this._setLoaded.createDelegate(this));
38406 * Forces a content refresh from the URL specified in the {@link #setUrl} method.
38407 * Will fail silently if the setUrl method has not been called.
38408 * This does not activate the panel, just updates its content.
38410 refresh : function(){
38411 if(this.refreshDelegate){
38412 this.loaded = false;
38413 this.refreshDelegate();
38418 _setLoaded : function(){
38419 this.loaded = true;
38423 closeClick : function(e){
38426 this.fireEvent("beforeclose", this, o);
38427 if(o.cancel !== true){
38428 this.tabPanel.removeTab(this.id);
38432 * The text displayed in the tooltip for the close icon.
38435 closeText : "Close this tab"
38438 * This script refer to:
38439 * Title: International Telephone Input
38440 * Author: Jack O'Connor
38441 * Code version: v12.1.12
38442 * Availability: https://github.com/jackocnr/intl-tel-input.git
38445 Roo.bootstrap.PhoneInputData = function() {
38448 "Afghanistan (افغانستان)",
38453 "Albania (Shqipëri)",
38458 "Algeria (الجزائر)",
38483 "Antigua and Barbuda",
38493 "Armenia (Հայաստան)",
38509 "Austria (Österreich)",
38514 "Azerbaijan (Azərbaycan)",
38524 "Bahrain (البحرين)",
38529 "Bangladesh (বাংলাদেশ)",
38539 "Belarus (Беларусь)",
38544 "Belgium (België)",
38574 "Bosnia and Herzegovina (Босна и Херцеговина)",
38589 "British Indian Ocean Territory",
38594 "British Virgin Islands",
38604 "Bulgaria (България)",
38614 "Burundi (Uburundi)",
38619 "Cambodia (កម្ពុជា)",
38624 "Cameroon (Cameroun)",
38633 ["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"]
38636 "Cape Verde (Kabu Verdi)",
38641 "Caribbean Netherlands",
38652 "Central African Republic (République centrafricaine)",
38672 "Christmas Island",
38678 "Cocos (Keeling) Islands",
38689 "Comoros (جزر القمر)",
38694 "Congo (DRC) (Jamhuri ya Kidemokrasia ya Kongo)",
38699 "Congo (Republic) (Congo-Brazzaville)",
38719 "Croatia (Hrvatska)",
38740 "Czech Republic (Česká republika)",
38745 "Denmark (Danmark)",
38760 "Dominican Republic (República Dominicana)",
38764 ["809", "829", "849"]
38782 "Equatorial Guinea (Guinea Ecuatorial)",
38802 "Falkland Islands (Islas Malvinas)",
38807 "Faroe Islands (Føroyar)",
38828 "French Guiana (Guyane française)",
38833 "French Polynesia (Polynésie française)",
38848 "Georgia (საქართველო)",
38853 "Germany (Deutschland)",
38873 "Greenland (Kalaallit Nunaat)",
38910 "Guinea-Bissau (Guiné Bissau)",
38935 "Hungary (Magyarország)",
38940 "Iceland (Ísland)",
38960 "Iraq (العراق)",
38976 "Israel (ישראל)",
39003 "Jordan (الأردن)",
39008 "Kazakhstan (Казахстан)",
39029 "Kuwait (الكويت)",
39034 "Kyrgyzstan (Кыргызстан)",
39044 "Latvia (Latvija)",
39049 "Lebanon (لبنان)",
39064 "Libya (ليبيا)",
39074 "Lithuania (Lietuva)",
39089 "Macedonia (FYROM) (Македонија)",
39094 "Madagascar (Madagasikara)",
39124 "Marshall Islands",
39134 "Mauritania (موريتانيا)",
39139 "Mauritius (Moris)",
39160 "Moldova (Republica Moldova)",
39170 "Mongolia (Монгол)",
39175 "Montenegro (Crna Gora)",
39185 "Morocco (المغرب)",
39191 "Mozambique (Moçambique)",
39196 "Myanmar (Burma) (မြန်မာ)",
39201 "Namibia (Namibië)",
39216 "Netherlands (Nederland)",
39221 "New Caledonia (Nouvelle-Calédonie)",
39256 "North Korea (조선 민주주의 인민 공화국)",
39261 "Northern Mariana Islands",
39277 "Pakistan (پاکستان)",
39287 "Palestine (فلسطين)",
39297 "Papua New Guinea",
39339 "Réunion (La Réunion)",
39345 "Romania (România)",
39361 "Saint Barthélemy",
39372 "Saint Kitts and Nevis",
39382 "Saint Martin (Saint-Martin (partie française))",
39388 "Saint Pierre and Miquelon (Saint-Pierre-et-Miquelon)",
39393 "Saint Vincent and the Grenadines",
39408 "São Tomé and Príncipe (São Tomé e Príncipe)",
39413 "Saudi Arabia (المملكة العربية السعودية)",
39418 "Senegal (Sénégal)",
39448 "Slovakia (Slovensko)",
39453 "Slovenia (Slovenija)",
39463 "Somalia (Soomaaliya)",
39473 "South Korea (대한민국)",
39478 "South Sudan (جنوب السودان)",
39488 "Sri Lanka (ශ්රී ලංකාව)",
39493 "Sudan (السودان)",
39503 "Svalbard and Jan Mayen",
39514 "Sweden (Sverige)",
39519 "Switzerland (Schweiz)",
39524 "Syria (سوريا)",
39569 "Trinidad and Tobago",
39574 "Tunisia (تونس)",
39579 "Turkey (Türkiye)",
39589 "Turks and Caicos Islands",
39599 "U.S. Virgin Islands",
39609 "Ukraine (Україна)",
39614 "United Arab Emirates (الإمارات العربية المتحدة)",
39636 "Uzbekistan (Oʻzbekiston)",
39646 "Vatican City (Città del Vaticano)",
39657 "Vietnam (Việt Nam)",
39662 "Wallis and Futuna (Wallis-et-Futuna)",
39667 "Western Sahara (الصحراء الغربية)",
39673 "Yemen (اليمن)",
39697 * This script refer to:
39698 * Title: International Telephone Input
39699 * Author: Jack O'Connor
39700 * Code version: v12.1.12
39701 * Availability: https://github.com/jackocnr/intl-tel-input.git
39705 * @class Roo.bootstrap.PhoneInput
39706 * @extends Roo.bootstrap.TriggerField
39707 * An input with International dial-code selection
39709 * @cfg {String} defaultDialCode default '+852'
39710 * @cfg {Array} preferedCountries default []
39713 * Create a new PhoneInput.
39714 * @param {Object} config Configuration options
39717 Roo.bootstrap.PhoneInput = function(config) {
39718 Roo.bootstrap.PhoneInput.superclass.constructor.call(this, config);
39721 Roo.extend(Roo.bootstrap.PhoneInput, Roo.bootstrap.TriggerField, {
39723 listWidth: undefined,
39725 selectedClass: 'active',
39727 invalidClass : "has-warning",
39729 validClass: 'has-success',
39731 allowed: '0123456789',
39734 * @cfg {String} defaultDialCode The default dial code when initializing the input
39736 defaultDialCode: '+852',
39739 * @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
39741 preferedCountries: false,
39743 getAutoCreate : function()
39745 var data = Roo.bootstrap.PhoneInputData();
39746 var align = this.labelAlign || this.parentLabelAlign();
39749 this.allCountries = [];
39750 this.dialCodeMapping = [];
39752 for (var i = 0; i < data.length; i++) {
39754 this.allCountries[i] = {
39758 priority: c[3] || 0,
39759 areaCodes: c[4] || null
39761 this.dialCodeMapping[c[2]] = {
39764 priority: c[3] || 0,
39765 areaCodes: c[4] || null
39777 cls : 'form-control tel-input',
39778 autocomplete: 'new-password'
39781 var hiddenInput = {
39784 cls: 'hidden-tel-input'
39788 hiddenInput.name = this.name;
39791 if (this.disabled) {
39792 input.disabled = true;
39795 var flag_container = {
39812 cls: this.hasFeedback ? 'has-feedback' : '',
39818 cls: 'dial-code-holder',
39825 cls: 'roo-select2-container input-group',
39832 if (this.fieldLabel.length) {
39835 tooltip: 'This field is required'
39841 cls: 'control-label',
39847 html: this.fieldLabel
39850 indicator.cls = 'roo-required-indicator text-danger fa fa-lg fa-star left-indicator';
39856 if(this.indicatorpos == 'right') {
39857 indicator.cls = 'roo-required-indicator text-danger fa fa-lg fa-star right-indicator';
39864 if(align == 'left') {
39872 if(this.labelWidth > 12){
39873 label.style = "width: " + this.labelWidth + 'px';
39875 if(this.labelWidth < 13 && this.labelmd == 0){
39876 this.labelmd = this.labelWidth;
39878 if(this.labellg > 0){
39879 label.cls += ' col-lg-' + this.labellg;
39880 input.cls += ' col-lg-' + (12 - this.labellg);
39882 if(this.labelmd > 0){
39883 label.cls += ' col-md-' + this.labelmd;
39884 container.cls += ' col-md-' + (12 - this.labelmd);
39886 if(this.labelsm > 0){
39887 label.cls += ' col-sm-' + this.labelsm;
39888 container.cls += ' col-sm-' + (12 - this.labelsm);
39890 if(this.labelxs > 0){
39891 label.cls += ' col-xs-' + this.labelxs;
39892 container.cls += ' col-xs-' + (12 - this.labelxs);
39902 var settings = this;
39904 ['xs','sm','md','lg'].map(function(size){
39905 if (settings[size]) {
39906 cfg.cls += ' col-' + size + '-' + settings[size];
39910 this.store = new Roo.data.Store({
39911 proxy : new Roo.data.MemoryProxy({}),
39912 reader : new Roo.data.JsonReader({
39923 'name' : 'dialCode',
39927 'name' : 'priority',
39931 'name' : 'areaCodes',
39938 if(!this.preferedCountries) {
39939 this.preferedCountries = [
39946 var p = this.preferedCountries.reverse();
39949 for (var i = 0; i < p.length; i++) {
39950 for (var j = 0; j < this.allCountries.length; j++) {
39951 if(this.allCountries[j].iso2 == p[i]) {
39952 var t = this.allCountries[j];
39953 this.allCountries.splice(j,1);
39954 this.allCountries.unshift(t);
39960 this.store.proxy.data = {
39962 data: this.allCountries
39968 initEvents : function()
39971 Roo.bootstrap.PhoneInput.superclass.initEvents.call(this);
39973 this.indicator = this.indicatorEl();
39974 this.flag = this.flagEl();
39975 this.dialCodeHolder = this.dialCodeHolderEl();
39977 this.trigger = this.el.select('div.flag-box',true).first();
39978 this.trigger.on("click", this.onTriggerClick, this, {preventDefault:true});
39983 var lw = _this.listWidth || Math.max(_this.inputEl().getWidth(), _this.minListWidth);
39984 _this.list.setWidth(lw);
39987 this.list.on('mouseover', this.onViewOver, this);
39988 this.list.on('mousemove', this.onViewMove, this);
39989 this.inputEl().on("keyup", this.onKeyUp, this);
39991 this.tpl = '<li><a href="#"><div class="flag {iso2}"></div>{name} <span class="dial-code">+{dialCode}</span></a></li>';
39993 this.view = new Roo.View(this.list, this.tpl, {
39994 singleSelect:true, store: this.store, selectedClass: this.selectedClass
39997 this.view.on('click', this.onViewClick, this);
39998 this.setValue(this.defaultDialCode);
40001 onTriggerClick : function(e)
40003 Roo.log('trigger click');
40008 if(this.isExpanded()){
40010 this.hasFocus = false;
40012 this.store.load({});
40013 this.hasFocus = true;
40018 isExpanded : function()
40020 return this.list.isVisible();
40023 collapse : function()
40025 if(!this.isExpanded()){
40029 Roo.get(document).un('mousedown', this.collapseIf, this);
40030 Roo.get(document).un('mousewheel', this.collapseIf, this);
40031 this.fireEvent('collapse', this);
40035 expand : function()
40039 if(this.isExpanded() || !this.hasFocus){
40043 var lw = this.listWidth || Math.max(this.inputEl().getWidth(), this.minListWidth);
40044 this.list.setWidth(lw);
40047 this.restrictHeight();
40049 Roo.get(document).on('mousedown', this.collapseIf, this);
40050 Roo.get(document).on('mousewheel', this.collapseIf, this);
40052 this.fireEvent('expand', this);
40055 restrictHeight : function()
40057 this.list.alignTo(this.inputEl(), this.listAlign);
40058 this.list.alignTo(this.inputEl(), this.listAlign);
40061 onViewOver : function(e, t)
40063 if(this.inKeyMode){
40066 var item = this.view.findItemFromChild(t);
40069 var index = this.view.indexOf(item);
40070 this.select(index, false);
40075 onViewClick : function(view, doFocus, el, e)
40077 var index = this.view.getSelectedIndexes()[0];
40079 var r = this.store.getAt(index);
40082 this.onSelect(r, index);
40084 if(doFocus !== false && !this.blockFocus){
40085 this.inputEl().focus();
40089 onViewMove : function(e, t)
40091 this.inKeyMode = false;
40094 select : function(index, scrollIntoView)
40096 this.selectedIndex = index;
40097 this.view.select(index);
40098 if(scrollIntoView !== false){
40099 var el = this.view.getNode(index);
40101 this.list.scrollChildIntoView(el, false);
40106 createList : function()
40108 this.list = Roo.get(document.body).createChild({
40110 cls: 'typeahead typeahead-long dropdown-menu tel-list',
40111 style: 'display:none'
40114 this.list.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
40117 collapseIf : function(e)
40119 var in_combo = e.within(this.el);
40120 var in_list = e.within(this.list);
40121 var is_list = (Roo.get(e.getTarget()).id == this.list.id) ? true : false;
40123 if (in_combo || in_list || is_list) {
40129 onSelect : function(record, index)
40131 if(this.fireEvent('beforeselect', this, record, index) !== false){
40133 this.setFlagClass(record.data.iso2);
40134 this.setDialCode(record.data.dialCode);
40135 this.hasFocus = false;
40137 this.fireEvent('select', this, record, index);
40141 flagEl : function()
40143 var flag = this.el.select('div.flag',true).first();
40150 dialCodeHolderEl : function()
40152 var d = this.el.select('input.dial-code-holder',true).first();
40159 setDialCode : function(v)
40161 this.dialCodeHolder.dom.value = '+'+v;
40164 setFlagClass : function(n)
40166 this.flag.dom.className = 'flag '+n;
40169 getValue : function()
40171 var v = this.inputEl().getValue();
40172 if(this.dialCodeHolder) {
40173 v = this.dialCodeHolder.dom.value+this.inputEl().getValue();
40178 setValue : function(v)
40180 var d = this.getDialCode(v);
40182 //invalid dial code
40183 if(v.length == 0 || !d || d.length == 0) {
40185 this.inputEl().dom.value = (v === null || v === undefined ? '' : v);
40186 this.hiddenEl().dom.value = (v === null || v === undefined ? '' : v);
40192 this.setFlagClass(this.dialCodeMapping[d].iso2);
40193 this.setDialCode(d);
40194 this.inputEl().dom.value = v.replace('+'+d,'');
40195 this.hiddenEl().dom.value = this.getValue();
40200 getDialCode : function(v)
40204 if (v.length == 0) {
40205 return this.dialCodeHolder.dom.value;
40209 if (v.charAt(0) != "+") {
40212 var numericChars = "";
40213 for (var i = 1; i < v.length; i++) {
40214 var c = v.charAt(i);
40217 if (this.dialCodeMapping[numericChars]) {
40218 dialCode = v.substr(1, i);
40220 if (numericChars.length == 4) {
40230 this.setValue(this.defaultDialCode);
40234 hiddenEl : function()
40236 return this.el.select('input.hidden-tel-input',true).first();
40239 onKeyUp : function(e){
40241 var k = e.getKey();
40242 var c = e.getCharCode();
40245 (String.fromCharCode(c) == '.' || String.fromCharCode(c) == '-') &&
40246 this.allowed.indexOf(String.fromCharCode(c)) === -1
40251 // if(!Roo.isIE && (e.isSpecialKey() || k == e.BACKSPACE || k == e.DELETE)){
40254 if(this.allowed.indexOf(String.fromCharCode(c)) === -1){
40258 this.setValue(this.getValue());
40263 * @class Roo.bootstrap.MoneyField
40264 * @extends Roo.bootstrap.ComboBox
40265 * Bootstrap MoneyField class
40268 * Create a new MoneyField.
40269 * @param {Object} config Configuration options
40272 Roo.bootstrap.MoneyField = function(config) {
40274 Roo.bootstrap.MoneyField.superclass.constructor.call(this, config);
40278 Roo.extend(Roo.bootstrap.MoneyField, Roo.bootstrap.ComboBox, {
40281 * @cfg {Boolean} allowDecimals False to disallow decimal values (defaults to true)
40283 allowDecimals : true,
40285 * @cfg {String} decimalSeparator Character(s) to allow as the decimal separator (defaults to '.')
40287 decimalSeparator : ".",
40289 * @cfg {Number} decimalPrecision The maximum precision to display after the decimal separator (defaults to 2)
40291 decimalPrecision : 0,
40293 * @cfg {Boolean} allowNegative False to prevent entering a negative sign (defaults to true)
40295 allowNegative : true,
40297 * @cfg {Boolean} allowZero False to blank out if the user enters '0' (defaults to true)
40301 * @cfg {Number} minValue The minimum allowed value (defaults to Number.NEGATIVE_INFINITY)
40303 minValue : Number.NEGATIVE_INFINITY,
40305 * @cfg {Number} maxValue The maximum allowed value (defaults to Number.MAX_VALUE)
40307 maxValue : Number.MAX_VALUE,
40309 * @cfg {String} minText Error text to display if the minimum value validation fails (defaults to "The minimum value for this field is {minValue}")
40311 minText : "The minimum value for this field is {0}",
40313 * @cfg {String} maxText Error text to display if the maximum value validation fails (defaults to "The maximum value for this field is {maxValue}")
40315 maxText : "The maximum value for this field is {0}",
40317 * @cfg {String} nanText Error text to display if the value is not a valid number. For example, this can happen
40318 * if a valid character like '.' or '-' is left in the field with no number (defaults to "{value} is not a valid number")
40320 nanText : "{0} is not a valid number",
40322 * @cfg {Boolean} castInt (true|false) cast int if true (defalut true)
40326 * @cfg {String} defaults currency of the MoneyField
40327 * value should be in lkey
40329 defaultCurrency : false,
40331 * @cfg {String} thousandsDelimiter Symbol of thousandsDelimiter
40333 thousandsDelimiter : false,
40343 getAutoCreate : function()
40345 var align = this.labelAlign || this.parentLabelAlign();
40357 cls : 'form-control roo-money-amount-input',
40358 autocomplete: 'new-password'
40361 var hiddenInput = {
40365 cls: 'hidden-number-input'
40369 hiddenInput.name = this.name;
40372 if (this.disabled) {
40373 input.disabled = true;
40376 var clg = 12 - this.inputlg;
40377 var cmd = 12 - this.inputmd;
40378 var csm = 12 - this.inputsm;
40379 var cxs = 12 - this.inputxs;
40383 cls : 'row roo-money-field',
40387 cls : 'roo-money-currency column col-lg-' + clg + ' col-md-' + cmd + ' col-sm-' + csm + ' col-xs-' + cxs,
40391 cls: 'roo-select2-container input-group',
40395 cls : 'form-control roo-money-currency-input',
40396 autocomplete: 'new-password',
40398 name : this.currencyName
40402 cls : 'input-group-addon',
40416 cls : 'roo-money-amount column col-lg-' + this.inputlg + ' col-md-' + this.inputmd + ' col-sm-' + this.inputsm + ' col-xs-' + this.inputxs,
40420 cls: this.hasFeedback ? 'has-feedback' : '',
40431 if (this.fieldLabel.length) {
40434 tooltip: 'This field is required'
40440 cls: 'control-label',
40446 html: this.fieldLabel
40449 indicator.cls = 'roo-required-indicator text-danger fa fa-lg fa-star left-indicator';
40455 if(this.indicatorpos == 'right') {
40456 indicator.cls = 'roo-required-indicator text-danger fa fa-lg fa-star right-indicator';
40463 if(align == 'left') {
40471 if(this.labelWidth > 12){
40472 label.style = "width: " + this.labelWidth + 'px';
40474 if(this.labelWidth < 13 && this.labelmd == 0){
40475 this.labelmd = this.labelWidth;
40477 if(this.labellg > 0){
40478 label.cls += ' col-lg-' + this.labellg;
40479 input.cls += ' col-lg-' + (12 - this.labellg);
40481 if(this.labelmd > 0){
40482 label.cls += ' col-md-' + this.labelmd;
40483 container.cls += ' col-md-' + (12 - this.labelmd);
40485 if(this.labelsm > 0){
40486 label.cls += ' col-sm-' + this.labelsm;
40487 container.cls += ' col-sm-' + (12 - this.labelsm);
40489 if(this.labelxs > 0){
40490 label.cls += ' col-xs-' + this.labelxs;
40491 container.cls += ' col-xs-' + (12 - this.labelxs);
40502 var settings = this;
40504 ['xs','sm','md','lg'].map(function(size){
40505 if (settings[size]) {
40506 cfg.cls += ' col-' + size + '-' + settings[size];
40513 initEvents : function()
40515 this.indicator = this.indicatorEl();
40517 this.initCurrencyEvent();
40519 this.initNumberEvent();
40522 initCurrencyEvent : function()
40525 throw "can not find store for combo";
40528 this.store = Roo.factory(this.store, Roo.data);
40529 this.store.parent = this;
40533 this.triggerEl = this.el.select('.input-group-addon', true).first();
40535 this.triggerEl.on("click", this.onTriggerClick, this, { preventDefault : true });
40540 var lw = _this.listWidth || Math.max(_this.inputEl().getWidth(), _this.minListWidth);
40541 _this.list.setWidth(lw);
40544 this.list.on('mouseover', this.onViewOver, this);
40545 this.list.on('mousemove', this.onViewMove, this);
40546 this.list.on('scroll', this.onViewScroll, this);
40549 this.tpl = '<li><a href="#">{' + this.currencyField + '}</a></li>';
40552 this.view = new Roo.View(this.list, this.tpl, {
40553 singleSelect:true, store: this.store, selectedClass: this.selectedClass
40556 this.view.on('click', this.onViewClick, this);
40558 this.store.on('beforeload', this.onBeforeLoad, this);
40559 this.store.on('load', this.onLoad, this);
40560 this.store.on('loadexception', this.onLoadException, this);
40562 this.keyNav = new Roo.KeyNav(this.currencyEl(), {
40563 "up" : function(e){
40564 this.inKeyMode = true;
40568 "down" : function(e){
40569 if(!this.isExpanded()){
40570 this.onTriggerClick();
40572 this.inKeyMode = true;
40577 "enter" : function(e){
40580 if(this.fireEvent("specialkey", this, e)){
40581 this.onViewClick(false);
40587 "esc" : function(e){
40591 "tab" : function(e){
40594 if(this.fireEvent("specialkey", this, e)){
40595 this.onViewClick(false);
40603 doRelay : function(foo, bar, hname){
40604 if(hname == 'down' || this.scope.isExpanded()){
40605 return Roo.KeyNav.prototype.doRelay.apply(this, arguments);
40613 this.currencyEl().on("click", this.onTriggerClick, this, { preventDefault : true });
40617 initNumberEvent : function(e)
40619 this.inputEl().on("keydown" , this.fireKey, this);
40620 this.inputEl().on("focus", this.onFocus, this);
40621 this.inputEl().on("blur", this.onBlur, this);
40623 this.inputEl().relayEvent('keyup', this);
40625 if(this.indicator){
40626 this.indicator.addClass('invisible');
40629 this.originalValue = this.getValue();
40631 if(this.validationEvent == 'keyup'){
40632 this.validationTask = new Roo.util.DelayedTask(this.validate, this);
40633 this.inputEl().on('keyup', this.filterValidation, this);
40635 else if(this.validationEvent !== false){
40636 this.inputEl().on(this.validationEvent, this.validate, this, {buffer: this.validationDelay});
40639 if(this.selectOnFocus){
40640 this.on("focus", this.preFocus, this);
40643 if(this.maskRe || (this.vtype && this.disableKeyFilter !== true && (this.maskRe = Roo.form.VTypes[this.vtype+'Mask']))){
40644 this.inputEl().on("keypress", this.filterKeys, this);
40646 this.inputEl().relayEvent('keypress', this);
40649 var allowed = "0123456789";
40651 if(this.allowDecimals){
40652 allowed += this.decimalSeparator;
40655 if(this.allowNegative){
40659 if(this.thousandsDelimiter) {
40663 this.stripCharsRe = new RegExp('[^'+allowed+']', 'gi');
40665 var keyPress = function(e){
40667 var k = e.getKey();
40669 var c = e.getCharCode();
40672 (String.fromCharCode(c) == '.' || String.fromCharCode(c) == '-') &&
40673 allowed.indexOf(String.fromCharCode(c)) === -1
40679 if(!Roo.isIE && (e.isSpecialKey() || k == e.BACKSPACE || k == e.DELETE)){
40683 if(allowed.indexOf(String.fromCharCode(c)) === -1){
40688 this.inputEl().on("keypress", keyPress, this);
40692 onTriggerClick : function(e)
40699 this.loadNext = false;
40701 if(this.isExpanded()){
40706 this.hasFocus = true;
40708 if(this.triggerAction == 'all') {
40709 this.doQuery(this.allQuery, true);
40713 this.doQuery(this.getRawValue());
40716 getCurrency : function()
40718 var v = this.currencyEl().getValue();
40723 restrictHeight : function()
40725 this.list.alignTo(this.currencyEl(), this.listAlign);
40726 this.list.alignTo(this.currencyEl(), this.listAlign);
40729 onViewClick : function(view, doFocus, el, e)
40731 var index = this.view.getSelectedIndexes()[0];
40733 var r = this.store.getAt(index);
40736 this.onSelect(r, index);
40740 onSelect : function(record, index){
40742 if(this.fireEvent('beforeselect', this, record, index) !== false){
40744 this.setFromCurrencyData(index > -1 ? record.data : false);
40748 this.fireEvent('select', this, record, index);
40752 setFromCurrencyData : function(o)
40756 this.lastCurrency = o;
40758 if (this.currencyField) {
40759 currency = !o || typeof(o[this.currencyField]) == 'undefined' ? '' : o[this.currencyField];
40761 Roo.log('no currencyField value set for '+ (this.name ? this.name : this.id));
40764 this.lastSelectionText = currency;
40766 //setting default currency
40767 if(o[this.currencyField] * 1 == 0 && this.defaultCurrency) {
40768 this.setCurrency(this.defaultCurrency);
40772 this.setCurrency(currency);
40775 setFromData : function(o)
40779 c[this.currencyField] = !o || typeof(o[this.currencyName]) == 'undefined' ? '' : o[this.currencyName];
40781 this.setFromCurrencyData(c);
40786 value = !o || typeof(o[this.name]) == 'undefined' ? '' : o[this.name];
40788 Roo.log('no value set for '+ (this.name ? this.name : this.id));
40791 this.setValue(value);
40795 setCurrency : function(v)
40797 this.currencyValue = v;
40800 this.currencyEl().dom.value = (v === null || v === undefined ? '' : v);
40805 setValue : function(v)
40807 v = String(this.fixPrecision(v)).replace(".", this.decimalSeparator);
40813 this.hiddenEl().dom.value = (v === null || v === undefined ? '' : v);
40815 this.inputEl().dom.value = (v == '') ? '' :
40816 Roo.util.Format.number(v, this.decimalPrecision, this.thousandsDelimiter || '');
40818 if(!this.allowZero && v === '0') {
40819 this.hiddenEl().dom.value = '';
40820 this.inputEl().dom.value = '';
40827 getRawValue : function()
40829 var v = this.inputEl().getValue();
40834 getValue : function()
40836 return this.fixPrecision(this.parseValue(this.getRawValue()));
40839 parseValue : function(value)
40841 if(this.thousandsDelimiter) {
40843 r = new RegExp(",", "g");
40844 value = value.replace(r, "");
40847 value = parseFloat(String(value).replace(this.decimalSeparator, "."));
40848 return isNaN(value) ? '' : value;
40852 fixPrecision : function(value)
40854 if(this.thousandsDelimiter) {
40856 r = new RegExp(",", "g");
40857 value = value.replace(r, "");
40860 var nan = isNaN(value);
40862 if(!this.allowDecimals || this.decimalPrecision == -1 || nan || !value){
40863 return nan ? '' : value;
40865 return parseFloat(value).toFixed(this.decimalPrecision);
40868 decimalPrecisionFcn : function(v)
40870 return Math.floor(v);
40873 validateValue : function(value)
40875 if(!Roo.bootstrap.MoneyField.superclass.validateValue.call(this, value)){
40879 var num = this.parseValue(value);
40882 this.markInvalid(String.format(this.nanText, value));
40886 if(num < this.minValue){
40887 this.markInvalid(String.format(this.minText, this.minValue));
40891 if(num > this.maxValue){
40892 this.markInvalid(String.format(this.maxText, this.maxValue));
40899 validate : function()
40901 if(this.disabled || this.allowBlank){
40906 var currency = this.getCurrency();
40908 if(this.validateValue(this.getRawValue()) && currency.length){
40913 this.markInvalid();
40917 getName: function()
40922 beforeBlur : function()
40928 var v = this.parseValue(this.getRawValue());
40935 onBlur : function()
40939 if(!Roo.isOpera && this.focusClass){ // don't touch in Opera
40940 //this.el.removeClass(this.focusClass);
40943 this.hasFocus = false;
40945 if(this.validationEvent !== false && this.validateOnBlur && this.validationEvent != "blur"){
40949 var v = this.getValue();
40951 if(String(v) !== String(this.startValue)){
40952 this.fireEvent('change', this, v, this.startValue);
40955 this.fireEvent("blur", this);
40958 inputEl : function()
40960 return this.el.select('.roo-money-amount-input', true).first();
40963 currencyEl : function()
40965 return this.el.select('.roo-money-currency-input', true).first();
40968 hiddenEl : function()
40970 return this.el.select('input.hidden-number-input',true).first();