caboose-cms 0.8.43 → 0.8.44

Sign up to get free protection for your applications and to get access to all the features.
Files changed (30) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/caboose/admin_page_edit_content.js +83 -70
  3. data/app/assets/javascripts/caboose/card.js +2432 -0
  4. data/app/assets/javascripts/caboose/clipboard.js +7 -0
  5. data/app/assets/javascripts/caboose/modal_controllers/modal_block_controller.js +174 -252
  6. data/app/assets/javascripts/caboose/modal_controllers/modal_controller.js +160 -12
  7. data/app/assets/javascripts/caboose/modal_controllers/modal_media_controller.js +419 -0
  8. data/app/assets/javascripts/caboose/modal_integration.js +21 -1
  9. data/app/assets/javascripts/caboose/model/bound_checkbox.js +13 -6
  10. data/app/assets/javascripts/caboose/model/bound_select.js +16 -7
  11. data/app/assets/javascripts/caboose/model/bound_text.js +15 -2
  12. data/app/assets/stylesheets/caboose/admin_block_edit_image.css.scss +16 -1
  13. data/app/assets/stylesheets/caboose/admin_new_block.css +9 -0
  14. data/app/assets/stylesheets/caboose/application.css +2 -1
  15. data/app/assets/stylesheets/caboose/modal_inline.css +8 -15
  16. data/app/assets/stylesheets/caboose/my_account.scss +178 -0
  17. data/app/controllers/caboose/block_types_controller.rb +20 -0
  18. data/app/controllers/caboose/blocks_controller.rb +70 -8
  19. data/app/controllers/caboose/media_controller.rb +39 -3
  20. data/app/models/caboose/block.rb +17 -1
  21. data/app/models/caboose/media.rb +9 -8
  22. data/app/models/caboose/schema.rb +1 -0
  23. data/app/views/caboose/block_types/admin_edit.html.erb +5 -2
  24. data/app/views/caboose/block_types/admin_index.html.erb +2 -1
  25. data/app/views/caboose/my_account/index.html.erb +124 -63
  26. data/app/views/caboose/my_account/index_old.html.erb +191 -0
  27. data/app/views/caboose/pages/admin_edit_content.html.erb +16 -1
  28. data/lib/caboose/version.rb +1 -1
  29. metadata +8 -3
  30. data/app/assets/stylesheets/caboose/my_account.css +0 -2
