BoundImage = BoundControl.extend({ //el: false, //model: false, //attribute: false, //binder: false, width: 100, style: 'medium', authenticity_token: false, init: function(params) { for (var thing in params) this[thing] = params[thing]; this.el = this.el ? this.el : this.model.name.toLowerCase() + '_' + this.model.id + '_' + this.attribute.name; if (!this.attribute.update_url) this.attribute.update_url = this.model.update_url; var this2 = this; $('#'+this.el).wrap($('
') .attr('id', this.el + '_container') .addClass('mb_container') .css('position', 'relative') ); $('#'+this.el+'_container').empty(); $('#'+this.el+'_container').append($('') .attr('src', this.attribute.value) .css('width', this.width) .css('float', 'left') .css('margin-right', 10) ); $('#'+this.el+'_container').append($('
') .attr('action', this.attribute.update_url) .attr('method', 'post') .attr('enctype', 'multipart/form-data') .attr('encoding', 'multipart/form-data') .attr('target', this.el + '_iframe') .on('submit', function() { $('#'+this2.el+'_message').html("

Uploading...

"); $('#'+this2.el+'_iframe').on('load', function() { this2.post_upload(); }); }) .append($('').attr('type', 'hidden').attr('name', 'authenticity_token').val(this.binder.authenticity_token)) .append($('').attr('type', 'button').val('Update ' + this.attribute.nice_name).click(function() { $('#'+this2.el+'_container input[type="file"]').click(); })) .append($('') .attr('type', 'file') .attr('name', this.attribute.name) .css('display', 'none') .on('change', function() { $('#'+this2.el+'_container form').submit(); }) ) ); $('#'+this.el+'_container').append($('
') .attr('id', this.el + '_message') ); iframe = $('