var MediaModalController = BlockModalController.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, assets_path: 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 [ 'https://cabooseit.s3.amazonaws.com/assets/caboose/plupload_with_jquery.min.js', 'https://cdnjs.cloudflare.com/ajax/libs/plupload/2.1.3/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(); }, alphabetize_media: function() { var mylist = $('#the_modal #media > ul'); var listitems = mylist.children('li').get(); listitems.sort(function(a, b) { return $(a).text().toUpperCase().localeCompare($(b).text().toUpperCase()); }); if ( mylist.data('alph-order') == null || mylist.data('alph-order') == 'desc' ) { $.each(listitems, function(idx, itm) { mylist.append(itm); }); mylist.data('alph-order', 'asc'); } else { $.each(listitems, function(idx, itm) { mylist.prepend(itm); }); mylist.data('alph-order', 'desc'); } }, 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 == 'list' ? 'Thumbnail View' : 'List View' ).click(function(e) { e.preventDefault(); that.toggle_file_view(); $(this).html( that.file_view == 'thumbnail' ? 'List View' : 'Thumbnail View' ); })).append(' | ') .append($('').attr('href', '#').html('Alphabetize' ).click(function(e) { e.preventDefault(); that.alphabetize_media(); })) ) .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($('