@@ -6,12 +6,20 @@ var ModalController = Class.extend({
6
6
  block: false,
7
7
  modal_element: false,
8
8
  authenticity_token: false,
9
+ parent_controller: false,
10
+ new_block_on_init: false,
11
+ assets_path: false,
9
12
 
10
- init: function(params) {
11
- var that = this;
13
+ init: function(params)
14
+ {
15
+ var that = this;
12
16
  for (var i in params)
13
- that[i] = params[i];
14
- that.print();
17
+ that[i] = params[i];
18
+ that.include_assets();
19
+ if (that.new_block_on_init == true)
20
+ that.add_block();
21
+ else
22
+ that.print();
15
23
  },
16
24
 
17
25
  refresh: function(callback)
@@ -37,9 +45,9 @@ var ModalController = Class.extend({
37
45
  $.colorbox({
38
46
  html: el,
39
47
  initialWidth: width,
40
- initialHeight: height,
48
+ //initialHeight: height,
41
49
  innerWidth: width,
42
- innerHeight: height,
50
+ //innerHeight: height,
43
51
  scrolling: false,
44
52
  closeButton: false,
45
53
  opacity: 0.50,
@@ -52,18 +60,158 @@ var ModalController = Class.extend({
52
60
  });
53
61
  },
54
62
 
55
- autosize: function(msg, msg_container)
56
- {
57
- var that = this;
63
+ last_size: 0,
64
+ autosize: function(msg, msg_container, flag)
65
+ {
66
+ var that = this;
67
+ if (!flag)
68
+ that.last_size = 0;
58
69
  if (!that.modal_element) return;
59
- if (msg) $('#' + (msg_container ? msg_container : 'modal_message')).html(msg);
70
+ if (msg) $('#' + (msg_container ? msg_container : 'modal_message')).html(msg);
60
71
  var h = $(that.modal_element).outerHeight(true) + 20;
61
- $.colorbox.resize({ innerHeight: '' + h + 'px' });
72
+ if (h > 0 && h > that.last_size)
73
+ $.colorbox.resize({ innerHeight: '' + h + 'px' });
74
+ that.last_size = h;
75
+
76
+ if (!flag || flag < 2)
77
+ setTimeout(function() { that.autosize(false, false, flag ? flag + 1 : 1); }, 200);
62
78
  },
63
79
 
64
80
  close: function()
65
81
  {
66
82
  $.colorbox.close();
67
- }
83
+ },
84
+
85
+ block_with_id: function(block_id, b)
86
+ {
87
+ var that = this;
88
+ if (!b) b = that.block;
89
+ if (b.id == block_id) return b;
90
+
91
+ var the_block = false;
92
+ $.each(b.children, function(i, b2) {
93
+ the_block = that.block_with_id(block_id, b2);
94
+ if (the_block)
95
+ return false;
96
+ });
97
+ return the_block;
98
+ },
99
+
100
+ base_url: function(b)
101
+ {
102
+ var that = this;
103
+ if (!b) b = that.block;
104
+ return '/admin/' + (b.page_id ? 'pages/' + b.page_id : 'posts/' + b.post_id) + '/blocks';
105
+ },
68
106
 
107
+ block_url: function(b)
108
+ {
109
+ var that = this;
110
+ if (!b) b = that.block;
111
+ return this.base_url(b) + '/' + b.id;
112
+ },
113
+
114
+ add_block: function(block_type_id)
115
+ {
116
+ var that = this;
117
+
118
+ that.include_assets([
119
+ 'caboose/icomoon_fonts.css',
120
+ 'caboose/admin_new_block.css'
121
+ ]);
122
+
123
+ if (!that.block_type_id)
124
+ {
125
+ that.new_block_types = false;
126
+ $.ajax({
127
+ url: '/admin/block-types/new-options',
128
+ type: 'get',
129
+ success: function(resp) { that.new_block_types = resp; },
130
+ async: false
131
+ });
132
+
133
+ var icons = $('<div/>').addClass('icons');
134
+ $.each(that.new_block_types, function(i, h) {
135
+ if (h.block_types && h.block_types.length > 0)
136
+ {
137
+ var cat = h.block_type_category;
138
+ icons.append($('<h2/>').click(function(e) { $('#cat_' + cat.id + '_container').slideToggle(); }).append(cat.name));
139
+ var cat_container = $('<div/>').attr('id', 'cat_' + cat.id + '_container');
140
+ $.each(h.block_types, function(j, bt) {
141
+ cat_container.append($('<a/>').attr('href', '#')
142
+ .data('block_type_id', bt.id)
143
+ .click(function(e) { e.preventDefault(); that.add_block($(this).data('block_type_id')); })
144
+ .append($('<span/>').addClass('icon icon-' + bt.icon))
145
+ .append($('<span/>').addClass('name').append(bt.description))
146
+ );
147
+ });
148
+ icons.append(cat_container);
149
+ }
150
+ });
151
+
152
+ var div = $('<div/>').append($('<form/>').attr('id', 'new_block_form')
153
+ .submit(function(e) { e.preventDefault(); return false; })
154
+ .append(icons)
155
+ );
156
+ that.modal(div, 800);
157
+ return;
158
+ }
159
+
160
+ that.autosize("<p class='loading'>Adding block...</p>");
161
+ var h = {
162
+ authenticity_token: that.authenticity_token,
163
+ block_type_id: block_type_id
164
+ };
165
+ if (that.before_id ) h['before_id'] = that.before_id;
166
+ if (that.after_id ) h['after_id' ] = that.after_id;
167
+
168
+ $.ajax({
169
+ url: that.block_url(),
170
+ type: 'post',
171
+ data: h,
172
+ success: function(resp) {
173
+ if (resp.error) that.autosize("<p class='note error'>" + resp.error + "</p>");
174
+ if (resp.success) that.parent_controller.edit_block(resp.new_id);
175
+ }
176
+ });
177
+ },
178
+
179
+ /*****************************************************************************
180
+ Asset management
181
+ *****************************************************************************/
182
+
183
+ // To be overridden in each controller
184
+ assets_to_include: function() { return []; },
185
+
186
+ // Called at the beginning of init to include modal assets,
187
+ // and can be called at anytime with more assets
188
+ include_assets: function(arr)
189
+ {
190
+ var that = this;
191
+ if (!arr) arr = that.assets_to_include();
192
+ if (!arr) return;
193
+
194
+ if (!that.parent_controller.included_assets || that.parent_controller.included_assets == undefined)
195
+ that.parent_controller.included_assets = [];
196
+ if (typeof arr == 'string') arr = [arr];
197
+ $.each(arr, function(i, url) {
198
+ if (that.parent_controller.included_assets.indexOf(url) > -1) return;
199
+ if (url.match(/\.js/))
200
+ {
201
+ var el = document.createElement('script');
202
+ el.setAttribute('type', 'text/javascript');
203
+ el.setAttribute('src', that.assets_path + url);
204
+ document.getElementsByTagName('head')[0].appendChild(el)
205
+ }
206
+ else if (url.match(/\.css/))
207
+ {
208
+ var el = document.createElement('link');
209
+ el.setAttribute('rel', 'stylesheet');
210
+ el.setAttribute('type', 'text/css');
211
+ el.setAttribute('href', that.assets_path + url);
212
+ document.getElementsByTagName('head')[0].appendChild(el)
213
+ }
214
+ that.parent_controller.included_assets.push(url);
215
+ });
216
+ }
69
217
  });
@@ -0,0 +1,419 @@
1
+
2
+ var ModalMediaController = ModalController.extend({
3
+
4
+ media_id: false,
5
+ top_cat_id: false,
6
+ cat_id: false,
7
+ cat: false,
8
+ categories: false,
9
+ s3_upload_url: false,
10
+ aws_access_key_id: false,
11
+ policy: false,
12
+ signature: false,
13
+ refresh_unprocessed_images: false,
14
+ selected_media: false,
15
+ uploader: false,
16
+ upload_extensions: "jpg,jpeg,png,gif,tif,tiff,pdf,doc,docx,odt,odp,ods,ppt,pptx,xls,xlsx,zip,tgz,csv,txt",
17
+ file_view: 'thumbnail',
18
+
19
+ assets_to_include: function()
20
+ {
21
+ return [
22
+ 'plupload/plupload.full.min.js',
23
+ 'plupload/jquery.ui.plupload/jquery.ui.plupload.js',
24
+ 'plupload/jquery.ui.plupload/css/jquery.ui.plupload.css'
25
+ ];
26
+ },
27
+
28
+ refresh_categories: function(after)
29
+ {
30
+ var that = this;
31
+ $.ajax({
32
+ url: '/admin/media-categories/tree',
33
+ type: 'get',
34
+ async: false,
35
+ success: function(resp) {
36
+ that.top_category = resp;
37
+ if (!that.cat_id) that.cat_id = that.top_category.id;
38
+ if (after) after();
39
+ }
40
+ });
41
+ },
42
+
43
+ refresh_media: function(after)
44
+ {
45
+ var that = this;
46
+ $.ajax({
47
+ url: '/admin/media/json',
48
+ type: 'get',
49
+ async: false,
50
+ data: { media_category_id: that.cat_id },
51
+ success: function(resp) {
52
+ that.media = resp;
53
+ that.selected_media = [];
54
+ if (after) after();
55
+ }
56
+ });
57
+ },
58
+
59
+ refresh_policy: function(after)
60
+ {
61
+ var that = this;
62
+ $.ajax({
63
+ url: '/admin/media/policy',
64
+ type: 'get',
65
+ success: function(resp) {
66
+ that.policy = resp.policy;
67
+ that.signature = resp.signature;
68
+ that.s3_upload_url = resp.s3_upload_url;
69
+ that.aws_access_key_id = resp.aws_access_key_id;
70
+ that.top_media_category = resp.top_media_category;
71
+ that.top_cat_id = resp.top_media_category.id;
72
+ if (after) after();
73
+ }
74
+ });
75
+ },
76
+
77
+ print: function()
78
+ {
79
+ var that = this;
80
+ if (!that.block)
81
+ {
82
+ var div = $('<div/>')
83
+ .append($('<div/>').attr('id', 'top_controls'))
84
+ .append($('<div/>').attr('id', 'media' ))
85
+ .append($('<div/>').attr('id', 'controls')
86
+ .append($('<p/>').css('clear', 'both')
87
+ .append($('<input/>').attr('type', 'button').val('Close' ).click(function(e) { that.parent_controller.render_blocks(); that.close(); }))
88
+ )
89
+ );
90
+ that.modal(div, 800);
91
+ that.refresh(function() {
92
+ that.refresh_categories(function() {
93
+ that.refresh_media(function() {
94
+ that.refresh_policy(function() {
95
+ that.print();
96
+ });
97
+ });
98
+ });
99
+ })
100
+ return;
101
+ }
102
+ that.print_top_controls();
103
+ that.print_media();
104
+ that.autosize();
105
+ },
106
+
107
+ print_top_controls: function()
108
+ {
109
+ var that = this;
110
+
111
+ var select = $('<select/>').attr('id', 'categories').change(function(e) {
112
+ that.select_category($(this).val());
113
+ });
114
+ that.print_categories_helper(that.top_category, select, '');
115
+
116
+ var div = $('<div/>').attr('id', 'top_controls')
117
+ .append($('<p/>')
118
+ .append(select).append(' | ')
119
+ .append($('<a/>').attr('href', '#').html('New Category' ).click(function(e) { e.preventDefault(); that.add_category(); })).append(' | ')
120
+ .append($('<a/>').attr('href', '#').html('Upload to this Category' ).click(function(e) { e.preventDefault(); that.toggle_uploader(); })).append(' | ')
121
+ .append($('<a/>').attr('href', '#').html(that.file_view == 'thumbnail' ? 'List View' : 'Thumbnail View' ).click(function(e) { e.preventDefault(); that.toggle_file_view(); }))
122
+ )
123
+ .append($('<div/>').attr('id', 'new_cat_message'))
124
+ .append($('<div/>').attr('id', 'uploader' ).append($('<div/>').attr('id', 'the_uploader')));
125
+
126
+ $('#top_controls').replaceWith(div);
127
+ },
128
+
129
+ print_categories_helper: function(cat, select, prefix)
130
+ {
131
+ var that = this;
132
+ var opt = $('<option/>')
133
+ .data('media_category_id', cat.id)
134
+ .val(cat.id)
135
+ .append(prefix + cat.name + ' (' + cat.media_count + ')');
136
+ if (cat.id == that.cat_id)
137
+ opt.attr('selected', 'true');
138
+ select.append(opt);
139
+ if (cat.children.length > 0)
140
+ {
141
+ $.each(cat.children, function(i, cat2) {
142
+ that.print_categories_helper(cat2, select, prefix + ' - ');
143
+ });
144
+ }
145
+ },
146
+
147
+ print_media: function()
148
+ {
149
+ var that = this;
150
+ var ul = $('<ul/>').addClass(that.file_view + '_view');
151
+ var processing = false;
152
+ var d = new Date();
153
+ d = d.getTime();
154
+
155
+ if (that.media.length > 0)
156
+ {
157
+ $.each(that.media, function(i, m) {
158
+ if (m.media_type == 'image' && m.processed == false)
159
+ processing = true
160
+ var li = $('<li/>')
161
+ .attr('id', 'media' + m.id)
162
+ .addClass('media')
163
+ .data('media_id', m.id)
164
+ .click(function(e) { that.print_media_detail($(this).data('media_id')); })
165
+ .append($('<span/>').addClass('name').html(m.original_name));
166
+ if (m.image_urls)
167
+ li.append($('<img/>').attr('src', m.image_urls.tiny_url + '?' + d));
168
+ //if (that.selected_media.indexOf(m.id) > -1)
169
+ // li.addClass('selected ui-selected');
170
+ if (m.id == that.media_id)
171
+ li.addClass('selected ui-selected');
172
+ ul.append(li);
173
+ });
174
+ }
175
+ else
176
+ ul = $('<p/>').html("This category is empty.");
177
+ $('#media').empty().append(ul);
178
+ if (that.refresh_unprocessed_images == true && processing)
179
+ setTimeout(function() { that.refresh(); }, 2000);
180
+ that.autosize();
181
+
182
+ $.each(that.media, function(i, m) {
183
+ $('li.media').draggable({
184
+ multiple: true,
185
+ revert: 'invalid',
186
+ start: function() { $(this).data("origPosition", $(this).position()); }
187
+ });
188
+ });
189
+ },
190
+
191
+ print_media_detail: function(media_id)
192
+ {
193
+ var that = this;
194
+ var m = that.media_with_id(media_id);
195
+
196
+ var image_urls = $('<div/>').attr('id', 'image_urls').css('margin-bottom', '20px');
197
+ for (var size in m.image_urls)
198
+ {
199
+ var s = size.replace('_url', '');
200
+ s = s[0].toUpperCase() + s.slice(1);
201
+ var url = m.image_urls[size];
202
+ image_urls.append($('<div/>')
203
+ .append($('<span/>').addClass('size').append(s))
204
+ .append($('<input/>').attr('type', 'text').attr('id', 'size_' + s).addClass('url').val(url))
205
+ .append($('<button/>').addClass('clippy').data('clipboard-target', '#size_' + s).append('Copy'))
206
+ );
207
+ }
208
+
209
+ $('#top_controls').empty();
210
+ $('#media').empty()
211
+ .append($('<img/>').attr('id', 'detail_image').attr('src', m.image_urls.thumb_url))
212
+ .append($('<p/>').append($('<div/>').attr('id', 'media_' + media_id + '_media_category_id' )))
213
+ .append($('<p/>').append($('<div/>').attr('id', 'media_' + media_id + '_name' )))
214
+ .append($('<p/>').append($('<div/>').attr('id', 'media_' + media_id + '_description' )))
215
+ .append($('<h2/>').append('Image URLs'))
216
+ .append(image_urls);
217
+ $('#controls').empty()
218
+ .append($('<p/>').css('clear', 'both')
219
+ .append($('<input/>').attr('type', 'button').val('< Back' ).click(function(e) { that.print_top_controls(); that.print_media(); }))
220
+ .append($('<input/>').attr('type', 'button').val('Select this Image' ).click(function(e) { that.select_media(media_id) }))
221
+ .append($('<input/>').attr('type', 'button').val('Close' ).click(function(e) { that.parent_controller.render_blocks(); that.close(); }))
222
+ );
223
+
224
+ var m = new ModelBinder({
225
+ name: 'Media',
226
+ id: m.id,
227
+ update_url: '/admin/media/' + m.id,
228
+ authenticity_token: that.authenticity_token,
229
+ attributes: [
230
+ { name: 'media_category_id' , nice_name: 'Category' , type: 'select' , value: m.media_category_id , fixed_placeholder: true, width: 400, after_update: function() { m.media_category_id = this.value; }, on_load: function() { that.autosize(); }, options_url: '/admin/media-categories/options' },
231
+ { name: 'name' , nice_name: 'Name' , type: 'text' , value: m.name , fixed_placeholder: true, width: 400, after_update: function() { m.name = this.value; }, on_load: function() { that.autosize(); }},
232
+ { name: 'description' , nice_name: 'Description' , type: 'text' , value: m.description , fixed_placeholder: true, width: 400, after_update: function() { m.description = this.value; }, on_load: function() { that.autosize(); }},
233
+ ]
234
+ });
235
+ $('#media_' + media_id + '_media_category_id' + '_container').css('width', '400px');
236
+ $('#media_' + media_id + '_name' + '_container').css('width', '400px');
237
+ $('#media_' + media_id + '_description' + '_container').css('width', '400px');
238
+
239
+ $('#image_urls span.size' ).css('width', '70px').css('display', 'inline-block');
240
+ $('#image_urls input.url' ).css('width', '270px').css('border', '#ccc 1px solid');
241
+ $('#image_urls button').css('width', '60px');
242
+
243
+ c = new Clipboard('.clippy');
244
+ c.on('success', function(e) {
245
+ console.info('Action:', e.action);
246
+ console.info('Text:', e.text);
247
+ console.info('Trigger:', e.trigger);
248
+ e.clearSelection();
249
+ });
250
+ c.on('error', function(e) {
251
+ console.error('Action:', e.action);
252
+ console.error('Trigger:', e.trigger);
253
+ });
254
+
255
+ that.autosize();
256
+ },
257
+
258
+ //============================================================================
259
+
260
+ toggle_uploader: function()
261
+ {
262
+ var that = this;
263
+ if (that.uploader)
264
+ {
265
+ $("#the_uploader").slideUp(400, function() {
266
+ $("#the_uploader").plupload('destroy');
267
+ that.uploader = false;
268
+ that.autosize();
269
+ });
270
+ }
271
+ else
272
+ {
273
+ $("#the_uploader").hide();
274
+ that.uploader = $("#the_uploader").plupload({
275
+ runtimes: 'html5,flash,silverlight',
276
+ url: that.s3_upload_url,
277
+ multipart: true,
278
+ multipart_params: {
279
+ key: that.cat_id + '_${filename}', // use filename as a key
280
+ Filename: that.cat_id + '_${filename}', // adding this to keep consistency across the runtimes
281
+ acl: 'public-read',
282
+ //'Content-Type': 'image/jpeg',
283
+ AWSAccessKeyId: that.aws_access_key_id,
284
+ policy: that.policy,
285
+ signature: that.signature
286
+ },
287
+ file_data_name: 'file', // optional, but better be specified directly
288
+ filters: {
289
+ max_file_size: '100mb', // Maximum file size
290
+ mime_types: [{ title: "Upload files", extensions: that.upload_extensions }] // Specify what files to browse for
291
+ },
292
+ flash_swf_url: '../../js/Moxie.swf', // Flash settings
293
+ silverlight_xap_url: '../../js/Moxie.xap', // Silverlight settings
294
+ init: {
295
+ BeforeUpload: function(up, file) {
296
+ $.ajax({
297
+ url: '/admin/media/pre-upload',
298
+ type: 'post',
299
+ data: {
300
+ media_category_id: that.cat_id,
301
+ name: file.name
302
+ },
303
+ success: function(resp) {},
304
+ async: false
305
+ });
306
+ that.refresh_media(function() { that.refresh_categories(function() { that.print(); }); });
307
+ },
308
+ FileUploaded: function(ip, file)
309
+ {
310
+ that.refresh_media(function() { that.refresh_categories(function() { that.print(); }); });
311
+ },
312
+ UploadComplete: function(up, files) {
313
+ that.refresh_media(function() { that.refresh_categories(function() { that.print(); }); });
314
+ if (that.uploader)
315
+ {
316
+ $("#the_uploader").slideUp(400, function() {
317
+ $("#the_uploader").plupload('destroy');
318
+ that.uploader = false;
319
+ });
320
+ }
321
+ }
322
+ }
323
+ });
324
+ $("#the_uploader").slideDown(400, function() { that.autosize(); });
325
+ }
326
+ },
327
+
328
+ //============================================================================
329
+
330
+ select_media: function(media_id)
331
+ {
332
+ var that = this;
333
+ $.ajax({
334
+ url: that.block_url(),
335
+ type: 'put',
336
+ data: { media_id: media_id },
337
+ success: function(resp) {
338
+ that.parent_controller.render_blocks();
339
+ that.parent_controller.edit_block(that.block.parent_id);
340
+ }
341
+ });
342
+ },
343
+
344
+ //============================================================================
345
+
346
+ select_category: function(cat_id)
347
+ {
348
+ var that = this;
349
+ that.cat_id = cat_id;
350
+ that.print_top_controls();
351
+ that.refresh_media(function() { that.print_media(); });
352
+ },
353
+
354
+ add_category: function(name)
355
+ {
356
+ var that = this;
357
+ if (!name)
358
+ {
359
+ if (!$('#new_cat_message').is(':empty'))
360
+ {
361
+ $('#new_cat_message').empty();
362
+ return;
363
+ }
364
+ var div = $('<p/>').addClass('note warning')
365
+ .append('Name: ')
366
+ .append($('<input/>').attr('type', 'text').attr('id', 'new_cat_name')).append(" ")
367
+ .append($('<input/>').attr('type', 'button').val('Add').click(function() { that.add_category($('#new_cat_name').val()); })).append(" ")
368
+ .append($('<input/>').attr('type', 'button').val('Cancel').click(function() { $('#new_cat_message').empty(); }));
369
+ $('#new_cat_message').empty().append(div);
370
+ return;
371
+ }
372
+ $('#new_cat_message').empty().html("<p class='loading'>Adding category...</p>");
373
+ $.ajax({
374
+ url: '/admin/media-categories',
375
+ type: 'post',
376
+ data: {
377
+ parent_id: that.cat_id,
378
+ name: name
379
+ },
380
+ success: function(resp) {
381
+ if (resp.error) $('#new_cat_message').empty().html("<p class='note error'>" + resp.error + "</p>");
382
+ if (resp.refresh) {
383
+ that.cat_id = resp.new_id;
384
+ that.refresh(function() {
385
+ that.refresh_categories(function() {
386
+ that.refresh_media(function() {
387
+ that.refresh_policy(function() {
388
+ that.print();
389
+ });
390
+ });
391
+ });
392
+ });
393
+ }
394
+ }
395
+ });
396
+ },
397
+
398
+ toggle_file_view: function()
399
+ {
400
+ var that = this;
401
+ that.file_view = (that.file_view == 'thumbnail' ? 'list' : 'thumbnail');
402
+ that.print_media();
403
+ },
404
+
405
+ media_with_id: function(media_id)
406
+ {
407
+ var that = this;
408
+ var media = false;
409
+ $.each(that.media, function(i, m) {
410
+ if (m.id == media_id)
411
+ {
412
+ media = m;
413
+ return false;
414
+ }
415
+ });
416
+ return media;
417
+ },
418
+
419
+ });