comfortable_mexican_sofa 2.0.12 → 2.0.13

Sign up to get free protection for your applications and to get access to all the features.
Files changed (146) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +1 -1
  3. data/.travis.yml +5 -2
  4. data/Gemfile +5 -0
  5. data/Rakefile +2 -0
  6. data/app/assets/javascripts/comfy/admin/cms/application.js +40 -0
  7. data/app/assets/javascripts/comfy/admin/cms/base.js +46 -0
  8. data/app/assets/javascripts/comfy/admin/cms/categories.js +17 -0
  9. data/app/assets/javascripts/comfy/admin/cms/codemirror.js +31 -0
  10. data/app/assets/javascripts/comfy/admin/cms/custom.js +1 -0
  11. data/app/assets/javascripts/comfy/admin/cms/diff.js +10 -0
  12. data/app/assets/javascripts/comfy/admin/cms/file_link.js +67 -0
  13. data/app/assets/javascripts/comfy/admin/cms/file_upload.js +194 -0
  14. data/app/assets/javascripts/comfy/admin/cms/files_modal.js +40 -0
  15. data/app/assets/javascripts/comfy/admin/cms/page_fragments.js +22 -0
  16. data/app/assets/javascripts/comfy/admin/cms/slugify.js +34 -0
  17. data/app/assets/javascripts/comfy/admin/cms/sortable_list.js +40 -0
  18. data/app/assets/javascripts/comfy/admin/cms/timepicker.js +30 -0
  19. data/app/assets/javascripts/comfy/admin/cms/wysiwyg.js +65 -0
  20. data/app/assets/javascripts/comfy/vendor/redactor.js +12 -6
  21. data/app/assets/stylesheets/comfy/admin/cms/base.sass +32 -35
  22. data/app/controllers/application_controller.rb +2 -0
  23. data/app/controllers/comfy/admin/base_controller.rb +3 -1
  24. data/app/controllers/comfy/admin/cms/base_controller.rb +9 -1
  25. data/app/controllers/comfy/admin/cms/categories_controller.rb +2 -0
  26. data/app/controllers/comfy/admin/cms/files_controller.rb +3 -1
  27. data/app/controllers/comfy/admin/cms/layouts_controller.rb +2 -0
  28. data/app/controllers/comfy/admin/cms/pages_controller.rb +4 -1
  29. data/app/controllers/comfy/admin/cms/revisions/base_controller.rb +2 -0
  30. data/app/controllers/comfy/admin/cms/revisions/layout_controller.rb +2 -0
  31. data/app/controllers/comfy/admin/cms/revisions/page_controller.rb +2 -0
  32. data/app/controllers/comfy/admin/cms/revisions/snippet_controller.rb +2 -0
  33. data/app/controllers/comfy/admin/cms/revisions/translation_controller.rb +2 -0
  34. data/app/controllers/comfy/admin/cms/sites_controller.rb +2 -0
  35. data/app/controllers/comfy/admin/cms/snippets_controller.rb +2 -0
  36. data/app/controllers/comfy/admin/cms/translations_controller.rb +8 -0
  37. data/app/controllers/comfy/cms/assets_controller.rb +2 -0
  38. data/app/controllers/comfy/cms/base_controller.rb +4 -2
  39. data/app/controllers/comfy/cms/content_controller.rb +3 -1
  40. data/app/controllers/concerns/comfy/paginate.rb +2 -0
  41. data/app/controllers/concerns/comfy/reorder_action.rb +2 -0
  42. data/app/helpers/comfy/admin/cms_helper.rb +19 -0
  43. data/app/helpers/comfy/cms_helper.rb +4 -2
  44. data/app/models/comfy/cms/categorization.rb +2 -0
  45. data/app/models/comfy/cms/category.rb +2 -0
  46. data/app/models/comfy/cms/file.rb +2 -0
  47. data/app/models/comfy/cms/fragment.rb +3 -1
  48. data/app/models/comfy/cms/layout.rb +3 -1
  49. data/app/models/comfy/cms/page.rb +3 -1
  50. data/app/models/comfy/cms/revision.rb +2 -0
  51. data/app/models/comfy/cms/site.rb +5 -1
  52. data/app/models/comfy/cms/snippet.rb +2 -0
  53. data/app/models/comfy/cms/translation.rb +2 -0
  54. data/app/models/concerns/comfy/cms/with_categories.rb +2 -0
  55. data/app/models/concerns/comfy/cms/with_fragments.rb +2 -0
  56. data/app/views/comfy/admin/cms/categories/_index.html.haml +3 -3
  57. data/app/views/comfy/admin/cms/categories/create.js.erb +1 -1
  58. data/app/views/comfy/admin/cms/categories/destroy.js.erb +8 -3
  59. data/app/views/comfy/admin/cms/files/_file.html.haml +9 -10
  60. data/app/views/comfy/admin/cms/files/_modal.html.haml +1 -2
  61. data/app/views/comfy/admin/cms/files/destroy.js.erb +4 -0
  62. data/app/views/comfy/admin/cms/files/index.html.haml +10 -10
  63. data/app/views/comfy/admin/cms/fragments/_form_fragment_attachments.html.haml +15 -6
  64. data/app/views/comfy/admin/cms/fragments/_form_fragments.html.haml +17 -21
  65. data/app/views/comfy/admin/cms/pages/_form.html.haml +3 -2
  66. data/app/views/comfy/admin/cms/pages/toggle_branch.js.erb +3 -1
  67. data/app/views/comfy/admin/cms/translations/_form.html.haml +3 -2
  68. data/app/views/layouts/comfy/admin/cms.html.haml +0 -1
  69. data/app/views/layouts/comfy/admin/cms/_body.html.haml +1 -0
  70. data/app/views/layouts/comfy/admin/cms/_left.html.haml +1 -1
  71. data/comfortable_mexican_sofa.gemspec +3 -2
  72. data/config.ru +2 -0
  73. data/config/application.rb +2 -0
  74. data/config/boot.rb +2 -0
  75. data/config/cms_routes.rb +2 -0
  76. data/config/environment.rb +2 -0
  77. data/config/environments/development.rb +2 -0
  78. data/config/environments/test.rb +2 -0
  79. data/config/initializers/comfortable_mexican_sofa.rb +2 -0
  80. data/lib/comfortable_mexican_sofa.rb +2 -0
  81. data/lib/comfortable_mexican_sofa/access_control/admin_authentication.rb +2 -0
  82. data/lib/comfortable_mexican_sofa/access_control/admin_authorization.rb +2 -0
  83. data/lib/comfortable_mexican_sofa/access_control/public_authentication.rb +2 -0
  84. data/lib/comfortable_mexican_sofa/access_control/public_authorization.rb +2 -0
  85. data/lib/comfortable_mexican_sofa/configuration.rb +3 -0
  86. data/lib/comfortable_mexican_sofa/content.rb +3 -0
  87. data/lib/comfortable_mexican_sofa/content/block.rb +2 -0
  88. data/lib/comfortable_mexican_sofa/content/params_parser.rb +59 -41
  89. data/lib/comfortable_mexican_sofa/content/renderer.rb +18 -4
  90. data/lib/comfortable_mexican_sofa/content/tag.rb +20 -5
  91. data/lib/comfortable_mexican_sofa/content/tags/asset.rb +2 -0
  92. data/lib/comfortable_mexican_sofa/content/tags/checkbox.rb +10 -3
  93. data/lib/comfortable_mexican_sofa/content/tags/date.rb +3 -1
  94. data/lib/comfortable_mexican_sofa/content/tags/datetime.rb +3 -1
  95. data/lib/comfortable_mexican_sofa/content/tags/file.rb +21 -27
  96. data/lib/comfortable_mexican_sofa/content/tags/file_link.rb +23 -24
  97. data/lib/comfortable_mexican_sofa/content/tags/files.rb +11 -9
  98. data/lib/comfortable_mexican_sofa/content/tags/fragment.rb +11 -1
  99. data/lib/comfortable_mexican_sofa/content/tags/helper.rb +3 -1
  100. data/lib/comfortable_mexican_sofa/content/tags/markdown.rb +3 -1
  101. data/lib/comfortable_mexican_sofa/content/tags/mixins/file_content.rb +38 -0
  102. data/lib/comfortable_mexican_sofa/content/tags/number.rb +3 -1
  103. data/lib/comfortable_mexican_sofa/content/tags/page_file_link.rb +82 -0
  104. data/lib/comfortable_mexican_sofa/content/tags/partial.rb +3 -1
  105. data/lib/comfortable_mexican_sofa/content/tags/snippet.rb +2 -0
  106. data/lib/comfortable_mexican_sofa/content/tags/template.rb +3 -1
  107. data/lib/comfortable_mexican_sofa/content/tags/text.rb +3 -1
  108. data/lib/comfortable_mexican_sofa/content/tags/textarea.rb +3 -1
  109. data/lib/comfortable_mexican_sofa/content/tags/wysiwyg.rb +3 -1
  110. data/lib/comfortable_mexican_sofa/engine.rb +2 -1
  111. data/lib/comfortable_mexican_sofa/error.rb +2 -0
  112. data/lib/comfortable_mexican_sofa/extensions/acts_as_tree.rb +2 -0
  113. data/lib/comfortable_mexican_sofa/extensions/has_revisions.rb +2 -0
  114. data/lib/comfortable_mexican_sofa/form_builder.rb +24 -17
  115. data/lib/comfortable_mexican_sofa/render_methods.rb +2 -0
  116. data/lib/comfortable_mexican_sofa/routes/cms.rb +2 -0
  117. data/lib/comfortable_mexican_sofa/routes/cms_admin.rb +2 -0
  118. data/lib/comfortable_mexican_sofa/routing.rb +2 -0
  119. data/lib/comfortable_mexican_sofa/seeds.rb +3 -1
  120. data/lib/comfortable_mexican_sofa/seeds/file/exporter.rb +2 -0
  121. data/lib/comfortable_mexican_sofa/seeds/file/importer.rb +2 -0
  122. data/lib/comfortable_mexican_sofa/seeds/layout/exporter.rb +2 -0
  123. data/lib/comfortable_mexican_sofa/seeds/layout/importer.rb +2 -0
  124. data/lib/comfortable_mexican_sofa/seeds/page/exporter.rb +2 -0
  125. data/lib/comfortable_mexican_sofa/seeds/page/importer.rb +2 -0
  126. data/lib/comfortable_mexican_sofa/seeds/snippet/exporter.rb +2 -0
  127. data/lib/comfortable_mexican_sofa/seeds/snippet/importer.rb +2 -0
  128. data/lib/comfortable_mexican_sofa/version.rb +3 -1
  129. data/lib/comfortable_mexican_sofa/view_hooks.rb +2 -0
  130. data/lib/generators/comfy/cms/assets_generator.rb +2 -0
  131. data/lib/generators/comfy/cms/cms_generator.rb +6 -4
  132. data/lib/generators/comfy/cms/controllers_generator.rb +2 -0
  133. data/lib/generators/comfy/cms/models_generator.rb +2 -0
  134. data/lib/generators/comfy/cms/views_generator.rb +2 -0
  135. data/lib/generators/comfy/scaffold/scaffold_generator.rb +6 -2
  136. data/lib/tasks/cms_seeds.rake +2 -0
  137. metadata +20 -26
  138. data/app/assets/javascripts/comfy/admin/cms/application.js.coffee +0 -30
  139. data/app/assets/javascripts/comfy/admin/cms/base.js.coffee +0 -224
  140. data/app/assets/javascripts/comfy/admin/cms/custom.js.coffee +0 -1
  141. data/app/assets/javascripts/comfy/admin/cms/files.js.coffee +0 -29
  142. data/app/assets/javascripts/comfy/admin/cms/uploader.js.coffee +0 -140
  143. data/app/views/comfy/admin/cms/files/create.js.erb +0 -1
  144. data/app/views/comfy/admin/cms/files/destroy.js.coffee +0 -2
  145. data/app/views/comfy/admin/cms/pages/form_fragments.js.erb +0 -1
  146. data/app/views/comfy/admin/cms/translations/form_fragments.js.erb +0 -1
