scrivito_content_browser 0.1.0
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 +41 -0
- data/LICENSE +4 -0
- data/README.md +36 -0
- data/Rakefile +4 -0
- data/app/assets/javascripts/scrivito_content_browser/content_browser.js.coffee +527 -0
- data/app/assets/javascripts/scrivito_content_browser/deprecation_warnings.js.coffee +22 -0
- data/app/assets/javascripts/scrivito_content_browser/inspector.js.coffee +67 -0
- data/app/assets/javascripts/scrivito_content_browser/uploader.js.coffee +148 -0
- data/app/assets/javascripts/scrivito_content_browser.js +13 -0
- data/app/assets/stylesheets/scrivito_content_browser/content_browser.css +1095 -0
- data/app/assets/stylesheets/scrivito_content_browser/icons.css.erb +82 -0
- data/app/assets/stylesheets/scrivito_content_browser.css +12 -0
- data/app/controllers/scrivito_content_browser/content_browser_controller.rb +31 -0
- data/app/views/layouts/scrivito_content_browser/inspector.html.erb +11 -0
- data/app/views/scrivito_content_browser/obj/details.html +7 -0
- data/config/initializers/scrivito_content_browser.rb +13 -0
- data/config/routes.rb +3 -0
- data/lib/scrivito_content_browser/engine.rb +4 -0
- data/lib/scrivito_content_browser/version.rb +3 -0
- data/lib/scrivito_content_browser.rb +4 -0
- metadata +135 -0
@@ -0,0 +1,67 @@
|
|
1
|
+
return if !scrivito?
|
2
|
+
|
3
|
+
scrivito.content_browser._inspector = do ->
|
4
|
+
inspectorSelector: '.scrivito-content-browser-inspector'
|
5
|
+
contentSelector: '.inspector-content'
|
6
|
+
inspector: undefined
|
7
|
+
objectId: undefined
|
8
|
+
|
9
|
+
_initializeBindings: ->
|
10
|
+
@modal.on 'click', 'li.content-browser-item', (event) =>
|
11
|
+
@_onInspect(event)
|
12
|
+
|
13
|
+
@inspector = @modal.find(@inspectorSelector)
|
14
|
+
@inspector.hide()
|
15
|
+
|
16
|
+
_onInspect: (event) ->
|
17
|
+
if $(event.target).hasClass('scrivito-content-browser-inspect')
|
18
|
+
currentTarget = $(event.currentTarget)
|
19
|
+
id = currentTarget.data('id')
|
20
|
+
|
21
|
+
if id
|
22
|
+
@open(id)
|
23
|
+
@_highlightItem(currentTarget)
|
24
|
+
|
25
|
+
_renderLoading: ->
|
26
|
+
@inspector.html(@_loadingTemplate())
|
27
|
+
|
28
|
+
_loadingTemplate: ->
|
29
|
+
icon = $('<i></i>')
|
30
|
+
.addClass('scrivito-content-browser-icon scrivito-content-browser-icon-refresh')
|
31
|
+
|
32
|
+
$('<div></div>')
|
33
|
+
.addClass('scrivito-content-browser-loading')
|
34
|
+
.html(icon)
|
35
|
+
|
36
|
+
_highlightItem: (element) ->
|
37
|
+
@modal.find('li.content-browser-item.active').removeClass('active')
|
38
|
+
element.addClass('active')
|
39
|
+
|
40
|
+
init: (modal) ->
|
41
|
+
@modal = modal
|
42
|
+
@_initializeBindings()
|
43
|
+
|
44
|
+
# Opens the inspector section in the content browser for the given object ID and displays its edit
|
45
|
+
# view.
|
46
|
+
open: (objectId) ->
|
47
|
+
@objectId = objectId
|
48
|
+
|
49
|
+
@inspector.show()
|
50
|
+
@_renderLoading()
|
51
|
+
|
52
|
+
$.ajax
|
53
|
+
url: '/scrivito_content_browser/inspector'
|
54
|
+
dataType: 'json'
|
55
|
+
data:
|
56
|
+
id: @objectId
|
57
|
+
success: (json) =>
|
58
|
+
@inspector.html(json.content)
|
59
|
+
scrivito.trigger('new_content', @inspector)
|
60
|
+
|
61
|
+
error: =>
|
62
|
+
@inspector.empty()
|
63
|
+
|
64
|
+
# Closes the inspector section of the content browser.
|
65
|
+
close: ->
|
66
|
+
@inspector.empty()
|
67
|
+
@inspector.hide()
|
@@ -0,0 +1,148 @@
|
|
1
|
+
return if !scrivito?
|
2
|
+
|
3
|
+
scrivito.content_browser._uploader = do ->
|
4
|
+
dropZoneSelector: '.scrivito-content-browser-items'
|
5
|
+
dropOverCssClass: 'uploader-drag-over'
|
6
|
+
|
7
|
+
_initializeBindings: ->
|
8
|
+
dropZone = @modal.find(@dropZoneSelector)
|
9
|
+
|
10
|
+
dropZone.on 'dragover', (event) =>
|
11
|
+
$(event.currentTarget).addClass(@dropOverCssClass)
|
12
|
+
event.preventDefault()
|
13
|
+
|
14
|
+
dropZone.on 'dragleave', (event) =>
|
15
|
+
$(event.currentTarget).removeClass(@dropOverCssClass)
|
16
|
+
event.preventDefault()
|
17
|
+
|
18
|
+
dropZone.on 'drop', (event) =>
|
19
|
+
$(event.currentTarget).removeClass(@dropOverCssClass)
|
20
|
+
@_onDrop(event)
|
21
|
+
event.preventDefault()
|
22
|
+
|
23
|
+
_objClassForMimeType: (mimeType) ->
|
24
|
+
for mime, objClass of scrivito.content_browser.filter_defaults.upload
|
25
|
+
return objClass if mimeType.match(mime)
|
26
|
+
|
27
|
+
undefined
|
28
|
+
|
29
|
+
_processQueue: (queue, createdObjs, failedUploads, promise) ->
|
30
|
+
file = queue.pop()
|
31
|
+
|
32
|
+
if file?
|
33
|
+
@_createResource(file)
|
34
|
+
.done (obj) =>
|
35
|
+
@_updateProgress(file, '100%')
|
36
|
+
createdObjs.push(obj)
|
37
|
+
@_processQueue(queue, createdObjs, failedUploads, promise)
|
38
|
+
.fail (args) =>
|
39
|
+
@_updateError(file, args.message || "Upload failed. Please check your network connection.")
|
40
|
+
@_updateProgress(file, '0%')
|
41
|
+
failedUploads.push(args)
|
42
|
+
@_processQueue(queue, createdObjs, failedUploads, promise)
|
43
|
+
else
|
44
|
+
return promise.resolve(createdObjs, failedUploads)
|
45
|
+
|
46
|
+
_addProgressWrapper: () ->
|
47
|
+
itemsElement = $('.scrivito-content-browser-items').empty()
|
48
|
+
|
49
|
+
$('<div></div>')
|
50
|
+
.addClass('scrivito-content-browser-loading')
|
51
|
+
.appendTo itemsElement
|
52
|
+
|
53
|
+
$('<div></div>')
|
54
|
+
.addClass('scrivito-content-browser-progress-wrapper')
|
55
|
+
.appendTo itemsElement
|
56
|
+
|
57
|
+
_addProgress: (file) ->
|
58
|
+
progressBar = $('<div></div>')
|
59
|
+
.addClass('scrivito-content-browser-progress-bar')
|
60
|
+
.css('width', '10%')
|
61
|
+
|
62
|
+
progress = $('<div></div>')
|
63
|
+
.addClass('scrivito-content-browser-progress')
|
64
|
+
.html(progressBar)
|
65
|
+
|
66
|
+
fileName = $('<p></p>')
|
67
|
+
.html(file.name)
|
68
|
+
|
69
|
+
error = $('<p></p>')
|
70
|
+
.addClass('scrivito-content-browser-error')
|
71
|
+
|
72
|
+
$('<div></div>')
|
73
|
+
.addClass('scrivito-content-browser-progress-file')
|
74
|
+
.append(fileName)
|
75
|
+
.append(error)
|
76
|
+
.append(progress)
|
77
|
+
.prependTo $('.scrivito-content-browser-progress-wrapper')
|
78
|
+
|
79
|
+
file.progressBar = progressBar
|
80
|
+
file.error = error
|
81
|
+
|
82
|
+
_updateProgress: (file, percent) ->
|
83
|
+
file.progressBar.css('width', percent)
|
84
|
+
|
85
|
+
_updateError: (file, message) ->
|
86
|
+
file.error.text(message)
|
87
|
+
|
88
|
+
_onDrop: (event) ->
|
89
|
+
dataTransfer = event.originalEvent.dataTransfer
|
90
|
+
|
91
|
+
unless dataTransfer?
|
92
|
+
return
|
93
|
+
|
94
|
+
files = dataTransfer.files
|
95
|
+
|
96
|
+
if files.length == 0
|
97
|
+
return
|
98
|
+
|
99
|
+
@_addProgressWrapper()
|
100
|
+
|
101
|
+
queue = for file in files
|
102
|
+
@_addProgress(file)
|
103
|
+
file
|
104
|
+
|
105
|
+
@onUploadStart(queue)
|
106
|
+
promise = $.Deferred()
|
107
|
+
.done (createdObjs, failedUploads) =>
|
108
|
+
@onUploadFailure(failedUploads) if failedUploads.length > 0
|
109
|
+
@onUploadSuccess(createdObjs) if createdObjs.length > 0
|
110
|
+
|
111
|
+
@_processQueue(queue, [], [], promise)
|
112
|
+
promise
|
113
|
+
|
114
|
+
_randomResourceId: ->
|
115
|
+
hex = Math.floor(Math.random() * Math.pow(16, 8)).toString(16)
|
116
|
+
|
117
|
+
while (hex.length < 8)
|
118
|
+
hex = '0' + hex
|
119
|
+
|
120
|
+
hex
|
121
|
+
|
122
|
+
_createResource: (file) ->
|
123
|
+
objName = file.name.replace(/[^a-z0-9_.$\-]/ig, '-')
|
124
|
+
path = "_resources/#{@_randomResourceId()}/#{objName}"
|
125
|
+
objClass = @_objClassForMimeType(file.type)
|
126
|
+
|
127
|
+
if objClass
|
128
|
+
scrivito.create_obj
|
129
|
+
blob: file
|
130
|
+
_path: path
|
131
|
+
_obj_class: objClass
|
132
|
+
else
|
133
|
+
$.Deferred().reject
|
134
|
+
id: "no_obj_class_for_mime_type"
|
135
|
+
file_name: file.name
|
136
|
+
message: "File type #{file.type} rejected by resource configuration."
|
137
|
+
|
138
|
+
init: (@modal) ->
|
139
|
+
@_initializeBindings()
|
140
|
+
|
141
|
+
# Hook for 3rd parties when the upload starts.
|
142
|
+
onUploadStart: (files) ->
|
143
|
+
|
144
|
+
# Hook for 3rd parties when the upload fails.
|
145
|
+
onUploadFailure: (errors) ->
|
146
|
+
|
147
|
+
# Hook for 3rd parties when the upload was successful.
|
148
|
+
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 .
|