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){
25 Roo.bootstrap.CardUploader.superclass.constructor.call(this, config);
28 this.imageCollection = new Roo.util.MixedCollection(function(r) { return r.id });
33 Roo.extend(Roo.bootstrap.CardUploader, Roo.bootstrap.Button, {
40 imageCollection : false,
42 getAutoCreate : function()
44 var btn = Roo.bootstrap.Button.getAutoCreate.prototype.call(this);
47 cls : 'roo-card-uploader-wrap',
52 cls : 'd=none roo-card-upload-selector',
57 cls : 'card-columns roo-card-uploader-container'
67 getChildContainer : function() /// what children are added to.
69 return this.containerEl;
73 initEvents : function()
75 this.urlAPI = (window.createObjectURL && window) ||
76 (window.URL && URL.revokeObjectURL && URL) ||
77 (window.webkitURL && webkitURL);
82 this.selectorEl = this.el.select('.roo-card-upload-selector', true).first();
84 this.bodyEl.on('click', this.beforeSelectFile, this);
85 this.selectorEl.on('change', this.onFileSelected, this);
88 this.images.forEach(function(img) {
93 this.containerEl = this.el.select('.roo-card-uploader-container', true).first();
99 beforeSelectFile : function(e)
103 this.selectorEl.dom.click();
107 onFileSelected : function(e)
111 if(typeof(this.selectorEl.dom.files) == 'undefined' || !this.selectorEl.dom.files.length){
115 Roo.each(this.selectorEl.dom.files, function(file){
125 addFile : function(file)
128 if(typeof(file) === 'string'){
129 throw "Add file by name?"; // should not happen
133 if(!file || !this.urlAPI){
143 var url = _this.urlAPI.createObjectURL( file);
146 id : Roo.bootstrap.CardUploader.ID--,
150 mimetype : file.mimetype,
155 addCard : function (data)
157 // hidden input element?
158 // if the file is not an image...
159 //then we need to use something other that and header_image
163 var cn = this.addxtype(
169 header_image : data.src,
180 xtype : 'CardFooter',
211 Roo.bootstrap.CardUploader.ID = -1;