Roo.bootstrap.CardUploader.superclass.constructor.call(this, config);
- this.imageCollection = new Roo.util.MixedCollection(function(r) { return r.data.id });
+ this.fileCollection = new Roo.util.MixedCollection(false,function(r) {
+ return r.data.id
+ });
};
images : false,
- imageCollection : false,
+ fileCollection : false,
+ allowBlank : true,
getAutoCreate : function()
{
var cfg = {
cls :'form-group' ,
cn : [
- {
- tag : 'i',
- cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
- tooltip : 'This field is required'
- },
+
{
tag: 'label',
//cls : 'input-group-addon',
{
tag: 'input',
- id : id,
type : 'hidden',
value : this.value,
- cls : 'd-none'
+ cls : 'd-none form-control'
+ },
+
+ {
+ tag: 'input',
+ multiple : 'multiple',
+ type : 'file',
+ cls : 'd-none roo-card-upload-selector'
},
+
{
- cls : 'roo-card-uploader-button-container'
+ cls : 'roo-card-uploader-button-container w-100 mb-2'
},
{
cls : 'card-columns roo-card-uploader-container'
};
- var input = Roo.bootstrap.Input.prototype.getAutoCreate.call(this);
-
-
- btn.cls += ' w-100 mb-2';
- var cfg = {
- cls : 'roo-card-uploader-wrap',
- cn : [
- btn,
- {
- tag : 'input',
- cls : 'd-none roo-card-upload-selector',
- type : 'file',
- multiple : 'multiple'
- },
-
- ]
-
- }
-
+
return cfg;
},
getChildContainer : function() /// what children are added to.
{
- return this.el;
+ return this.containerEl;
+ },
+
+ getButtonContainer : function() /// what children are added to.
+ {
+ return this.el.select(".roo-card-uploader-button-container").first();
},
-
initEvents : function()
{
Roo.bootstrap.Input.prototype.initEvents.call(this);
+ var t = this;
this.addxtype({
xns: Roo.bootstrap,
+
xtype : 'Button',
-
-
+ container_method : 'getButtonContainer' ,
+ html : 'Upload File / Images', // fix changable?
+ cls : 'w-100 ',
+ listeners : {
+ 'click' : function(btn, e) {
+ t.onClick(e);
+ }
+ }
})
this.selectorEl = this.el.select('.roo-card-upload-selector', true).first();
- this.selectorEl.on('change', this.onFileSelected, this);
+ this.selectorEl.on('change', this.onFileSelected, this);
if (this.images) {
var t = this;
this.images.forEach(function(img) {
fa : 'times',
listeners : {
click : function() {
- this.removeCard(data.id)
+ t.removeCard(data.id)
}
}
}
}
);
- this.items.push(cn);
+ // dont' really need ot update items.
+ // this.items.push(cn);
+ this.fileCollection.add(cn);
+ },
+ removeCard : function(id)
+ {
+ var card = this.fileCollection.get(id);
+ this.fileCollection.remove(card);
+ //this.items = this.items.filter(function(e) { return e != card });
+ // dont' really need ot update items.
+ card.el.dom.parentNode.removeChild(card.el.dom);
+
+ },
+ reset: function()
+ {
+ this.fileCollection.each(function(card) {
+ card.el.dom.parentNode.removeChild(card.el.dom);
+ });
+ this.inputEl().dom.value = '[]';
+ },
+
+ updateInput : function()
+ {
+ var data = [];
+ this.fileCollection.each(function(e) {
+ data.push(e.data);
+ });
+ this.inputEl().dom.value = JSON.stringify(data);
}