scrivito_editors 0.0.8
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 +7 -0
- data/CHANGELOG.md +48 -0
- data/LICENSE +4 -0
- data/README.md +55 -0
- data/Rakefile +9 -0
- data/app/assets/fonts/editing_icons-webfont.eot +0 -0
- data/app/assets/fonts/editing_icons-webfont.ttf +0 -0
- data/app/assets/fonts/editing_icons-webfont.woff +0 -0
- data/app/assets/javascripts/jquery_additions/jquery_center.js.coffee +6 -0
- data/app/assets/javascripts/mediabrowser/inspector.js.coffee +65 -0
- data/app/assets/javascripts/mediabrowser/mediabrowser.js.coffee +420 -0
- data/app/assets/javascripts/mediabrowser/uploader.js.coffee +132 -0
- data/app/assets/javascripts/scrivito_editors.js +18 -0
- data/app/assets/javascripts/scrivito_editors/date_editor.js.coffee +50 -0
- data/app/assets/javascripts/scrivito_editors/enum_editor.js.coffee +36 -0
- data/app/assets/javascripts/scrivito_editors/html_editor.js.coffee +140 -0
- data/app/assets/javascripts/scrivito_editors/linklist_editor.js.coffee +176 -0
- data/app/assets/javascripts/scrivito_editors/multienum_editor.js.coffee +37 -0
- data/app/assets/javascripts/scrivito_editors/placeholder.js.coffee +22 -0
- data/app/assets/javascripts/scrivito_editors/reference_editor.js.coffee +28 -0
- data/app/assets/javascripts/scrivito_editors/referencelist_editor.js.coffee +111 -0
- data/app/assets/javascripts/scrivito_editors/slider_editor.js.coffee +39 -0
- data/app/assets/javascripts/scrivito_editors/string_editor.js.coffee +83 -0
- data/app/assets/javascripts/scrivito_editors/text_editor.js.coffee +85 -0
- data/app/assets/stylesheets/scrivito_editors.css +16 -0
- data/app/assets/stylesheets/scrivito_editors/buttons.css +161 -0
- data/app/assets/stylesheets/scrivito_editors/editors/linklist_editor.css +105 -0
- data/app/assets/stylesheets/scrivito_editors/editors/referencelist_editor.css +67 -0
- data/app/assets/stylesheets/scrivito_editors/editors/text_editor.css +7 -0
- data/app/assets/stylesheets/scrivito_editors/icons.css.erb +229 -0
- data/app/assets/stylesheets/scrivito_editors/mediabrowser.css +1010 -0
- data/app/assets/stylesheets/scrivito_editors/placeholder.css +17 -0
- data/app/assets/stylesheets/scrivito_editors/widget_preview.css +38 -0
- data/app/controllers/scrivito_editors/mediabrowser_controller.rb +36 -0
- data/app/views/layouts/scrivito_editors/mediabrowser/inspector.html.erb +11 -0
- data/app/views/scrivito_editors/mediabrowser/_buttons.html.erb +16 -0
- data/app/views/scrivito_editors/mediabrowser/_header.html.erb +25 -0
- data/app/views/scrivito_editors/mediabrowser/modal.html.erb +12 -0
- data/app/views/scrivito_editors/obj/details.html +5 -0
- data/config/initializers/mediabrowser.rb +13 -0
- data/config/routes.rb +5 -0
- data/lib/scrivito_editors.rb +4 -0
- data/lib/scrivito_editors/engine.rb +7 -0
- data/lib/scrivito_editors/version.rb +3 -0
- data/spec/dummy/README.rdoc +28 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/assets/javascripts/application.js +13 -0
- data/spec/dummy/app/assets/stylesheets/application.css +13 -0
- data/spec/dummy/app/controllers/application_controller.rb +5 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/bin/bundle +3 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +23 -0
- data/spec/dummy/config/boot.rb +5 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +29 -0
- data/spec/dummy/config/environments/production.rb +80 -0
- data/spec/dummy/config/environments/test.rb +36 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +12 -0
- data/spec/dummy/config/initializers/session_store.rb +3 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +23 -0
- data/spec/dummy/config/routes.rb +4 -0
- data/spec/dummy/public/404.html +58 -0
- data/spec/dummy/public/422.html +58 -0
- data/spec/dummy/public/500.html +57 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/spec_helper.rb +13 -0
- data/vendor/assets/fonts/redactor-font.eot +0 -0
- data/vendor/assets/javascripts/jquery-ui-timepicker-addon.min.js +5 -0
- data/vendor/assets/javascripts/redactor.js +7869 -0
- data/vendor/assets/stylesheets/jquery-ui-timepicker-addon.min.css +5 -0
- data/vendor/assets/stylesheets/redactor.css.erb +968 -0
- metadata +240 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: cf1ebdd00044d7054e121007f00f33c8db2d49c5
|
4
|
+
data.tar.gz: daf06bd788bba66cad36195e3d03243f2bf51f3c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d9571c486b4a348b976259632dd20194eff1e8af0acb3cc12a29e30e844e5e60cac5930080b594183976e770f2daf23ca0c99f2329dcce958cd9e8fe38b2b8b3
|
7
|
+
data.tar.gz: f62413860d2790e1d6a9195b6dd653ff5ccd4a6207b96ba10d987562d6c05114d87ca197740024b18dcd3ba2494e1d0fd4aeac276bbb1ea7337389bc6785e412
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
# v0.0.8
|
2
|
+
* Use Twitter Bootstrap styling for enum and multienum select fields.
|
3
|
+
|
4
|
+
# v0.0.7
|
5
|
+
* Linklist and referencelist editors now better handle all aspects of the inplace editing process
|
6
|
+
for these two attributes. The "add" button no longer has to be rendered by the application code.
|
7
|
+
The styling of both editors was also improved to make it more user friendly.
|
8
|
+
* Mediabrowser: Thumbnails only display an image, if the object defines a `image?` method, that
|
9
|
+
returns `true`, otherwise a generic icon is rendered.
|
10
|
+
* Bugfix: The string and text editor now also save correctly, when highlighting and editing the
|
11
|
+
content without triggering a `click` event.
|
12
|
+
* Bugfix: The placeholder now also works for attributes, that have been cleared without triggering
|
13
|
+
a reload of the page afterwards. (Thanks @gertimon)
|
14
|
+
* Bugfix: The default placeholder text for empty CMS attributes only used the name of the first
|
15
|
+
attribute on the page, instead of the correct field name for each CMS attribute.
|
16
|
+
|
17
|
+
# v0.0.6
|
18
|
+
* Rewrite of string and text editor to better support pasting HTML, correctly handling quotes,
|
19
|
+
inserting the carrot at the correct position and better multiline support for preformatted text
|
20
|
+
fields. (Thanks @dcsaszar)
|
21
|
+
* Bugfix: Using renamed `obj_class_name` method from the new Scrivito SDK instead of `obj_class`.
|
22
|
+
* Changed the behavior when an item is clicked in the mediabrowser. Instead of opening the
|
23
|
+
inspector, the item is now selected or deselected. A small magnifying glass in the upper right
|
24
|
+
corner of the thumbnail now allows to open the inspector for the item.
|
25
|
+
* Rename the fallback inspector view to `details.html`, to be consistent to the new Scrivito SDK.
|
26
|
+
|
27
|
+
# v0.0.5
|
28
|
+
* The template used in the inspector is no longer configurable and always corresponds to the
|
29
|
+
details view used by the Scrivito SDK.
|
30
|
+
* Bugfix: The mediabrowser did not use a correct start index to render multiple thumbnails.
|
31
|
+
|
32
|
+
# v0.0.4
|
33
|
+
* Bugfix: Mediabrowser buttons now also work in Chrome browser.
|
34
|
+
|
35
|
+
# v0.0.3
|
36
|
+
* Updated redactor to version 9.2.1 and removed all custom settings.
|
37
|
+
* Added option `data-reload` to the string editor to configure if a reload event should
|
38
|
+
be triggered or not after saving the changes. (Thanks @apepper)
|
39
|
+
|
40
|
+
# v0.0.2
|
41
|
+
* Added placeholder text to empty CMS attributes.
|
42
|
+
|
43
|
+
# v0.0.1
|
44
|
+
* Updated html editor seperator height from 29px to 27px.
|
45
|
+
* Updated the README to describe the new gem.
|
46
|
+
* Added editing icons used in some of the editors and the media browser.
|
47
|
+
* Removed the saving animation for editors to not disturb the in-place editing
|
48
|
+
experience.
|
data/LICENSE
ADDED
data/README.md
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
# Scrivito Editors
|
2
|
+
|
3
|
+
[](http://badge.fury.io/rb/scrivito_editors)
|
4
|
+
[](https://codeclimate.com/github/infopark/scrivito_editors)
|
5
|
+
[](https://gemnasium.com/infopark/scrivito_editors)
|
6
|
+
[](https://travis-ci.org/infopark/scrivito_editors)
|
7
|
+
|
8
|
+
The [Scrivito](http://scrivito.com) Editors gem is a collection of useful standard
|
9
|
+
JavaScript editors based on the Scrivito SDK. The editors allow to edit all CMS
|
10
|
+
attributes in place and provide helper for the property view of pages and
|
11
|
+
widgets. A media browser is also part of the gem, to add, update and delete
|
12
|
+
resources.
|
13
|
+
|
14
|
+
## Installation and Usage
|
15
|
+
|
16
|
+
Please visit our Documentation to get the
|
17
|
+
[latest installation and usage information](https://scrivito.com/editors).
|
18
|
+
|
19
|
+
|
20
|
+
## Changelog
|
21
|
+
|
22
|
+
See [Changelog](https://github.com/infopark/scrivito_editors/blob/master/CHANGELOG.md) for more
|
23
|
+
details.
|
24
|
+
|
25
|
+
|
26
|
+
## Contributing
|
27
|
+
|
28
|
+
We would be very happy and thankful if you open new issues in order to further improve Scrivito
|
29
|
+
Editors. If you want to go a step further and extend the functionality or fix a problem, you can
|
30
|
+
do so any time by following the steps below.
|
31
|
+
|
32
|
+
1. Fork and clone the
|
33
|
+
[Scrivito Editors GitHub repository](https://github.com/infopark/scrivito_editors).
|
34
|
+
|
35
|
+
git clone git@github.com:_username_/scrivito_editors.git
|
36
|
+
cd scrivito_editors
|
37
|
+
|
38
|
+
2. We suggest using [rbenv](https://github.com/sstephenson/rbenv/) for managing your local Ruby
|
39
|
+
version. Make sure to use at least Ruby version 2.0.
|
40
|
+
|
41
|
+
ruby --version
|
42
|
+
|
43
|
+
3. Create your feature branch and create a pull request for the `develop` branch. Please take a
|
44
|
+
look at the already existing generators and rake tasks to get an impression of our coding style
|
45
|
+
and the general architecture.
|
46
|
+
|
47
|
+
4. We are using the [GitHub Styleguides](https://github.com/styleguide) and would prefer if you
|
48
|
+
could stick to it.
|
49
|
+
|
50
|
+
|
51
|
+
## License
|
52
|
+
Copyright (c) 2009 - 2014 Infopark AG (http://www.infopark.com)
|
53
|
+
|
54
|
+
This software can be used and modified under the LGPL-3.0. Please refer to
|
55
|
+
http://www.gnu.org/licenses/lgpl-3.0.html for the license text.
|
data/Rakefile
ADDED
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,65 @@
|
|
1
|
+
@MediabrowserInspector = do ->
|
2
|
+
inspectorSelector: '.editing-mediabrowser-inspector'
|
3
|
+
contentSelector: '.inspector-content'
|
4
|
+
inspector: undefined
|
5
|
+
objectId: undefined
|
6
|
+
|
7
|
+
_initializeBindings: ->
|
8
|
+
@modal.on 'click', 'li.mediabrowser-item', (event) =>
|
9
|
+
@_onInspect(event)
|
10
|
+
|
11
|
+
@inspector = @modal.find(@inspectorSelector)
|
12
|
+
@inspector.hide()
|
13
|
+
|
14
|
+
_onInspect: (event) ->
|
15
|
+
if $(event.target).hasClass('editing-mediabrowser-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-mediabrowser-loading')
|
32
|
+
.html(icon)
|
33
|
+
|
34
|
+
_highlightItem: (element) ->
|
35
|
+
@modal.find('li.mediabrowser-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 mediabrowser 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: '/mediabrowser/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 mediabrowser.
|
63
|
+
close: ->
|
64
|
+
@inspector.empty()
|
65
|
+
@inspector.hide()
|
@@ -0,0 +1,420 @@
|
|
1
|
+
@Mediabrowser = do ->
|
2
|
+
thumbnailViewButtonSelector: '.editing-button-view'
|
3
|
+
options: {}
|
4
|
+
|
5
|
+
# The media 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-mediabrowser-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-mediabrowser-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-mediabrowser-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('mediabrowser')
|
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.mediabrowser')
|
124
|
+
item.remove()
|
125
|
+
|
126
|
+
@_deselectAllItems()
|
127
|
+
|
128
|
+
_getItemId: (item) ->
|
129
|
+
$(item).closest('li.mediabrowser-item').data('id')
|
130
|
+
|
131
|
+
_getItemContainer: (id) ->
|
132
|
+
$('li.mediabrowser-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.mediabrowser-item .select-item.active').removeClass('active')
|
173
|
+
|
174
|
+
_getItems: ->
|
175
|
+
@modal.find('.editing-mediabrowser-items')
|
176
|
+
|
177
|
+
_getContainer: ->
|
178
|
+
@modal.find('.editing-mediabrowser-thumbnails')
|
179
|
+
|
180
|
+
_itemsPlaceholder: (count) ->
|
181
|
+
size = @_getThumbnailSize()
|
182
|
+
|
183
|
+
list = $('<ul></ul>')
|
184
|
+
.addClass('items editing-mediabrowser-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('mediabrowser-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.mediabrowser-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-mediabrowser-preview')
|
252
|
+
.appendTo(wrapper)
|
253
|
+
|
254
|
+
inspect = $('<span></span>')
|
255
|
+
.addClass('editing-mediabrowser-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-mediabrowser-meta')
|
270
|
+
.appendTo(wrapper)
|
271
|
+
|
272
|
+
title = $('<span></span>')
|
273
|
+
.addClass('editing-mediabrowser-thumbnails-name')
|
274
|
+
.html(title)
|
275
|
+
.appendTo(meta)
|
276
|
+
|
277
|
+
select = $('<span></span>')
|
278
|
+
.addClass('editing-mediabrowser-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-mediabrowser.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.mediabrowser-item', (event) =>
|
311
|
+
unless $(event.target).hasClass('editing-mediabrowser-inspect')
|
312
|
+
item = $(event.currentTarget).find('.select-item')
|
313
|
+
@_selectItem(item)
|
314
|
+
|
315
|
+
@modal.on 'click', '.mediabrowser-save', (event) =>
|
316
|
+
event.preventDefault()
|
317
|
+
@_save()
|
318
|
+
|
319
|
+
@modal.on 'click', '.mediabrowser-delete', (event) =>
|
320
|
+
event.preventDefault()
|
321
|
+
@_delete()
|
322
|
+
|
323
|
+
@modal.on 'click', '.mediabrowser-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.mediabrowser', (event) =>
|
336
|
+
@reload = true
|
337
|
+
|
338
|
+
$(document).on 'keyup.mediabrowser', (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.mediabrowser'
|
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-mediabrowser show')
|
356
|
+
.attr('id', 'editing-mediabrowser')
|
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-mediabrowser-loading')
|
369
|
+
.html(icon)
|
370
|
+
|
371
|
+
_changeThumbnailSize: (size) ->
|
372
|
+
size ||= @_getThumbnailSize()
|
373
|
+
@_setThumbnailSize(size)
|
374
|
+
|
375
|
+
transitionListener = 'webkitTransitionEnd.mediabrowser otransitionend.mediabrowser oTransitionEnd.mediabrowser msTransitionEnd.mediabrowser transitionend.mediabrowser'
|
376
|
+
@modal.on transitionListener, 'li.mediabrowser-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: '/mediabrowser/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
|
+
MediabrowserInspector.init(@modal)
|
414
|
+
MediabrowserUploader.init(@modal)
|
415
|
+
|
416
|
+
MediabrowserUploader.onUploadFailure = (error) =>
|
417
|
+
console.error('Mediabrowser Uploader Error:', error)
|
418
|
+
|
419
|
+
MediabrowserUploader.onUploadSuccess = (objs) =>
|
420
|
+
@_renderPlaceholder()
|