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.fileCollection = new Roo.util.MixedCollection(false,function(r) {
33 Roo.extend(Roo.bootstrap.CardUploader, Roo.bootstrap.Input, {
40 fileCollection : false,
43 getAutoCreate : function()
52 //cls : 'input-group-addon',
53 html : this.fieldLabel
61 cls : 'd-none form-control'
66 multiple : 'multiple',
68 cls : 'd-none roo-card-upload-selector'
72 cls : 'roo-card-uploader-button-container w-100 mb-2'
75 cls : 'card-columns roo-card-uploader-container'
87 getChildContainer : function() /// what children are added to.
89 return this.containerEl;
92 getButtonContainer : function() /// what children are added to.
94 return this.el.select(".roo-card-uploader-button-container").first();
97 initEvents : function()
100 Roo.bootstrap.Input.prototype.initEvents.call(this);
107 container_method : 'getButtonContainer' ,
108 html : 'Upload File / Images', // fix changable?
111 'click' : function(btn, e) {
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 t.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' });
282 // dont' really need ot update items.
283 // this.items.push(cn);
284 this.fileCollection.add(cn);
288 removeCard : function(id)
291 var card = this.fileCollection.get(id);
292 this.fileCollection.remove(card);
293 //this.items = this.items.filter(function(e) { return e != card });
294 // dont' really need ot update items.
295 card.el.dom.parentNode.removeChild(card.el.dom);
300 this.fileCollection.each(function(card) {
301 card.el.dom.parentNode.removeChild(card.el.dom);
303 this.fileCollection.clear();
304 this.inputEl().dom.value = '[]';
307 updateInput : function()
310 this.fileCollection.each(function(e) {
314 this.inputEl().dom.value = JSON.stringify(data);
321 Roo.bootstrap.CardUploader.ID = -1;