var MediaModalController = DefaultBlockModalController.extend({ media_id: false, top_cat_id: false, cat_id: false, cat: false, categories: false, s3_upload_url: false, aws_access_key_id: false, policy: false, signature: false, refresh_unprocessed_images: false, selected_media: false, uploader: false, upload_extensions: "jpg,jpeg,png,gif,tif,tiff,pdf,doc,docx,odt,odp,ods,ppt,pptx,xls,xlsx,zip,tgz,csv,txt", file_view: 'thumbnail', assets_to_include: function() { return [ //'plupload/plupload.full.min.js', //'plupload/jquery.ui.plupload/jquery.ui.plupload.js', 'plupload/plupload_with_jquery.min.js', 'plupload/jquery.ui.plupload/css/jquery.ui.plupload.css' ]; }, refresh: function(callback) { var that = this; that.refresh_block(function() { that.refresh_categories(function() { that.refresh_media(function() { that.refresh_policy(function() { that.print(); }); }); }); }) }, refresh_categories: function(after) { var that = this; $.ajax({ url: '/admin/media-categories/tree', type: 'get', async: false, success: function(resp) { that.top_category = resp; if (!that.cat_id) that.cat_id = that.top_category.id; if (after) after(); } }); }, refresh_media: function(after) { var that = this; $.ajax({ url: '/admin/media/json', type: 'get', async: false, data: { media_category_id: that.cat_id }, success: function(resp) { that.media = resp; that.selected_media = []; if (after) after(); } }); }, refresh_policy: function(after) { var that = this; $.ajax({ url: '/admin/media/policy', type: 'get', success: function(resp) { that.policy = resp.policy; that.signature = resp.signature; that.s3_upload_url = resp.s3_upload_url; that.aws_access_key_id = resp.aws_access_key_id; that.top_media_category = resp.top_media_category; that.top_cat_id = resp.top_media_category.id; if (after) after(); } }); }, print_content: function() { var that = this; $('#modal_content').empty() .append($('
').attr('id', 'top_controls' )) .append($('
').attr('id', 'media' )); that.print_top_controls(); that.print_media(); that.autosize(); }, print_top_controls: function() { var that = this; //var select = $('').attr('id', 'categories')).append(' | ') .append($('').attr('href', '#').html('New Category' ).click(function(e) { e.preventDefault(); that.add_category(); })).append(' | ') .append($('').attr('href', '#').html('Upload to this Category' ).click(function(e) { e.preventDefault(); that.toggle_uploader(); })).append(' | ') .append($('').attr('href', '#').html(that.file_view == 'thumbnail' ? 'List View' : 'Thumbnail View' ).click(function(e) { e.preventDefault(); that.toggle_file_view(); })) ) .append($('
').attr('id', 'new_cat_message')) .append($('
').attr('id', 'uploader' ).append($('
').attr('id', 'the_uploader'))); $('#top_controls').replaceWith(div); that.print_categories(); }, print_categories: function() { var that = this; var select = $('').attr('type', 'text').attr('id', 'size_' + s).addClass('url').val(url)) .append($('