caboose-cms 0.6.16 → 0.6.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YjI1YjFlNmY3MmZkYWIzMTJlNGFmZjVhZjJjMDk5OTE0ZjUyMWI0YQ==
4
+ Y2JhZWYzY2JiNzdlZmMxOGM4YzlmM2Y3MDUzMWFjZTg2ODM5YzNkMg==
5
5
  data.tar.gz: !binary |-
6
- MTQyNjIxZTRlZWQ0MTFiOTJkYjU0MDZmZGZhMzYxNmJhNWFiZDM1NQ==
6
+ OWU4M2RlOTk1ZTUzZjRhOTI2NjgzYzU0NjhmMGRlYTMzZjNiZjIwZg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ZGZhNTk2ZmM1YWNjZmRiNjhjYTIzMjUyNDFkNWFiODcxZjU4YTNmOGJiNTdm
10
- OGJmZmIzMzllOWZiZGNkYmRmZmQ1NWM4OGFhZTNiN2EzNTFiOGM4OWY0Nzcw
11
- Y2NiNmMyZjM4NzVhZDZiNThjMjM1MDg3ZTM1MTJhZGM2MGViZmM=
9
+ ZjIzMjFjYmNjNTA4MzBhNDI2MTA5OGZjM2I3MmVjMWU1NjA3ZGI0Mzk2YjEz
10
+ MzQ4MmRkNGFiOGY1NjQwNzhlNmIyMTEzNWI3OGI3MzQwMGIyMDE0YjhjOGQ5
11
+ ODk2MzIyMTllNzA5Y2RiYjE5Y2YxYTgyODJjZjE1Zjg0YzM4ZWQ=
12
12
  data.tar.gz: !binary |-
