7 * @class Roo.bootstrap.CardUploader
8 * @extends Roo.bootstrap.Button
9 * Bootstrap Card Uploader class - it's a button which when you add files to it, adds cards below with preview and the name...
10 * @cfg {Number} errorTimeout default 3000
11 * @cfg {Boolean} name the field name for each image..
12 * @cfg {Array} images an array of ?? Img objects ??? when loading existing files..
15 * Create a new CardUploader
16 * @param {Object} config The config object
19 Roo.bootstrap.CardUploader = function(config){
23 Roo.bootstrap.CardUploader.superclass.constructor.call(this, config);
26 this.imageCollection = new Roo.util.MixedCollection(function(r) { return r.id });
31 Roo.extend(Roo.bootstrap.CardUploader, Roo.bootstrap.Button, {
38 imageCollection : false,
40 getAutoCreate : function()
42 var btn = Roo.bootstrap.Button.prototype.getAutoCreate.call(this);
45 cls : 'roo-card-uploader-wrap',
50 cls : 'd-none roo-card-upload-selector',
55 cls : 'card-columns roo-card-uploader-container'
65 getChildContainer : function() /// what children are added to.
67 return this.containerEl;
71 initEvents : function()
73 Roo.bootstrap.Button.prototype.initEvents.call(this);
74 this.urlAPI = (window.createObjectURL && window) ||
75 (window.URL && URL.revokeObjectURL && URL) ||
76 (window.webkitURL && webkitURL);
81 this.selectorEl = this.el.select('.roo-card-upload-selector', true).first();
83 this.selectorEl.on('change', this.onFileSelected, this);
86 this.images.forEach(function(img) {
91 this.containerEl = this.el.select('.roo-card-uploader-container', true).first();
101 this.selectorEl.dom.click();
105 onFileSelected : function(e)
109 if(typeof(this.selectorEl.dom.files) == 'undefined' || !this.selectorEl.dom.files.length){
113 Roo.each(this.selectorEl.dom.files, function(file){
123 addFile : function(file)
126 if(typeof(file) === 'string'){
127 throw "Add file by name?"; // should not happen
131 if(!file || !this.urlAPI){
141 var url = _this.urlAPI.createObjectURL( file);
144 id : Roo.bootstrap.CardUploader.ID--,
148 mimetype : file.mimetype,
153 addCard : function (data)
155 // hidden input element?
156 // if the file is not an image...
157 //then we need to use something other that and header_image
161 var cn = this.addxtype(
167 header_image : data.src,
178 xtype : 'CardFooter',
189 html : String.format("<small>{0}</small>", data.title),
190 cls : 'col-8 text-left',
233 Roo.bootstrap.CardUploader.ID = -1;