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 w-100 mb-2'
69 cls : 'card-columns roo-card-uploader-container'
81 getChildContainer : function() /// what children are added to.
83 return this.containerEl;
86 getButtonContainer : function() /// what children are added to.
91 initEvents : function()
94 Roo.bootstrap.Input.prototype.initEvents.call(this);
100 container_method : 'getButtonContainer' ,
101 title : 'Upload File / Images', // fix changable?
104 'click' : function(e) {
113 this.urlAPI = (window.createObjectURL && window) ||
114 (window.URL && URL.revokeObjectURL && URL) ||
115 (window.webkitURL && webkitURL);
120 this.selectorEl = this.el.select('.roo-card-upload-selector', true).first();
122 this.selectorEl.on('change', this.onFileSelected, this);
125 this.images.forEach(function(img) {
130 this.containerEl = this.el.select('.roo-card-uploader-container', true).first();
136 onClick : function(e)
140 this.selectorEl.dom.click();
144 onFileSelected : function(e)
148 if(typeof(this.selectorEl.dom.files) == 'undefined' || !this.selectorEl.dom.files.length){
152 Roo.each(this.selectorEl.dom.files, function(file){
162 addFile : function(file)
165 if(typeof(file) === 'string'){
166 throw "Add file by name?"; // should not happen
170 if(!file || !this.urlAPI){
180 var url = _this.urlAPI.createObjectURL( file);
183 id : Roo.bootstrap.CardUploader.ID--,
187 mimetype : file.type,
193 addCard : function (data)
195 // hidden input element?
196 // if the file is not an image...
197 //then we need to use something other that and header_image
203 xtype : 'CardFooter',
214 html : String.format("<small>{0}</small>", data.title),
215 cls : 'col-11 text-left',
221 this.downloadCard(data.id)
236 this.removeCard(data.id)
248 var cn = this.addxtype(
254 header : !data.mimetype.match(/image/) && !data.preview ? "Document": false,
255 header_image : data.mimetype.match(/image/) ? data.src : data.preview,
256 header_image_fit_square: true,
261 initEvents : function() {
262 Roo.bootstrap.Card.prototype.initEvents.call(this);
263 this.imgEl = this.el.select('.card-img-top').first();
265 this.imgEl.on('click', function() { t.previewCard( data.id); }, this);
266 this.imgEl.set({ 'pointer' : 'cursor' });
284 Roo.bootstrap.CardUploader.ID = -1;