X-Git-Url: http://git.roojs.org/?p=roojs1;a=blobdiff_plain;f=Roo%2FView.js;h=e6b134de4dd187ac558ee2257ab5e4d55fb7816d;hp=45464a1f8e3cc23be0895e25469cdba835bf877d;hb=0b69a11b1055a6d3a3fd0719bdd58b5a235de0e4;hpb=afef318661e0f111cea7fd5891f1b7f3b49114df diff --git a/Roo/View.js b/Roo/View.js index 45464a1f8e..e6b134de4d 100644 --- a/Roo/View.js +++ b/Roo/View.js @@ -49,6 +49,8 @@ */ Roo.View = function(config, depreciated_tpl, depreciated_config){ + this.parent = false; + if (typeof(depreciated_tpl) == 'undefined') { // new way.. - universal constructor. Roo.apply(this, config); @@ -72,10 +74,7 @@ Roo.View = function(config, depreciated_tpl, depreciated_config){ this.tpl.compile(); - - - /** @private */ this.addEvents({ /** @@ -162,7 +161,7 @@ Roo.View = function(config, depreciated_tpl, depreciated_config){ var fctr = this.wrapEl.appendChild(document.createElement("div")); - this.footer.dataSource = this.store + this.footer.dataSource = this.store; this.footer.container = fctr; this.footer = Roo.factory(this.footer, Roo); fctr.insertFirst(this.el); @@ -226,6 +225,11 @@ Roo.extend(Roo.View, Roo.util.Observable, { */ toggleSelect : false, + /** + * @cfg {Boolean} tickable - selecting + */ + tickable : false, + /** * Returns the element this view is bound to. * @return {Roo.Element} @@ -240,7 +244,7 @@ Roo.extend(Roo.View, Roo.util.Observable, { * Refreshes the view. - called by datachanged on the store. - do not call directly. */ refresh : function(){ - Roo.log('refresh'); + //Roo.log('refresh'); var t = this.tpl; // if we are using something like 'domtemplate', then @@ -274,10 +278,26 @@ Roo.extend(Roo.View, Roo.util.Observable, { for(var i = 0, len = records.length; i < len; i++){ var data = this.prepareData(records[i].data, i, records[i]); this.fireEvent("preparedata", this, data, i, records[i]); + + var d = Roo.apply({}, data); + + if(this.tickable){ + Roo.apply(d, {'roo-id' : Roo.id()}); + + var _this = this; + + Roo.each(this.parent.item, function(item){ + if(item[_this.parent.valueField] != data[_this.parent.valueField]){ + return; + } + Roo.apply(d, {'roo-data-checked' : 'checked'}); + }); + } + html[html.length] = Roo.util.Format.trim( this.dataName ? - t.applySubtemplate(this.dataName, data, this.store.meta) : - t.apply(data) + t.applySubtemplate(this.dataName, d, this.store.meta) : + t.apply(d) ); } @@ -303,7 +323,7 @@ Roo.extend(Roo.View, Roo.util.Observable, { }, onUpdate : function(ds, record){ - Roo.log('on update'); + // Roo.log('on update'); this.clearSelections(); var index = this.store.indexOf(record); var n = this.nodes[index]; @@ -317,7 +337,7 @@ Roo.extend(Roo.View, Roo.util.Observable, { // --------- FIXME onAdd : function(ds, records, index) { - Roo.log(['on Add', ds, records, index] ); + //Roo.log(['on Add', ds, records, index] ); this.clearSelections(); if(this.nodes.length == 0){ this.refresh(); @@ -337,7 +357,7 @@ Roo.extend(Roo.View, Roo.util.Observable, { }, onRemove : function(ds, record, index){ - Roo.log('onRemove'); + // Roo.log('onRemove'); this.clearSelections(); var el = this.dataName ? this.el.child('.roo-tpl-' + this.dataName) : @@ -401,7 +421,7 @@ Roo.extend(Roo.View, Roo.util.Observable, { */ onBeforeLoad : function(store,opts) { - Roo.log('onBeforeLoad'); + //Roo.log('onBeforeLoad'); if (!opts.add) { this.el.update(""); } @@ -438,9 +458,7 @@ Roo.extend(Roo.View, Roo.util.Observable, { /** @ignore */ onClick : function(e){ - Roo.log('view click'); var item = this.findItemFromChild(e.getTarget()); - Roo.log(item); if(item){ var index = this.indexOf(item); if(this.onItemClick(item, index, e) !== false){ @@ -474,7 +492,7 @@ Roo.extend(Roo.View, Roo.util.Observable, { } if (this.toggleSelect) { var m = this.isSelected(item) ? 'unselect' : 'select'; - Roo.log(m); + //Roo.log(m); var _t = this; _t[m](item, true, false); return true; @@ -486,7 +504,11 @@ Roo.extend(Roo.View, Roo.util.Observable, { this.select(item, this.multiSelect && e.ctrlKey); this.lastSelection = item; } - e.preventDefault(); + + if(!this.tickable){ + e.preventDefault(); + } + } return true; }, @@ -571,6 +593,7 @@ Roo.extend(Roo.View, Roo.util.Observable, { if(!keepExisting){ this.clearSelections(true); } + if(this.fireEvent("beforeselect", this, node, this.selections) !== false){ Roo.fly(node).addClass(this.selectedClass); this.selections.push(node); @@ -597,7 +620,7 @@ Roo.extend(Roo.View, Roo.util.Observable, { } var node = this.getNode(nodeInfo); if(!node || !this.isSelected(node)){ - Roo.log("not selected"); + //Roo.log("not selected"); return; // not selected. } // fireevent???