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.data.id });
31 Roo.extend(Roo.bootstrap.CardUploader, Roo.bootstrap.Input, {
38 imageCollection : false,
40 getAutoCreate : function()
48 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
49 tooltip : 'This field is required'
53 //cls : 'input-group-addon',
54 html : this.fieldLabel
66 cls : 'roo-card-uploader-button-container'
69 cls : 'card-columns roo-card-uploader-container'
76 var input = Roo.bootstrap.Input.prototype.getAutoCreate.call(this);
79 btn.cls += ' w-100 mb-2';
81 cls : 'roo-card-uploader-wrap',
86 cls : 'd-none roo-card-upload-selector',
99 getChildContainer : function() /// what children are added to.
105 initEvents : function()
108 Roo.bootstrap.Input.prototype.initEvents.call(this);
120 this.urlAPI = (window.createObjectURL && window) ||
121 (window.URL && URL.revokeObjectURL && URL) ||
122 (window.webkitURL && webkitURL);
127 this.selectorEl = this.el.select('.roo-card-upload-selector', true).first();
129 this.selectorEl.on('change', this.onFileSelected, this);
132 this.images.forEach(function(img) {
137 this.containerEl = this.el.select('.roo-card-uploader-container', true).first();
143 onClick : function(e)
147 this.selectorEl.dom.click();
151 onFileSelected : function(e)
155 if(typeof(this.selectorEl.dom.files) == 'undefined' || !this.selectorEl.dom.files.length){
159 Roo.each(this.selectorEl.dom.files, function(file){
169 addFile : function(file)
172 if(typeof(file) === 'string'){
173 throw "Add file by name?"; // should not happen
177 if(!file || !this.urlAPI){
187 var url = _this.urlAPI.createObjectURL( file);
190 id : Roo.bootstrap.CardUploader.ID--,
194 mimetype : file.type,
200 addCard : function (data)
202 // hidden input element?
203 // if the file is not an image...
204 //then we need to use something other that and header_image
210 xtype : 'CardFooter',
221 html : String.format("<small>{0}</small>", data.title),
222 cls : 'col-11 text-left',
228 this.downloadCard(data.id)
243 this.removeCard(data.id)
255 var cn = this.addxtype(
261 header : !data.mimetype.match(/image/) && !data.preview ? "Document": false,
262 header_image : data.mimetype.match(/image/) ? data.src : data.preview,
263 header_image_fit_square: true,
268 initEvents : function() {
269 Roo.bootstrap.Card.prototype.initEvents.call(this);
270 this.imgEl = this.el.select('.card-img-top').first();
272 this.imgEl.on('click', function() { t.previewCard( data.id); }, this);
273 this.imgEl.set({ 'pointer' : 'cursor' });
291 Roo.bootstrap.CardUploader.ID = -1;