@@ -1,30 +0,0 @@
1
- #= require rails-ujs
2
- #= require jquery3
3
-
4
- #= require comfy/vendor/codemirror
5
- #= require comfy/vendor/codemirror/mode/css/css
6
- #= require comfy/vendor/codemirror/mode/htmlmixed/htmlmixed
7
- #= require comfy/vendor/codemirror/mode/javascript/javascript
8
- #= require comfy/vendor/codemirror/mode/markdown/markdown
9
- #= require comfy/vendor/codemirror/mode/xml/xml
10
- #= require comfy/vendor/codemirror/addon/edit/closetag
11
- #= require comfy/vendor/sortable.min
12
- #= require comfy/vendor/popper.min
13
- #= require comfy/vendor/bootstrap.min
14
- #= require comfy/vendor/diff/diff_match_patch.min
15
- #= require comfy/vendor/diff/pretty_text_diff
16
- #= require comfy/vendor/fontawesome
17
- #= require comfy/vendor/redactor
18
- #= require comfy/vendor/redactor/filemanager
19
- #= require comfy/vendor/redactor/imagemanager
20
- #= require comfy/vendor/redactor/definedlinks
21
- #= require comfy/vendor/redactor/table
22
- #= require comfy/vendor/redactor/video
23
- #= require_directory ../../vendor/redactor/i18n/
24
- #= require comfy/vendor/flatpickr.min
25
- #= require_directory ../../vendor/flatpickr/i18n/
26
-
27
- #= require comfy/admin/cms/base
28
- #= require comfy/admin/cms/uploader
29
- #= require comfy/admin/cms/files
30
- #= require comfy/admin/cms/custom
@@ -1,224 +0,0 @@
1
- window.CMS ||= {}
2
-
3
- window.CMS.code_mirror_instances = [ ]
4
-
5
- unless Turbolinks?.controller? # Turbolinks 5 verification
6
- $ -> window.CMS.init()
7
-
8
- $(document).on 'page:load turbolinks:load', -> window.CMS.init()
9
-
10
- window.CMS.init = ->
11
- window.CMS.current_path = window.location.pathname
12
- CMS.set_iframe_layout()
13
- CMS.slugify()
14
- CMS.wysiwyg()
15
- CMS.codemirror()
16
- CMS.sortable_list()
17
- CMS.timepicker()
18
- CMS.page_fragments()
19
- CMS.page_file_popovers()
20
- CMS.page_update_preview()
21
- CMS.categories()
22
- CMS.files()
23
- CMS.upload_queue()
24
- CMS.diff()
25
-
26
-
27
- window.CMS.upload_queue = ->
28
- if $("#cms-uploader").length
29
- uploader_url = $("meta[name='cms-uploader-url']").attr("content")
30
- token_name = $("meta[name='cms-uploader-token-name']").attr("content")
31
- token_value = $("meta[name='cms-uploader-token-value']").attr("content")
32
- session_name = $("meta[name='cms-uploader-session-name']").attr("content")
33
- session_value = $("meta[name='cms-uploader-session-value']").attr("content")
34
-
35
- window.CMS.uploader $("#cms-uploader"),
36
- url: uploader_url,
37
- multipart_params:
38
- "#{token_name}": token_value,
39
- "#{session_name}": session_value
40
-
41
-
42
- window.CMS.slugify = ->
43
- slugify = (str) ->
44
- # Trim string and lower case.
45
- str = str.replace(/^\s+|\s+$/g, '').toLowerCase()
46
-
47
- # Replace special chars.
48
- replacements = [
49
- ['à', 'a'],
50
- ['á', 'a'],
51
- ['ä', 'ae'],
52
- ['â', 'a'],
53
- ['ã', 'a'],
54
- ['è', 'e'],
55
- ['é', 'e'],
56
- ['ë', 'e'],
57
- ['ê', 'e'],
58
- ['ì', 'i'],
59
- ['í', 'i'],
60
- ['ï', 'i'],
61
- ['î', 'i'],
62
- ['ò', 'o'],
63
- ['ó', 'o'],
64
- ['ö', 'oe'],
65
- ['ô', 'o'],
66
- ['õ', 'o'],
67
- ['ù', 'u'],
68
- ['ú', 'u'],
69
- ['ü', 'ue'],
70
- ['û', 'u'],
71
- ['ñ', 'n'],
72
- ['ç', 'c'],
73
- ['ß', 'ss'],
74
- ['·', '-'],
75
- ['/', '-'],
76
- [',', '-'],
77
- [':', '-'],
78
- [';', '-'],
79
- ['_', '-'],
80
- [' ', '-'],
81
- ]
82
-
83
- for replacement in replacements
84
- str = str.replace(new RegExp(replacement[0], 'g'), replacement[1])
85
-
86
- # Remove any other URL incompatible characters and replace multiple dashes with just a single one.
87
- str = str.replace(/[^a-z0-9-]/g, '').replace(/-+/g, '-')
88
-
89
- $('input[data-slugify=true]').bind 'keyup.cms', ->
90
- $('input[data-slug=true]').val(slugify($(this).val()))
91
-
92
-
93
- window.CMS.wysiwyg = ->
94
- csrf_token = $('meta[name=csrf-token]').attr('content')
95
- csrf_param = $('meta[name=csrf-param]').attr('content')
96
-
97
- if (csrf_param != undefined && csrf_token != undefined)
98
- params = csrf_param + "=" + encodeURIComponent(csrf_token)
99
-
100
- file_upload_path = $("meta[name='cms-file-upload-path']").attr("content")
101
- pages_path = $("meta[name='cms-pages-path']").attr("content")
102
-
103
- $('textarea.rich-text-editor, textarea[data-cms-rich-text]').redactor
104
- minHeight: 160
105
- autoresize: true
106
- imageUpload: "#{file_upload_path}?source=redactor&type=image&#{params}"
107
- imageManagerJson: "#{file_upload_path}?source=redactor&type=image"
108
- fileUpload: "#{file_upload_path}?source=redactor&type=file&#{params}"
109
- fileManagerJson: "#{file_upload_path}?source=redactor&type=file"
110
- definedLinks: "#{pages_path}?source=redactor"
111
- buttonSource: true
112
- formatting: ['p', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6']
113
- plugins: ['imagemanager', 'filemanager', 'table', 'video', 'definedlinks']
114
- lang: $("meta[name='cms-locale']").attr("content")
115
- convertDivs: false
116
-
117
-
118
- window.CMS.codemirror = ->
119
- $('textarea[data-cms-cm-mode]').each (i, element) ->
120
- cm = CodeMirror.fromTextArea element,
121
- mode: $(element).data('cms-cm-mode')
122
- tabSize: 2
123
- lineWrapping: true
124
- autoCloseTags: true
125
- lineNumbers: true
126
- viewportMargin: Infinity
127
-
128
- CMS.code_mirror_instances.push(cm)
129
-
130
- $('a[data-toggle="tab"]').on 'shown.bs.tab', ->
131
- for cm in CMS.code_mirror_instances
132
- cm.refresh()
133
-
134
-
135
- window.CMS.sortable_list = ->
136
- dataIdAttr = 'data-id'
137
- sortableStore =
138
- get: (sortable) ->
139
- Array::map.call sortable.el.children, (el) -> el.getAttribute(dataIdAttr)
140
- set: (sortable) ->
141
- $.ajax
142
- url: "#{CMS.current_path}/reorder"
143
- type: 'POST'
144
- dataType: 'json'
145
- data:
146
- order: sortable.toArray()
147
- _method: 'PUT'
148
-
149
- for root in document.querySelectorAll('.sortable')
150
- Sortable.create root,
151
- handle: '.dragger'
152
- draggable: 'li'
153
- dataIdAttr: dataIdAttr
154
- store: sortableStore
155
- onStart: (evt) -> evt.from.classList.add('sortable-active')
156
- onEnd: (evt) -> evt.from.classList.remove('sortable-active')
157
-
158
-
159
- window.CMS.timepicker = ->
160
- $('input[type=text][data-cms-datetime]').flatpickr
161
- format: 'yyyy-mm-dd hh:ii'
162
- enableTime: true
163
- locale: $("meta[name='cms-locale']").attr("content")
164
-
165
- $('input[type=text][data-cms-date]').flatpickr
166
- format: 'yyyy-mm-dd',
167
- locale: $("meta[name='cms-locale']").attr("content")
168
-
169
-
170
- window.CMS.page_fragments = ->
171
- $('select#fragments-toggle').bind 'change.cms', ->
172
- $.ajax
173
- url: $(this).data('url'),
174
- data:
175
- layout_id: $(this).val()
176
- complete: ->
177
- CMS.wysiwyg()
178
- CMS.timepicker()
179
- CMS.codemirror()
180
- CMS.page_file_popovers()
181
-
182
-
183
- window.CMS.page_file_popovers = ->
184
- $('[data-toggle="page-file-popover"]').popover
185
- trigger: 'hover'
186
- placement: 'top'
187
- html: true
188
-
189
-
190
- window.CMS.page_update_preview = ->
191
- $('input[name=commit]').click ->
192
- $(this).parents('form').attr('target', '')
193
- $('input[name=preview]').click ->
194
- $(this).parents('form').attr('target', 'comfy-cms-preview')
195
-
196
-
197
- window.CMS.categories = ->
198
- $('button.toggle-cat-edit', '.categories-widget').click (event) ->
199
- event.preventDefault()
200
- $('.read', '.categories-widget').toggle()
201
- $('.editable', '.categories-widget').toggle()
202
- $('.edit', '.categories-widget').toggle()
203
- $('.done', '.categories-widget').toggle()
204
-
205
-
206
- window.CMS.diff = ->
207
- $(".revision").prettyTextDiff
208
- cleanup: true
209
- originalContainer: '.original'
210
- changedContainer: '.current'
211
- diffContainer: '.diff .content'
212
-
213
- # If we are inside an iframe remove the columns and just keep the center column content.
214
- # This is used for the files widget that opens in a modal window.
215
- window.CMS.set_iframe_layout = ->
216
- in_iframe = ->
217
- try
218
- return window.self != window.top
219
- catch e
220
- return true
221
-
222
- $('body').ready ->
223
- if in_iframe()
224
- $('body').addClass('in-iframe')
@@ -1 +0,0 @@
1
- # Custom JS for the admin area
@@ -1,29 +0,0 @@
1
- (($) ->
2
- window.CMS or (window.CMS = {})
3
- window.CMS.files = ->
4
- modal = $('.cms-files-modal')
5
- $('.cms-files-open-modal').on 'click', (e) ->
6
- modal.on 'show.bs.modal', ->
7
- iframe = modal.find('iframe')
8
- iframeSrc = modal.data('iframe-src')
9
- if iframe.attr('src') != iframeSrc
10
- iframe.attr('src', iframeSrc)
11
-
12
- modal.modal(show: true)
13
- e.preventDefault()
14
-
15
- # Make the files library modal window fill the browsers available height.
16
- modal.on 'show.bs.modal', (e) ->
17
- height = $(window).height() - 60
18
- $(e.target).find('.modal-content').css('height', "#{height}px")
19
-
20
- $(window).on 'resize', ->
21
- height = $(window).height() - 60
22
- modal.find('.modal-content').css('height', "#{height}px")
23
-
24
- # When clicking a file path in the file list select it to make
25
- # it easy to copy&paste.
26
- $(document).on 'click', '.cms-uploader-filelist input[type=text]', ->
27
- $(this).select()
28
-
29
- ) jQuery
@@ -1,140 +0,0 @@
1
- # CMS Uploader using plupload http://www.plupload.com/. Code inspired by
2
- # plupload queue widget https://github.com/moxiecode/plupload/tree/master/js/jquery.plupload.queue
3
- #
4
- #= require comfy/vendor/moxie.min
5
- #= require comfy/vendor/plupload.dev
6
-
7
- (($, o) ->
8
- window.CMS or (window.CMS = {})
9
- window.CMS.uploader = (target, settings) ->
10
-
11
- # Add a file to the file list.
12
- addFile = (file) ->
13
- fileList = $(".cms-uploader-filelist", target)
14
-
15
- fileList.prepend("
16
- <li id='#{file.id}' class='row temp'>
17
- <div class='col-md-9 d-flex align-items-center'>
18
- <div class='progress'>
19
- <div class='progress-bar progress-bar-striped progress-bar-animated'>
20
- <span>#{file.name}</span>
21
- </div>
22
- </div>
23
- </div>
24
- <div class='col-md-3 d-flex align-items-center justify-content-md-end'>
25
- <a class='btn btn-sm btn-danger float-right cms-uploader-file-delete' href='#'>Delete</a>
26
- </div>
27
- </li>
28
- ")
29
-
30
- $("#" + file.id + " a.cms-uploader-file-delete").click (e) ->
31
- uploader.removeFile(file)
32
- e.preventDefault()
33
-
34
- updateFileStatus(file)
35
-
36
- # Remove a file from the file list.
37
- removeFile = (file) ->
38
- $("#" + file.id).remove()
39
-
40
- # Update a files upload status in the file list.
41
- updateFileStatus = (file) ->
42
- progress_bar = $("##{file.id} .progress-bar", target)
43
- if file.status == plupload.UPLOADING
44
- progress_bar.css('width', "#{file.percent}%")
45
- if file.status == plupload.FAILED
46
- progress_bar.css('width', '100%').addClass('progress-bar-danger')
47
- $('span', progress_bar).html(file.error_message)
48
-
49
- uploader = undefined
50
- id = target.attr("id")
51
-
52
- unless id
53
- id = plupload.guid()
54
- target.attr('id', id)
55
-
56
- settings = $.extend(
57
- runtimes: "html5,browserplus,silverlight,flash,gears"
58
- dragdrop: true
59
- drop_element: "#{id}-drag-drop-target"
60
- browse_button: "#{id}-browse"
61
- container: id
62
- file_data_name: "file[file]"
63
- , settings)
64
-
65
- uploader = new plupload.Uploader(settings)
66
- uploader.bind "PostInit", (up) ->
67
-
68
- # Show drag and drop info and attach events if drag and drop is
69
- # supported and enabled.
70
- if up.settings.dragdrop and up.features.dragdrop
71
- dropElement = $(up.settings.drop_element).get(0)
72
-
73
- # When dragging over the document add a class to the drop target
74
- # that puts it ontop of every element and remove that class when
75
- # dropping or leaving the drop target. Otherwise the dragleave
76
- # event would fire whenever we dragging over a child element inside
77
- # the drop target such as text nodes or stuff.
78
- activeClass = 'cms-uploader-drag-drop-target-active'
79
- document.addEventListener 'dragenter', (e) ->
80
- # Only react to drag'n'drops that contain a file. See:
81
- # https://developer.mozilla.org/en-US/docs/Web/API/DataTransfer/types
82
- if e.dataTransfer.types.indexOf('Files') != -1
83
- dropElement.classList.add(activeClass)
84
- for eventName in ['drop', 'dragleave']
85
- dropElement.addEventListener eventName, ->
86
- dropElement.classList.remove(activeClass)
87
-
88
- else
89
- $('.cms-uploader-drag-drop-info', target).hide()
90
-
91
- # Need to bind this before initialization to handle initialization errors too.
92
- uploader.bind 'Error', (up, err) ->
93
- file = err.file
94
- message = undefined
95
-
96
- if file
97
- # Get error message from the server response. Not all runtimes
98
- # support this though.
99
- message = err.response
100
-
101
- # If no error message is in the server response get standard
102
- # plupload error messages. This will have descriptive error message
103
- # for something like file size or file format errors but for
104
- # server errors it will only display a general error message.
105
- unless message
106
- message = err.message
107
- if err.details
108
- message += " (#{err.details})"
109
- file.status = plupload.FAILED
110
- file.error_message = message
111
- updateFileStatus file
112
-
113
- if err.code == plupload.INIT_ERROR
114
- alert _('Error: Initialisation error. Reload to try again.')
115
-
116
- uploader.init()
117
- uploader.bind 'FilesAdded', (up, files) ->
118
- $.each files, (i, file) ->
119
- addFile file
120
-
121
- # Auto start upload when files are added.
122
- uploader.start()
123
-
124
- uploader.bind 'UploadProgress', (up, file) ->
125
- updateFileStatus(file)
126
-
127
- uploader.bind "FileUploaded", (up, file, info) ->
128
- # Replace the dummy file entry in the file list with the the entry
129
- # from the server response.
130
- $("li##{file.id}").replaceWith(info.response)
131
-
132
- uploader.bind 'FilesRemoved', (up, files) ->
133
- $.each files, (i, file) ->
134
- removeFile file
135
-
136
- # Call setup function
137
- if settings.setup
138
- settings.setup(uploader)
139
-
140
- ) jQuery, plupload
@@ -1 +0,0 @@
1
- $("<%= escape_javascript(render :partial => 'file', :object => @file) %>").appendTo(".cms-uploader-filelist");
@@ -1,2 +0,0 @@
1
- $("li[data-id=<%= @file.id %>]").fadeOut 'slow', ->
2
- $(this).remove()
@@ -1 +0,0 @@
1
- $('#form-fragments').replaceWith('<%= escape_javascript(render("comfy/admin/cms/fragments/form_fragments", record: @page)) %>');
@@ -1 +0,0 @@
1
- $('#form-fragments').replaceWith('<%= escape_javascript(render("comfy/admin/cms/fragments/form_fragments", record: @translation)) %>');