scrivito_resourcebrowser 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +3 -0
- data/LICENSE +4 -0
- data/README.md +52 -0
- data/Rakefile +4 -0
- data/app/assets/javascripts/scrivito_resourcebrowser/inspector.js.coffee +65 -0
- data/app/assets/javascripts/scrivito_resourcebrowser/resourcebrowser.js.coffee +420 -0
- data/app/assets/javascripts/scrivito_resourcebrowser/uploader.js.coffee +132 -0
- data/app/assets/javascripts/scrivito_resourcebrowser.js +13 -0
- data/app/assets/stylesheets/scrivito_resourcebrowser/resourcebrowser.css +1010 -0
- data/app/assets/stylesheets/scrivito_resourcebrowser.css +12 -0
- data/app/controllers/scrivito_resourcebrowser/resourcebrowser_controller.rb +36 -0
- data/app/views/layouts/scrivito_resourcebrowser/inspector.html.erb +11 -0
- data/app/views/scrivito_resourcebrowser/application.html.erb +14 -0
- data/app/views/scrivito_resourcebrowser/obj/details.html +7 -0
- data/app/views/scrivito_resourcebrowser/resourcebrowser/_buttons.html.erb +16 -0
- data/app/views/scrivito_resourcebrowser/resourcebrowser/_header.html.erb +25 -0
- data/app/views/scrivito_resourcebrowser/resourcebrowser/modal.html.erb +12 -0
- data/config/initializers/resourcebrowser.rb +13 -0
- data/config/routes.rb +5 -0
- data/lib/scrivito_resourcebrowser/engine.rb +5 -0
- data/lib/scrivito_resourcebrowser/version.rb +3 -0
- data/lib/scrivito_resourcebrowser.rb +4 -0
- metadata +122 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 510275617f4f8a67da0e59da5894ebdb4e9eebbd
|
4
|
+
data.tar.gz: 8b2840de01ac7e2067d38f69950547bf8e967522
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 168f45c11796dcdf5f6a2e272c44c7d6eaf8d98c58686e278829e34cef79cb6993af0a3e9a0261d32e48d88f4279103af98077dd7e18f7d67bb63e812114cc31
|
7
|
+
data.tar.gz: ee4b97fee0ef7fa22c06bc28de6f3f327552f3b73a03fc3f70ead08600dc09f1ed041cb02ed1c8dfc6efe0a6a445914cc95e78468820fb98acffe25112cf61f0
|
data/CHANGELOG.md
ADDED
data/LICENSE
ADDED
data/README.md
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# Scrivito Resource Browser
|
2
|
+
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/scrivito_resourcebrowser.png)](http://badge.fury.io/rb/scrivito_resourcebrowser)
|
4
|
+
[![Code Climate](https://codeclimate.com/github/infopark/scrivito_resourcebrowser.png)](https://codeclimate.com/github/infopark/scrivito_resourcebrowser)
|
5
|
+
[![Dependency Status](https://gemnasium.com/infopark/scrivito_resourcebrowser.png)](https://gemnasium.com/infopark/scrivito_resourcebrowser)
|
6
|
+
[![Build Status](https://travis-ci.org/infopark/scrivito_resourcebrowser.png)](https://travis-ci.org/infopark/scrivito_resourcebrowser)
|
7
|
+
|
8
|
+
The [Scrivito](http://scrivito.com) Resource Browser is a JavaScript based tool to add, update and
|
9
|
+
delete resources. It provides flexible configuration options and can easily be integrated into your
|
10
|
+
application.
|
11
|
+
|
12
|
+
## Installation and Usage
|
13
|
+
|
14
|
+
TODO
|
15
|
+
|
16
|
+
|
17
|
+
## Changelog
|
18
|
+
|
19
|
+
See [Changelog](https://github.com/infopark/scrivito_resourcebrowser/blob/master/CHANGELOG.md) for more
|
20
|
+
details.
|
21
|
+
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
We would be very happy and thankful if you open new issues in order to further improve Scrivito
|
26
|
+
Resource Browser. If you want to go a step further and extend the functionality or fix a problem,
|
27
|
+
you can do so any time by following the steps below.
|
28
|
+
|
29
|
+
1. Fork and clone the
|
30
|
+
[Scrivito Resource Browser GitHub repository](https://github.com/infopark/scrivito_resourcebrowser).
|
31
|
+
|
32
|
+
git clone git@github.com:_username_/scrivito_resourcebrowser.git
|
33
|
+
cd scrivito_resourcebrowser
|
34
|
+
|
35
|
+
2. We suggest using [rbenv](https://github.com/sstephenson/rbenv/) for managing your local Ruby
|
36
|
+
version. Make sure to use at least Ruby version 2.0.
|
37
|
+
|
38
|
+
ruby --version
|
39
|
+
|
40
|
+
3. Create your feature branch and create a pull request for the `develop` branch. Please take a
|
41
|
+
look at the already existing generators and rake tasks to get an impression of our coding style
|
42
|
+
and the general architecture.
|
43
|
+
|
44
|
+
4. We are using the [GitHub Styleguides](https://github.com/styleguide) and would prefer if you
|
45
|
+
could stick to it.
|
46
|
+
|
47
|
+
|
48
|
+
## License
|
49
|
+
Copyright (c) 2009 - 2014 Infopark AG (http://www.infopark.com)
|
50
|
+
|
51
|
+
This software can be used and modified under the LGPL-3.0. Please refer to
|
52
|
+
http://www.gnu.org/licenses/lgpl-3.0.html for the license text.
|
data/Rakefile
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
@ResourcebrowserInspector = do ->
|
2
|
+
inspectorSelector: '.editing-resourcebrowser-inspector'
|
3
|
+
contentSelector: '.inspector-content'
|
4
|
+
inspector: undefined
|
5
|
+
objectId: undefined
|
6
|
+
|
7
|
+
_initializeBindings: ->
|
8
|
+
@modal.on 'click', 'li.resourcebrowser-item', (event) =>
|
9
|
+
@_onInspect(event)
|
10
|
+
|
11
|
+
@inspector = @modal.find(@inspectorSelector)
|
12
|
+
@inspector.hide()
|
13
|
+
|
14
|
+
_onInspect: (event) ->
|
15
|
+
if $(event.target).hasClass('editing-resourcebrowser-inspect')
|
16
|
+
currentTarget = $(event.currentTarget)
|
17
|
+
id = currentTarget.data('id')
|
18
|
+
|
19
|
+
if id
|
20
|
+
@open(id)
|
21
|
+
@_highlightItem(currentTarget)
|
22
|
+
|
23
|
+
_renderLoading: ->
|
24
|
+
@inspector.html(@_loadingTemplate())
|
25
|
+
|
26
|
+
_loadingTemplate: ->
|
27
|
+
icon = $('<i></i>')
|
28
|
+
.addClass('editing-icon editing-icon-refresh')
|
29
|
+
|
30
|
+
$('<div></div>')
|
31
|
+
.addClass('editing-resourcebrowser-loading')
|
32
|
+
.html(icon)
|
33
|
+
|
34
|
+
_highlightItem: (element) ->
|
35
|
+
@modal.find('li.resourcebrowser-item.active').removeClass('active')
|
36
|
+
element.addClass('active')
|
37
|
+
|
38
|
+
init: (modal) ->
|
39
|
+
@modal = modal
|
40
|
+
@_initializeBindings()
|
41
|
+
|
42
|
+
# Opens the inspector section in the resourcebrowser for the given object ID and displays its edit
|
43
|
+
# view.
|
44
|
+
open: (objectId) ->
|
45
|
+
@objectId = objectId
|
46
|
+
|
47
|
+
@inspector.show()
|
48
|
+
@_renderLoading()
|
49
|
+
|
50
|
+
$.ajax
|
51
|
+
url: '/resourcebrowser/inspector'
|
52
|
+
dataType: 'json'
|
53
|
+
data:
|
54
|
+
id: @objectId
|
55
|
+
success: (json) =>
|
56
|
+
@inspector.html(json.content)
|
57
|
+
scrivito.trigger('new_content', @inspector)
|
58
|
+
|
59
|
+
error: =>
|
60
|
+
@inspector.empty()
|
61
|
+
|
62
|
+
# Closes the inspector section of the resourcebrowser.
|
63
|
+
close: ->
|
64
|
+
@inspector.empty()
|
65
|
+
@inspector.hide()
|
@@ -0,0 +1,420 @@
|
|
1
|
+
@Resourcebrowser = do ->
|
2
|
+
thumbnailViewButtonSelector: '.editing-button-view'
|
3
|
+
options: {}
|
4
|
+
|
5
|
+
# The resource browser supports operations like +delete+ and +edit+ of resources that require a page
|
6
|
+
# reload, so that all references of the resources get updated.
|
7
|
+
reload: false
|
8
|
+
|
9
|
+
_getBatchSize: ->
|
10
|
+
@batchSize ||= 20
|
11
|
+
|
12
|
+
_getThumbnailSize: ->
|
13
|
+
@thumbnailSize ||= 'normal'
|
14
|
+
|
15
|
+
_setThumbnailSize: (value) ->
|
16
|
+
@thumbnailSize = value
|
17
|
+
|
18
|
+
_filterListTemplate: (filters) ->
|
19
|
+
list = $('<ul></ul>')
|
20
|
+
.addClass('editing-resourcebrowser-filter-items')
|
21
|
+
|
22
|
+
for name, options of filters
|
23
|
+
title = options.title
|
24
|
+
icon = options.icon || 'editing-icon-generic'
|
25
|
+
query = @_prepareQuery(options.query)
|
26
|
+
|
27
|
+
@_filterTemplate(title, icon, query)
|
28
|
+
.appendTo(list)
|
29
|
+
|
30
|
+
list
|
31
|
+
|
32
|
+
_loadFilter: () ->
|
33
|
+
filters = @_selectedFilters()
|
34
|
+
wrapper = @modal.find('.editing-resourcebrowser-filter')
|
35
|
+
|
36
|
+
@_filterListTemplate(filters)
|
37
|
+
.appendTo(wrapper)
|
38
|
+
|
39
|
+
@_defaultFilter().trigger('click')
|
40
|
+
|
41
|
+
_selectedFilters: ->
|
42
|
+
availableFilters = @filters()
|
43
|
+
selectedFilters = @options.filters
|
44
|
+
filters = availableFilters
|
45
|
+
|
46
|
+
if selectedFilters?
|
47
|
+
unless $.isArray(selectedFilters)
|
48
|
+
selectedFilters = new Array(selectedFilters)
|
49
|
+
|
50
|
+
filters = {}
|
51
|
+
|
52
|
+
for filterId, filter of availableFilters
|
53
|
+
if filterId in selectedFilters
|
54
|
+
filters[filterId] = filter
|
55
|
+
|
56
|
+
filters
|
57
|
+
|
58
|
+
_defaultFilter: ->
|
59
|
+
@_filterItems().first()
|
60
|
+
|
61
|
+
_getFilterQuery: (filter) ->
|
62
|
+
filter.data('query')
|
63
|
+
|
64
|
+
_defaultQuery: ->
|
65
|
+
@_getFilterQuery(@_defaultFilter())
|
66
|
+
|
67
|
+
_activeQuery: ->
|
68
|
+
filter = @_filterItems().filter('.active')
|
69
|
+
@_getFilterQuery(filter)
|
70
|
+
|
71
|
+
_filterItems: ->
|
72
|
+
@modal.find('li.filter')
|
73
|
+
|
74
|
+
_deactivateAllFilter: ->
|
75
|
+
@_getSearch().val('')
|
76
|
+
@_filterItems().removeClass('active')
|
77
|
+
|
78
|
+
_triggerFilter: (filter) ->
|
79
|
+
@_deactivateAllFilter()
|
80
|
+
|
81
|
+
filter.addClass('active')
|
82
|
+
|
83
|
+
query = @_getFilterQuery(filter)
|
84
|
+
@_renderPlaceholder(query)
|
85
|
+
|
86
|
+
_filterTemplate: (title, icon, query) ->
|
87
|
+
filter = $('<li></li>')
|
88
|
+
.addClass('filter')
|
89
|
+
.data('query', query)
|
90
|
+
|
91
|
+
icon = $('<span></span>')
|
92
|
+
.addClass('editing-icon')
|
93
|
+
.addClass(icon)
|
94
|
+
.appendTo(filter)
|
95
|
+
|
96
|
+
title = $('<span></span>')
|
97
|
+
.addClass('editing-resourcebrowser-filter-name')
|
98
|
+
.html(title)
|
99
|
+
.appendTo(filter)
|
100
|
+
|
101
|
+
filter
|
102
|
+
|
103
|
+
_prepareQuery: (query) ->
|
104
|
+
params = $.extend(true, {}, query.query())
|
105
|
+
scrivito.chainable_search.create_instance(params)
|
106
|
+
.order('_last_changed')
|
107
|
+
.reverse_order()
|
108
|
+
.format('resourcebrowser')
|
109
|
+
|
110
|
+
_save: ->
|
111
|
+
(@options.onSave || $.noop)(@selected)
|
112
|
+
|
113
|
+
@close()
|
114
|
+
|
115
|
+
_delete: ->
|
116
|
+
(@options.onDelete || $.noop)(@selected)
|
117
|
+
|
118
|
+
$.each @selected, (index, id) =>
|
119
|
+
item = @_getItemContainer(id)
|
120
|
+
@_itemLoading(item)
|
121
|
+
|
122
|
+
scrivito.delete_obj(id).then =>
|
123
|
+
@modal.trigger('resource_change.resourcebrowser')
|
124
|
+
item.remove()
|
125
|
+
|
126
|
+
@_deselectAllItems()
|
127
|
+
|
128
|
+
_getItemId: (item) ->
|
129
|
+
$(item).closest('li.resourcebrowser-item').data('id')
|
130
|
+
|
131
|
+
_getItemContainer: (id) ->
|
132
|
+
$('li.resourcebrowser-item').filter ->
|
133
|
+
id == $(this).data('id')
|
134
|
+
|
135
|
+
_selectItem: (item) ->
|
136
|
+
if (item.hasClass('active'))
|
137
|
+
@_removeItem(item)
|
138
|
+
else
|
139
|
+
@_addItem(item)
|
140
|
+
|
141
|
+
_addItem: (item) ->
|
142
|
+
@_activateItem(item)
|
143
|
+
|
144
|
+
id = @_getItemId(item)
|
145
|
+
|
146
|
+
@selected.push(id)
|
147
|
+
@_setSelected($.unique(@selected))
|
148
|
+
|
149
|
+
_removeItem: (item) ->
|
150
|
+
@_deactivateItem(item)
|
151
|
+
|
152
|
+
selected = @selected.filter (id) =>
|
153
|
+
id != @_getItemId(item)
|
154
|
+
|
155
|
+
@_setSelected(selected)
|
156
|
+
|
157
|
+
_activateItem: (item) ->
|
158
|
+
$(item).addClass('active')
|
159
|
+
|
160
|
+
_deactivateItem: (item) ->
|
161
|
+
$(item).removeClass('active')
|
162
|
+
|
163
|
+
_changeSelectedTotal: ->
|
164
|
+
@modal.find('.selected-total').html(@selected.length)
|
165
|
+
|
166
|
+
_setSelected: (value) ->
|
167
|
+
@selected = value || @options.selection || []
|
168
|
+
@_changeSelectedTotal()
|
169
|
+
|
170
|
+
_deselectAllItems: ->
|
171
|
+
@_setSelected([])
|
172
|
+
@modal.find('li.resourcebrowser-item .select-item.active').removeClass('active')
|
173
|
+
|
174
|
+
_getItems: ->
|
175
|
+
@modal.find('.editing-resourcebrowser-items')
|
176
|
+
|
177
|
+
_getContainer: ->
|
178
|
+
@modal.find('.editing-resourcebrowser-thumbnails')
|
179
|
+
|
180
|
+
_itemsPlaceholder: (count) ->
|
181
|
+
size = @_getThumbnailSize()
|
182
|
+
|
183
|
+
list = $('<ul></ul>')
|
184
|
+
.addClass('items editing-resourcebrowser-thumbnails')
|
185
|
+
.addClass(size)
|
186
|
+
|
187
|
+
content = for index in [0...count] by 1
|
188
|
+
itemTemplate = @_itemPlaceholderTemplate(index)
|
189
|
+
list.append(itemTemplate)
|
190
|
+
|
191
|
+
@_getItems().html(content)
|
192
|
+
|
193
|
+
_itemPlaceholderTemplate: (index) ->
|
194
|
+
item = $('<li></li>')
|
195
|
+
.addClass('resourcebrowser-item')
|
196
|
+
.attr('data-index', index)
|
197
|
+
|
198
|
+
@_itemLoading(item)
|
199
|
+
|
200
|
+
_itemLoading: (item) ->
|
201
|
+
loading = @_loadingTemplate()
|
202
|
+
$(item).html(loading)
|
203
|
+
|
204
|
+
_renderPlaceholder: (query) ->
|
205
|
+
query ||= @_defaultQuery()
|
206
|
+
|
207
|
+
return unless query?
|
208
|
+
|
209
|
+
@_getItems()
|
210
|
+
.empty()
|
211
|
+
.html(@_loadingTemplate())
|
212
|
+
|
213
|
+
query.size()
|
214
|
+
.then (total) =>
|
215
|
+
if total > 0
|
216
|
+
@_itemsPlaceholder(total)
|
217
|
+
@_renderItems(query)
|
218
|
+
else
|
219
|
+
@_getItems().empty()
|
220
|
+
|
221
|
+
_renderItems: (query, index = 0) ->
|
222
|
+
query
|
223
|
+
.batch_size(@_getBatchSize())
|
224
|
+
|
225
|
+
query.load_batch()
|
226
|
+
.then (result, next) =>
|
227
|
+
objects = result.hits
|
228
|
+
@_replacePlaceholder(objects, index)
|
229
|
+
|
230
|
+
if next?
|
231
|
+
start = index + objects.length
|
232
|
+
@_renderItems(next, start)
|
233
|
+
|
234
|
+
_replacePlaceholder: (objects, startIndex) ->
|
235
|
+
$(objects).each (index, object) =>
|
236
|
+
elementIndex = startIndex + index
|
237
|
+
template = @_itemTemplate(object)
|
238
|
+
|
239
|
+
@modal.find("li.resourcebrowser-item[data-index=#{elementIndex}]")
|
240
|
+
.html(template)
|
241
|
+
.data('id', object.id)
|
242
|
+
|
243
|
+
_itemTemplate: (object) ->
|
244
|
+
url = object.preview
|
245
|
+
title = object.title || object.name
|
246
|
+
id = object.id
|
247
|
+
|
248
|
+
wrapper = $('<div></div>')
|
249
|
+
|
250
|
+
preview = $('<div></div>')
|
251
|
+
.addClass('editing-resourcebrowser-preview')
|
252
|
+
.appendTo(wrapper)
|
253
|
+
|
254
|
+
inspect = $('<span></span>')
|
255
|
+
.addClass('editing-resourcebrowser-inspect')
|
256
|
+
.appendTo(preview)
|
257
|
+
|
258
|
+
image = if url?
|
259
|
+
$('<img />')
|
260
|
+
.attr('src', url)
|
261
|
+
else
|
262
|
+
$('<span></span>')
|
263
|
+
.addClass('editing-icon')
|
264
|
+
.addClass('editing-icon-generic')
|
265
|
+
|
266
|
+
image.appendTo(preview)
|
267
|
+
|
268
|
+
meta = $('<div></div>')
|
269
|
+
.addClass('editing-resourcebrowser-meta')
|
270
|
+
.appendTo(wrapper)
|
271
|
+
|
272
|
+
title = $('<span></span>')
|
273
|
+
.addClass('editing-resourcebrowser-thumbnails-name')
|
274
|
+
.html(title)
|
275
|
+
.appendTo(meta)
|
276
|
+
|
277
|
+
select = $('<span></span>')
|
278
|
+
.addClass('editing-resourcebrowser-thumbnails-select select-item')
|
279
|
+
.appendTo(title)
|
280
|
+
|
281
|
+
if id in @selected
|
282
|
+
select.addClass('active')
|
283
|
+
|
284
|
+
wrapper
|
285
|
+
|
286
|
+
_getSearch: ->
|
287
|
+
@modal.find('input.search-field')
|
288
|
+
|
289
|
+
_triggerSearch: ->
|
290
|
+
term = @_getSearch().val()
|
291
|
+
query = @_prepareQuery(@_activeQuery())
|
292
|
+
|
293
|
+
if term? && term.length > 0
|
294
|
+
query.and('*', 'contains_prefix', term)
|
295
|
+
|
296
|
+
@_renderPlaceholder(query)
|
297
|
+
|
298
|
+
_initializeBindings: ->
|
299
|
+
$(window).resize ->
|
300
|
+
$('#editing-resourcebrowser.show').center()
|
301
|
+
|
302
|
+
@modal.on 'keyup', 'input.search-field', (event) =>
|
303
|
+
if event.keyCode == 13
|
304
|
+
@_triggerSearch()
|
305
|
+
|
306
|
+
@modal.on 'click', 'button.search-field-button', (event) =>
|
307
|
+
event.preventDefault()
|
308
|
+
@_triggerSearch()
|
309
|
+
|
310
|
+
@modal.on 'click', 'li.resourcebrowser-item', (event) =>
|
311
|
+
unless $(event.target).hasClass('editing-resourcebrowser-inspect')
|
312
|
+
item = $(event.currentTarget).find('.select-item')
|
313
|
+
@_selectItem(item)
|
314
|
+
|
315
|
+
@modal.on 'click', '.resourcebrowser-save', (event) =>
|
316
|
+
event.preventDefault()
|
317
|
+
@_save()
|
318
|
+
|
319
|
+
@modal.on 'click', '.resourcebrowser-delete', (event) =>
|
320
|
+
event.preventDefault()
|
321
|
+
@_delete()
|
322
|
+
|
323
|
+
@modal.on 'click', '.resourcebrowser-close', (event) =>
|
324
|
+
event.preventDefault()
|
325
|
+
@close()
|
326
|
+
|
327
|
+
@modal.on 'click', 'li.filter', (event) =>
|
328
|
+
event.preventDefault()
|
329
|
+
@_triggerFilter($(event.currentTarget))
|
330
|
+
|
331
|
+
@modal.on 'click', @thumbnailViewButtonSelector, (event) =>
|
332
|
+
size = $(event.currentTarget).data('size')
|
333
|
+
@_changeThumbnailSize(size)
|
334
|
+
|
335
|
+
@modal.on 'resource_change.resourcebrowser', (event) =>
|
336
|
+
@reload = true
|
337
|
+
|
338
|
+
$(document).on 'keyup.resourcebrowser', (event) =>
|
339
|
+
event.stopImmediatePropagation()
|
340
|
+
|
341
|
+
if event.keyCode == 27
|
342
|
+
# Make sure to remove the event handler after
|
343
|
+
# +stopImmediatePropagation()+, otherwise all ESC keys are caught and
|
344
|
+
# not propagated.
|
345
|
+
$(document).off 'keyup.resourcebrowser'
|
346
|
+
|
347
|
+
@close()
|
348
|
+
|
349
|
+
_loadModal: (content) ->
|
350
|
+
@overlay = $('<div></div>')
|
351
|
+
.addClass('editing-overlay show')
|
352
|
+
.appendTo($('body'))
|
353
|
+
|
354
|
+
@modal = $('<div></div>')
|
355
|
+
.addClass('editing-resourcebrowser show')
|
356
|
+
.attr('id', 'editing-resourcebrowser')
|
357
|
+
.appendTo($('body'))
|
358
|
+
.center()
|
359
|
+
.html(content)
|
360
|
+
|
361
|
+
@_initializeBindings()
|
362
|
+
|
363
|
+
_loadingTemplate: ->
|
364
|
+
icon = $('<i></i>')
|
365
|
+
.addClass('editing-icon editing-icon-refresh')
|
366
|
+
|
367
|
+
$('<div></div>')
|
368
|
+
.addClass('editing-resourcebrowser-loading')
|
369
|
+
.html(icon)
|
370
|
+
|
371
|
+
_changeThumbnailSize: (size) ->
|
372
|
+
size ||= @_getThumbnailSize()
|
373
|
+
@_setThumbnailSize(size)
|
374
|
+
|
375
|
+
transitionListener = 'webkitTransitionEnd.resourcebrowser otransitionend.resourcebrowser oTransitionEnd.resourcebrowser msTransitionEnd.resourcebrowser transitionend.resourcebrowser'
|
376
|
+
@modal.on transitionListener, 'li.resourcebrowser-item', (event) =>
|
377
|
+
@modal.off transitionListener
|
378
|
+
|
379
|
+
@_getContainer()
|
380
|
+
.removeClass('small normal big large')
|
381
|
+
.addClass(size)
|
382
|
+
|
383
|
+
@modal.find(@thumbnailViewButtonSelector)
|
384
|
+
.removeClass('active')
|
385
|
+
.filter("[data-size='#{size}']")
|
386
|
+
.addClass('active')
|
387
|
+
|
388
|
+
filters: ->
|
389
|
+
{}
|
390
|
+
|
391
|
+
close: ->
|
392
|
+
(@options.onClose || $.noop)()
|
393
|
+
|
394
|
+
@overlay.remove()
|
395
|
+
@modal.remove()
|
396
|
+
|
397
|
+
if @reload
|
398
|
+
$('body').trigger('infopark_reload')
|
399
|
+
|
400
|
+
open: (options) ->
|
401
|
+
$.ajax
|
402
|
+
url: '/resourcebrowser/modal'
|
403
|
+
dataType: 'json'
|
404
|
+
success: (json) =>
|
405
|
+
@options = options
|
406
|
+
|
407
|
+
@_loadModal(json.content)
|
408
|
+
@_setSelected()
|
409
|
+
@_loadFilter()
|
410
|
+
@_renderPlaceholder()
|
411
|
+
@_changeThumbnailSize()
|
412
|
+
|
413
|
+
ResourcebrowserInspector.init(@modal)
|
414
|
+
ResourcebrowserUploader.init(@modal)
|
415
|
+
|
416
|
+
ResourcebrowserUploader.onUploadFailure = (error) =>
|
417
|
+
console.error('Resourcebrowser Uploader Error:', error)
|
418
|
+
|
419
|
+
ResourcebrowserUploader.onUploadSuccess = (objs) =>
|
420
|
+
@_renderPlaceholder()
|
@@ -0,0 +1,132 @@
|
|
1
|
+
@ResourcebrowserUploader = do ->
|
2
|
+
dropZoneSelector: '.editing-resourcebrowser-items'
|
3
|
+
dropOverCssClass: 'uploader-drag-over'
|
4
|
+
mimeTypeMapping:
|
5
|
+
'image/*': 'Image'
|
6
|
+
'video/*': 'Video'
|
7
|
+
|
8
|
+
_initializeBindings: ->
|
9
|
+
dropZone = @modal.find(@dropZoneSelector)
|
10
|
+
|
11
|
+
dropZone.on 'dragover', (event) =>
|
12
|
+
$(event.currentTarget).addClass(@dropOverCssClass)
|
13
|
+
event.preventDefault()
|
14
|
+
|
15
|
+
dropZone.on 'dragleave', (event) =>
|
16
|
+
$(event.currentTarget).removeClass(@dropOverCssClass)
|
17
|
+
event.preventDefault()
|
18
|
+
|
19
|
+
dropZone.on 'drop', (event) =>
|
20
|
+
$(event.currentTarget).removeClass(@dropOverCssClass)
|
21
|
+
@_onDrop(event)
|
22
|
+
event.preventDefault()
|
23
|
+
|
24
|
+
_objClassForMimeType: (mimeType) ->
|
25
|
+
for mime, objClass of @mimeTypeMapping
|
26
|
+
return objClass if mimeType.match(mime)
|
27
|
+
|
28
|
+
undefined
|
29
|
+
|
30
|
+
_processQueue: (queue, createdObjs, promise) ->
|
31
|
+
promise.then (data) =>
|
32
|
+
@onUploadSuccess(data)
|
33
|
+
|
34
|
+
file = queue.pop()
|
35
|
+
|
36
|
+
if file?
|
37
|
+
@_createResource(file).then (obj) =>
|
38
|
+
@_updateProgress(file, '100%')
|
39
|
+
createdObjs.push(obj)
|
40
|
+
.always =>
|
41
|
+
@_processQueue(queue, createdObjs, promise)
|
42
|
+
|
43
|
+
return promise
|
44
|
+
else
|
45
|
+
return promise.resolve(createdObjs)
|
46
|
+
|
47
|
+
_addProgressWrapper: () ->
|
48
|
+
itemsElement = $('.editing-resourcebrowser-items').empty()
|
49
|
+
|
50
|
+
$('<div></div>')
|
51
|
+
.addClass('editing-resourcebrowser-loading')
|
52
|
+
.appendTo itemsElement
|
53
|
+
|
54
|
+
$('<div></div>')
|
55
|
+
.addClass('editing-resourcebrowser-progress-wrapper')
|
56
|
+
.appendTo itemsElement
|
57
|
+
|
58
|
+
_addProgress: (file) ->
|
59
|
+
progressBar = $('<div></div>')
|
60
|
+
.addClass('editing-resourcebrowser-progress-bar')
|
61
|
+
.css('width', '10%')
|
62
|
+
|
63
|
+
progress = $('<div></div>')
|
64
|
+
.addClass('editing-resourcebrowser-progress')
|
65
|
+
.html(progressBar)
|
66
|
+
|
67
|
+
fileName = $('<p></p>')
|
68
|
+
.html(file.name)
|
69
|
+
|
70
|
+
$('<div></div>')
|
71
|
+
.addClass('editing-resourcebrowser-progress-file')
|
72
|
+
.append(fileName)
|
73
|
+
.append(progress)
|
74
|
+
.prependTo $('.editing-resourcebrowser-progress-wrapper')
|
75
|
+
|
76
|
+
file['progressBar'] = progressBar
|
77
|
+
|
78
|
+
_updateProgress: (file, percent) ->
|
79
|
+
file.progressBar.css('width', percent)
|
80
|
+
|
81
|
+
_onDrop: (event) ->
|
82
|
+
dataTransfer = event.originalEvent.dataTransfer
|
83
|
+
|
84
|
+
unless dataTransfer?
|
85
|
+
return
|
86
|
+
|
87
|
+
files = dataTransfer.files
|
88
|
+
|
89
|
+
if files.length == 0
|
90
|
+
return
|
91
|
+
|
92
|
+
@onUploadStart(queue)
|
93
|
+
@_addProgressWrapper()
|
94
|
+
|
95
|
+
promise = $.Deferred()
|
96
|
+
|
97
|
+
queue = for file in files
|
98
|
+
@_addProgress(file)
|
99
|
+
file
|
100
|
+
|
101
|
+
@_processQueue(queue, [], promise)
|
102
|
+
|
103
|
+
promise
|
104
|
+
|
105
|
+
_randomResourceId: ->
|
106
|
+
hex = Math.floor(Math.random() * Math.pow(16, 8)).toString(16)
|
107
|
+
|
108
|
+
while (hex.length < 8)
|
109
|
+
hex = '0' + hex
|
110
|
+
|
111
|
+
hex
|
112
|
+
|
113
|
+
_createResource: (file) ->
|
114
|
+
objName = file.name.replace(/[^a-z0-9_.$\-]/ig, '-')
|
115
|
+
path = "_resources/#{@_randomResourceId()}/#{objName}"
|
116
|
+
|
117
|
+
scrivito.create_obj
|
118
|
+
blob: file
|
119
|
+
_path: path
|
120
|
+
_obj_class: @_objClassForMimeType(file.type)
|
121
|
+
|
122
|
+
init: (@modal) ->
|
123
|
+
@_initializeBindings()
|
124
|
+
|
125
|
+
# Hook for 3rd parties when the upload starts.
|
126
|
+
onUploadStart: (files) ->
|
127
|
+
|
128
|
+
# Hook for 3rd parties when the upload fails.
|
129
|
+
onUploadFailure: (error) ->
|
130
|
+
|
131
|
+
# Hook for 3rd parties when the upload was successful.
|
132
|
+
onUploadSuccess: (objs) ->
|
@@ -0,0 +1,13 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
+
// listed below.
|
3
|
+
//
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
+
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
|
6
|
+
//
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
+
// compiled file.
|
9
|
+
//
|
10
|
+
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
|
11
|
+
// about supported directives.
|
12
|
+
//
|
13
|
+
//= require_tree .
|