13
- OWQyZDRlMGU4ZTJlNTM5NGQ0YjRkZWZiM2ZhZTIzNzE1MTQwODgyMzNjYmNh
14
- MzgzNGNkN2YwNThmNDVlNTMwMTI5ZDVhMDQyYTllZjU5YWZhYWU1NzU1Yjc5
15
- YjdlMDVhMzc0NjhjNDJmM2EyZTk4ZGVjMzE5MzNiZWNmYzY5OGQ=
13
+ NjdiZmYxZTg0YTFiYjcwODMyNWFhOTRlMDBlNjI3ZjQyYWI1OWUwY2JlODgy
14
+ NGNjMGRhOWYzYjgzZjc5ODU2NDQyZWQ5YjZjNjg2ODcyM2U3MGYzYWExZTJj
15
+ NzI3OTk2MzY4OTczMmI3OWZkYTNjMDkwOGM5NGZkMTM1YWFkMWY=
@@ -0,0 +1,466 @@
1
+
2
+ var MediaController = function(params) { this.init(params); };
3
+
4
+ MediaController.prototype = {
5
+
6
+ top_cat_id: false,
7
+ cat: false,
8
+ cat_id: false,
9
+ categories: false,
10
+ s3_upload_url: false,
11
+ aws_access_key_id: false,
12
+ policy: false,
13
+ signature: false,
14
+ selected_media: false,
15
+ uploader: false,
16
+ refresh_unprocessed_images: false,
17
+
18
+
19
+
20
+
21
+
22
+ init: function(params) {
23
+ var that = this;
24
+ for (var i in params)
25
+ this[i] = params[i];
26
+
27
+ $("#uploader")
28
+ .empty()
29
+ .append($('<p/>')
30
+ .append($('<a/>').attr('href', '#').html('Upload').click(function(e) { e.preventDefault(); that.toggle_uploader(); }))
31
+ .append(' | ')
32
+ .append($('<a/>').attr('href', '#').html('Select All').click(function(e) { e.preventDefault(); that.select_all_media(); }))
33
+ )
34
+ .append($('<div/>').attr('id', 'the_uploader'));
35
+ that.refresh();
36
+ },
37
+
38
+ refresh: function()
39
+ {
40
+ var that = this;
41
+ that.refresh_categories();
42
+ that.refresh_media();
43
+ that.print_controls();
44
+
45
+ },
46
+
47
+ toggle_uploader: function()
48
+ {
49
+ var that = this;
50
+ if (that.uploader)
51
+ {
52
+ $("#the_uploader").slideUp(400, function() {
53
+ $("#the_uploader").plupload('destroy');
54
+ that.uploader = false;
55
+ });
56
+ }
57
+ else
58
+ {
59
+ $("#the_uploader").hide();
60
+ that.uploader = $("#the_uploader").plupload({
61
+ runtimes: 'html5,flash,silverlight',
62
+ url: that.s3_upload_url,
63
+ multipart: true,
64
+ multipart_params: {
65
+ key: that.cat_id + '_${filename}', // use filename as a key
66
+ Filename: that.cat_id + '_${filename}', // adding this to keep consistency across the runtimes
67
+ acl: 'public-read',
68
+ //'Content-Type': 'image/jpeg',
69
+ AWSAccessKeyId: that.aws_access_key_id,
70
+ policy: that.policy,
71
+ signature: that.signature
72
+ },
73
+ file_data_name: 'file', // optional, but better be specified directly
74
+ filters: {
75
+ max_file_size: '100mb', // Maximum file size
76
+ mime_types: [{ title: "Upload files", extensions: "jpg,jpeg,png,gif,tif,tiff,pdf,doc,docx,odt,odp,ods,ppt,pptx,xls,xlsx,zip,tgz,csv,txt" }] // Specify what files to browse for
77
+ },
78
+ flash_swf_url: '../../js/Moxie.swf', // Flash settings
79
+ silverlight_xap_url: '../../js/Moxie.xap', // Silverlight settings
80
+ init: {
81
+ BeforeUpload: function(up, file) {
82
+ $.ajax({
83
+ url: '/admin/media/pre-upload',
84
+ type: 'post',
85
+ data: {
86
+ media_category_id: that.cat_id,
87
+ name: file.name
88
+ },
89
+ success: function(resp) {},
90
+ async: false
91
+ });
92
+ controller.refresh();
93
+ },
94
+ FileUploaded: function(ip, file)
95
+ {
96
+ that.refresh();
97
+ },
98
+ UploadComplete: function(up, files) {
99
+ that.refresh();
100
+ if (that.uploader)
101
+ {
102
+ $("#the_uploader").slideUp(400, function() {
103
+ $("#the_uploader").plupload('destroy');
104
+ that.uploader = false;
105
+ });
106
+ }
107
+ }
108
+ }
109
+ });
110
+ $("#the_uploader").slideDown();
111
+ }
112
+ },
113
+
114
+ refresh_categories: function(after)
115
+ {
116
+ var that = this;
117
+ $.ajax({
118
+ url: '/admin/media-categories/tree',
119
+ type: 'get',
120
+ async: false,
121
+ success: function(resp) {
122
+ that.top_category = resp;
123
+ if (!that.cat_id)
124
+ that.cat_id = that.top_category.id;
125
+ that.print_categories();
126
+ if (after) after();
127
+ }
128
+ });
129
+ },
130
+
131
+ refresh_media: function()
132
+ {
133
+ var that = this;
134
+ $.ajax({
135
+ url: '/admin/media/json',
136
+ type: 'get',
137
+ async: false,
138
+ data: { media_category_id: that.cat_id },
139
+ success: function(resp) {
140
+ that.cat = resp;
141
+ that.cat_id = that.cat.id;
142
+ that.selected_media = [];
143
+ that.print_media();
144
+ }
145
+ });
146
+ },
147
+
148
+ print_categories_helper: function(cat)
149
+ {
150
+ var that = this;
151
+ var li = $('<li/>')
152
+ .addClass('dd-item')
153
+ .addClass('category')
154
+ .attr('id', 'cat' + cat.id)
155
+ .data('id', cat.id)
156
+ .data('media_category_id', cat.id)
157
+ .append($('<div/>').addClass('dd-handle').html(cat.name + ' (' + cat.media_count + ')'));
158
+ if (cat.children.length > 0)
159
+ {
160
+ var ol = $('<ol/>').addClass('dd-list')
161
+ $.each(cat.children, function(i, cat2) {
162
+ ol.append(that.print_categories_helper(cat2));
163
+ });
164
+ li.append(ol);
165
+ }
166
+ if (cat.id == that.cat_id)
167
+ li.addClass('selected');
168
+ return li;
169
+ },
170
+
171
+ print_categories: function()
172
+ {
173
+ var that = this;
174
+ var ol = $('<ol/>').addClass('dd-list');
175
+ ol.append(that.print_categories_helper(that.top_category));
176
+ $('#categories').empty().append(ol)
177
+ .append($('<p/>').append($('<a/>').attr('href', '#').html('New Category').click(function(e) { e.preventDefault(); that.add_category(); })))
178
+ .append($('<div/>').attr('id', 'new_cat_message'));
179
+ //$('#categories').nestable({
180
+ //
181
+ //});
182
+
183
+ $.each(that.categories, function(i, cat) {
184
+ $('#cat' + cat.id).droppable({
185
+ accept: function(draggable) { return (draggable.hasClass('category') || draggable.hasClass('media')) },
186
+ hoverClass: 'cat_hover',
187
+ drop: function(event, ui) {
188
+ if (ui.draggable.hasClass('category'))
189
+ {
190
+ var child_cat_id = ui.draggable.data('media_category_id');
191
+ var new_parent_id = $(this).data('media_category_id');
192
+ $.ajax({
193
+ url: '/admin/media-categories/' + child_cat_id,
194
+ type: 'put',
195
+ data: { parent_id: new_parent_id },
196
+ success: function(resp) { that.refresh_categories(); }
197
+ });
198
+ }
199
+ else // media
200
+ {
201
+ var media_category_id = $(this).data('media_category_id');
202
+ var ids = (that.selected_media.length > 0 ? that.selected_media : [ui.draggable.data('media_id')]);
203
+ $.ajax({
204
+ url: '/admin/media-categories/' + media_category_id + '/attach',
205
+ type: 'post',
206
+ data: { media_id: ids },
207
+ success: function(resp) { that.refresh_categories(); that.refresh_media(); }
208
+ });
209
+ }
210
+ }
211
+ });
212
+ $('#cat' + cat.id).draggable({ revert: 'invalid' });
213
+ });
214
+ },
215
+
216
+ print_controls: function()
217
+ {
218
+ var that = this;
219
+ $('#controls').empty()
220
+ .append($('<div/>').attr('id', 'delete').append($('<p/>').addClass('delete_dropper').html('Delete')));
221
+
222
+ $('#delete').droppable({
223
+ accept: function(draggable) { return (draggable.hasClass('category') || draggable.hasClass('media')) },
224
+ hoverClass: 'hover',
225
+ drop: function(event, ui) {
226
+ if (ui.draggable.hasClass('category'))
227
+ {
228
+ var media_category_id = ui.draggable.data('media_category_id');
229
+ that.delete_category(media_category_id);
230
+ }
231
+ else // media
232
+ {
233
+ id = ui.draggable.data('media_id');
234
+ if (that.selected_media.length > 0 && that.selected_media.indexOf(id) > -1)
235
+ {
236
+ that.select_media(id); // Go ahead and de-select because the select event is about to run
237
+ }
238
+ that.delete_media();
239
+ }
240
+ }
241
+ });
242
+ },
243
+
244
+ print_media: function()
245
+ {
246
+ var that = this;
247
+ var ul = $('<ul/>');
248
+ var processing = false;
249
+ if (that.cat.media.length > 0)
250
+ {
251
+ $.each(that.cat.media, function(i, m) {
252
+ if (m.media_type == 'image' && m.processed == false)
253
+ processing = true
254
+ var li = $('<li/>')
255
+ .attr('id', 'media' + m.id)
256
+ .addClass('media')
257
+ .data('media_id', m.id)
258
+ .click(function(e) { that.select_media($(this).data('media_id')); })
259
+ .append($('<span/>').addClass('name').html(m.name).click(function(e) {
260
+ e.stopPropagation();
261
+ that.edit_media_description($(this).parent().data('media_id'));
262
+ }));
263
+ if (m.image_urls)
264
+ li.append($('<img/>').attr('src', m.image_urls.tiny_url));
265
+ if (that.selected_media.indexOf(m.id) > -1)
266
+ li.addClass('selected ui-selected');
267
+ ul.append(li);
268
+ });
269
+ }
270
+ else
271
+ ul = $('<p/>').html("This category is empty.");
272
+ $('#media').empty().append(ul);
273
+ if (that.refresh_unprocessed_images == true && processing)
274
+ setTimeout(function() { that.refresh(); }, 2000);
275
+
276
+ $.each(that.cat.media, function(i, m) {
277
+ $('li.media').draggable({
278
+ multiple: true,
279
+ revert: 'invalid',
280
+ start: function() { $(this).data("origPosition", $(this).position()); }
281
+ });
282
+ });
283
+ },
284
+
285
+ //============================================================================
286
+
287
+ select_media: function(media_id)
288
+ {
289
+ var that = this;
290
+ var i = that.selected_media.indexOf(media_id);
291
+ if (i > -1)
292
+ {
293
+ that.selected_media.splice(i, 1);
294
+ $('#media' + media_id).removeClass('selected ui-selected');
295
+ }
296
+ else
297
+ {
298
+ that.selected_media[that.selected_media.length] = media_id;
299
+ $('#media' + media_id).addClass('selected ui-selected').css('top', '0').css('left', '0');
300
+ }
301
+
302
+
303
+
304
+
305
+
306
+
307
+
308
+
309
+
310
+
311
+ },
312
+
313
+ select_all_media: function()
314
+ {
315
+ var that = this;
316
+
317
+ // See if they're all selected
318
+ var all_selected = true;
319
+ $.each(that.cat.media, function(i, m) {
320
+ if (that.selected_media.indexOf(m.id) == -1)
321
+ {
322
+ all_selected = false
323
+ return false;
324
+ }
325
+ });
326
+
327
+ // Now de-select everything
328
+ $('li.media').removeClass('selected ui-selected');
329
+ that.selected_media = [];
330
+
331
+ // And re-select everything if not everything was previously selected
332
+ if (!all_selected)
333
+ {
334
+ $.each(that.cat.media, function(i, m) {
335
+ $('#media' + m.id).addClass('selected ui-selected');
336
+ that.selected_media[i] = m.id;
337
+ });
338
+ }
339
+ },
340
+
341
+ delete_media: function(confirm)
342
+ {
343
+ var that = this;
344
+ if (!confirm)
345
+ {
346
+ $.each(that.selected_media, function(i, id) {
347
+ $('#media' + id).css('top', '0').css('left', '0');
348
+ });
349
+ var div = $('<p/>').addClass('note error')
350
+ .append('Are you sure?<br/>')
351
+ .append($('<input/>').attr('type', 'button').val('Yes').click(function() { that.delete_media(true); })).append(" ")
352
+ .append($('<input/>').attr('type', 'button').val('No' ).click(function() { that.refresh_media(); that.print_controls(); }));
353
+ $('#delete').empty().append(div);
354
+ return;
355
+ }
356
+ $('#delete').empty().html("<p class='loading'>Deleting...</p>");
357
+ $.ajax({
358
+ url: '/admin/media/bulk',
359
+ type: 'delete',
360
+ data: { ids: that.selected_media },
361
+ success: function(resp) { that.refresh_categories(); that.refresh_media(); that.print_controls(); }
362
+ });
363
+ },
364
+
365
+ edit_media_description: function(media_id)
366
+ {
367
+ var that = this;
368
+ caboose_modal_url('/admin/media/' + media_id + '/description');
369
+
370
+ //var div = $('<div/>').attr('id', 'media_' + media_id + '_description');
371
+ //$('#media').append(div);
372
+ //new ModelBinder({
373
+ // name: 'Media',
374
+ // id: media_id,
375
+ // update_url: '/admin/media/' + media_id,
376
+ // authenticity_token: that.authenticity_token,
377
+ // attributes: [
378
+ // {
379
+ // name: 'description', nice_name: 'Description', type: 'textarea', value: '', width: 400, height: 100, fixed_placeholder: true,
380
+ // after_update: function() { $('#media_' + media_id + '_description_container').remove(); },
381
+ // after_cancel: function() { $('#media_' + media_id + '_description_container').remove(); }
382
+ // }
383
+ // ]
384
+ //});
385
+ //var options = {
386
+ // iframe: true,
387
+ // innerWidth: 200,
388
+ // innerHeight: 50,
389
+ // scrolling: false,
390
+ // transition: 'fade',
391
+ // closeButton: false,
392
+ // onComplete: caboose_fix_colorbox,
393
+ // opacity: 0.50
394
+ //};
395
+ //setTimeout(function() { $('#media_' + media_id + '_description_container').colorbox(options); }, 2000);
396
+ },
397
+
398
+ //============================================================================
399
+
400
+ select_category: function(cat_id)
401
+ {
402
+ var that = this;
403
+ that.cat_id = cat_id;
404
+ that.print_categories();
405
+ that.refresh_media();
406
+ },
407
+
408
+ add_category: function(name)
409
+ {
410
+ var that = this;
411
+ if (!name)
412
+ {
413
+ var div = $('<p/>').addClass('note warning')
414
+ .append('New Category Name: ')
415
+ .append($('<input/>').attr('type', 'text').attr('id', 'new_cat_name')).append(" ")
416
+ .append($('<input/>').attr('type', 'button').val('Add').click(function() { that.add_category($('#new_cat_name').val()); })).append(" ")
417
+ .append($('<input/>').attr('type', 'button').val('Cancel').click(function() { $('#new_cat_message').empty(); }));
418
+ $('#new_cat_message').empty().append(div);
419
+ return;
420
+ }
421
+ $('#new_cat_message').empty().html("<p class='loading'>Adding category...</p>");
422
+ $.ajax({
423
+ url: '/admin/media-categories',
424
+ type: 'post',
425
+ data: {
426
+ parent_id: that.cat.id,
427
+ name: name
428
+ },
429
+ success: function(resp) {
430
+ if (resp.error) $('#new_cat_message').empty().html("<p class='note error'>" + resp.error + "</p>");
431
+ if (resp.refresh) that.refresh_categories();
432
+ }
433
+ });
434
+ },
435
+
436
+ delete_category: function(cat_id, confirm)
437
+ {
438
+ var that = this;
439
+ if (!confirm)
440
+ {
441
+ var div = $('<p/>').addClass('note warning')
442
+ .append('Are you sure? ')
443
+ .append($('<input/>').attr('type', 'button').val('Yes').click(function() { that.delete_category(cat_id, true); })).append(" ")
444
+ .append($('<input/>').attr('type', 'button').val('No' ).click(function() { that.refresh_categories(); that.print_controls() }));
445
+ $('#delete').empty().append(div);
446
+ return;
447
+ }
448
+ $('#delete').empty().html("<p class='loading'>Deleting...</p>");
449
+ $.ajax({
450
+ url: '/admin/media-categories/' + cat_id,
451
+ type: 'delete',
452
+ success: function(resp) {
453
+ that.refresh_categories(function() {
454
+ var exists = false;
455
+ $.each(that.categories, function(i, cat) { if (cat.id == cat_id) { exists = true; return false; }});
456
+ if (!exists)
457
+ that.select_category(that.categories[0].id);
458
+ else
459
+ that.refresh_media();
460
+ that.print_controls();
461
+ });
462
+ }
463
+ });
464
+ },
465
+
466
+ };