para 0.11.4 → 0.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (228) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/stylesheets/para/admin/main.scss +31 -0
  3. data/app/assets/stylesheets/para/admin/src/_affix.scss +7 -0
  4. data/app/assets/stylesheets/para/admin/src/_alert.scss +35 -0
  5. data/app/assets/stylesheets/para/admin/src/_base.scss +63 -0
  6. data/app/assets/stylesheets/para/admin/src/_bootstrap-variables.scss +766 -379
  7. data/app/assets/stylesheets/para/admin/src/_breadcrumb.scss +37 -0
  8. data/app/assets/stylesheets/para/admin/src/_buttons.scss +128 -0
  9. data/app/assets/stylesheets/para/admin/src/_checkable.scss +106 -0
  10. data/app/assets/stylesheets/para/admin/src/_common.scss +250 -0
  11. data/app/assets/stylesheets/para/admin/src/_dropdown.scss +52 -0
  12. data/app/assets/stylesheets/para/admin/src/_form.scss +359 -0
  13. data/app/assets/stylesheets/para/admin/src/_list.scss +96 -0
  14. data/app/assets/stylesheets/para/admin/src/_mixins.scss +109 -0
  15. data/app/assets/stylesheets/para/admin/src/_multi-select.scss +110 -0
  16. data/app/assets/stylesheets/para/admin/src/_navigation.scss +210 -0
  17. data/app/assets/stylesheets/para/admin/src/_navtabs.scss +68 -0
  18. data/app/assets/stylesheets/para/admin/src/_nested-many.scss +87 -0
  19. data/app/assets/stylesheets/para/admin/src/_nested_one.scss +26 -0
  20. data/app/assets/stylesheets/para/admin/src/_orderable.scss +48 -0
  21. data/app/assets/stylesheets/para/admin/src/_page-loading.scss +40 -0
  22. data/app/assets/stylesheets/para/admin/src/_pagination.scss +39 -0
  23. data/app/assets/stylesheets/para/admin/src/_panel.scss +61 -0
  24. data/app/assets/stylesheets/para/admin/src/_responsive.scss +133 -0
  25. data/app/assets/stylesheets/para/admin/src/_sorting.scss +43 -0
  26. data/app/assets/stylesheets/para/admin/src/_statcard.scss +46 -0
  27. data/app/assets/stylesheets/para/admin/src/_table.scss +36 -0
  28. data/app/assets/stylesheets/para/admin/src/_tree.scss +60 -0
  29. data/app/assets/stylesheets/para/admin/src/{_variables.sass → _variables.scss} +7 -7
  30. data/app/assets/stylesheets/para/admin/src/{_well.sass → _well.scss} +5 -4
  31. data/app/assets/stylesheets/para/admin.scss +15 -0
  32. data/app/assets/stylesheets/para/index.scss +1 -0
  33. data/app/assets/stylesheets/para/lib/datetimepicker.scss +15 -0
  34. data/app/assets/stylesheets/para/lib/fuelux.scss +46 -0
  35. data/app/assets/stylesheets/para/lib/jasny-bootstrap.scss +100 -0
  36. data/app/assets/stylesheets/para/lib/selectize.scss +129 -0
  37. data/app/assets/stylesheets/para/lib/slider.scss +14 -0
  38. data/app/controllers/para/admin/crud_resources_controller.rb +16 -9
  39. data/app/controllers/para/admin/imports_controller.rb +9 -9
  40. data/app/controllers/para/admin/jobs_controller.rb +7 -1
  41. data/app/controllers/para/admin/resources_controller.rb +17 -18
  42. data/app/controllers/para/admin/settings_component_controller.rb +2 -2
  43. data/app/helpers/para/admin/base_helper.rb +36 -25
  44. data/app/helpers/para/admin/page_helper.rb +8 -9
  45. data/app/helpers/para/flash_helper.rb +7 -28
  46. data/app/helpers/para/model_helper.rb +5 -8
  47. data/app/helpers/para/tree_helper.rb +4 -4
  48. data/app/javascripts/para/admin/async-progress.js +58 -0
  49. data/app/javascripts/para/admin/filters-form.js +12 -0
  50. data/app/javascripts/para/admin/job-tracker.js +33 -0
  51. data/app/javascripts/para/admin/table.js +58 -0
  52. data/app/javascripts/para/admin/tabs.js +110 -0
  53. data/app/javascripts/para/admin/theme_actions.js +39 -0
  54. data/app/javascripts/para/admin/tree.js +124 -0
  55. data/app/javascripts/para/application.js +2 -0
  56. data/app/javascripts/para/controllers/application.js +17 -0
  57. data/app/javascripts/para/controllers/index.js +10 -0
  58. data/app/javascripts/para/controllers/para_admin_flash_message_controller.js +48 -0
  59. data/app/javascripts/para/controllers/para_admin_modal_controller.js +43 -0
  60. data/app/javascripts/para/controllers/selectize_field_controller.js +142 -0
  61. data/app/javascripts/para/index.js +31 -0
  62. data/app/javascripts/para/inputs/material-input.js +7 -0
  63. data/app/javascripts/para/inputs/multi-select-input.js +343 -0
  64. data/app/javascripts/para/inputs/nested_many.js +151 -0
  65. data/app/javascripts/para/lib/fetch.js +41 -0
  66. data/app/javascripts/para/lib/page-loading.js +42 -0
  67. data/app/javascripts/para/simple_form_extension/colorpicker.js +30 -0
  68. data/app/javascripts/para/simple_form_extension/datetimepicker.js +115 -0
  69. data/app/javascripts/para/simple_form_extension/fileinput.js +57 -0
  70. data/app/javascripts/para/simple_form_extension/index.js +12 -0
  71. data/app/javascripts/para/simple_form_extension/selectize.js +160 -0
  72. data/app/javascripts/para/simple_form_extension/simple_form_extension_initialization.js +62 -0
  73. data/app/javascripts/para/simple_form_extension/slider.js +43 -0
  74. data/app/javascripts/para/simple_form_extension/spinbox.js +35 -0
  75. data/app/javascripts/para/vendor/bootstrap-colorpicker.js +1025 -0
  76. data/app/javascripts/para/vendor/bootstrap-slider.js +1610 -0
  77. data/app/javascripts/para/vendor/cocoon.js +150 -0
  78. data/app/javascripts/para/vendor/jquery.datetimepicker.js +2156 -0
  79. data/app/javascripts/para/vendor/jquery.js +3 -0
  80. data/app/javascripts/para/vendor/spinbox.js +438 -0
  81. data/app/javascripts/para/vendor/vertebra.js +224 -0
  82. data/app/views/admin/para/exporter/bases/_completed.html.haml +1 -1
  83. data/app/views/layouts/para/admin.html.haml +4 -2
  84. data/app/views/para/admin/imports/new.html.haml +12 -11
  85. data/app/views/para/admin/jobs/_completed.html.haml +1 -1
  86. data/app/views/para/admin/jobs/_failed.html.haml +1 -1
  87. data/app/views/para/admin/jobs/_job.html.haml +11 -0
  88. data/app/views/para/admin/jobs/show.html.haml +1 -10
  89. data/app/views/para/admin/resources/_add_button.html.haml +1 -1
  90. data/app/views/para/admin/resources/_exports_menu.html.haml +2 -2
  91. data/app/views/para/admin/resources/_filters.html.haml +1 -1
  92. data/app/views/para/admin/resources/_imports_menu.html.haml +2 -2
  93. data/app/views/para/admin/resources/_list.html.haml +27 -26
  94. data/app/views/para/admin/resources/_navigation.html.haml +10 -11
  95. data/app/views/para/admin/resources/_subclassable_add_button.html.haml +1 -1
  96. data/app/views/para/admin/shared/_flash.html.haml +18 -0
  97. data/app/views/para/admin/shared/_header.html.haml +1 -1
  98. data/app/views/para/form/_tabs.html.haml +1 -1
  99. data/app/views/para/inputs/_nested_many.html.haml +3 -3
  100. data/app/views/para/inputs/nested_many/_add.html.haml +1 -1
  101. data/app/views/para/inputs/nested_many/_add_with_subclasses.html.haml +2 -2
  102. data/app/views/para/inputs/nested_many/_container.html.haml +1 -1
  103. data/config/locales/fr.yml +1 -0
  104. data/lib/generators/para/install/install_generator.rb +10 -14
  105. data/lib/para/attribute_field/base.rb +3 -0
  106. data/lib/para/attribute_field/wysiwyg_editor.rb +15 -0
  107. data/lib/para/attribute_field.rb +1 -1
  108. data/lib/para/components_configuration.rb +1 -1
  109. data/lib/para/engine.rb +20 -22
  110. data/lib/para/ext/turbo_stream.rb +13 -0
  111. data/lib/para/ext.rb +1 -1
  112. data/lib/para/form_builder/containers.rb +33 -22
  113. data/lib/para/form_builder/nested_form.rb +6 -5
  114. data/lib/para/inputs/nested_many_input.rb +5 -0
  115. data/lib/para/markup/modal.rb +30 -15
  116. data/lib/para/markup/resources_buttons.rb +15 -11
  117. data/lib/para/model_field_parsers/wysiwyg_editor.rb +19 -0
  118. data/lib/para/model_field_parsers.rb +1 -1
  119. data/lib/para/version.rb +1 -1
  120. data/lib/para.rb +2 -8
  121. data/lib/simple_form_extension/components/icons.rb +13 -0
  122. data/lib/simple_form_extension/components/popovers.rb +46 -0
  123. data/lib/simple_form_extension/components.rb +8 -0
  124. data/lib/simple_form_extension/ext/form_builder.rb +20 -0
  125. data/lib/simple_form_extension/file_concern.rb +74 -0
  126. data/lib/simple_form_extension/inputs/boolean_input.rb +16 -0
  127. data/lib/simple_form_extension/inputs/collection_check_boxes_input.rb +15 -0
  128. data/lib/simple_form_extension/inputs/collection_radio_buttons_input.rb +15 -0
  129. data/lib/simple_form_extension/inputs/color_input.rb +37 -0
  130. data/lib/simple_form_extension/inputs/date_time_input.rb +48 -0
  131. data/lib/simple_form_extension/inputs/file_input.rb +41 -0
  132. data/lib/simple_form_extension/inputs/image_input.rb +110 -0
  133. data/lib/simple_form_extension/inputs/numeric_input.rb +27 -0
  134. data/lib/simple_form_extension/inputs/selectize_input.rb +210 -0
  135. data/lib/simple_form_extension/inputs/slider_input.rb +30 -0
  136. data/lib/simple_form_extension/inputs.rb +16 -0
  137. data/lib/simple_form_extension/railtie.rb +21 -0
  138. data/lib/simple_form_extension/resource_name_helper.rb +9 -0
  139. data/lib/simple_form_extension/translations.rb +7 -0
  140. data/lib/simple_form_extension/version.rb +3 -0
  141. data/lib/simple_form_extension.rb +30 -0
  142. data/vendor/assets/images/simple_form_extension/bootstrap-colorpicker/alpha-horizontal.png +0 -0
  143. data/vendor/assets/images/simple_form_extension/bootstrap-colorpicker/alpha.png +0 -0
  144. data/vendor/assets/images/simple_form_extension/bootstrap-colorpicker/hue-horizontal.png +0 -0
  145. data/vendor/assets/images/simple_form_extension/bootstrap-colorpicker/hue.png +0 -0
  146. data/vendor/assets/images/simple_form_extension/bootstrap-colorpicker/saturation.png +0 -0
  147. data/vendor/assets/stylesheets/bootstrap-colorpicker.scss +227 -0
  148. data/vendor/assets/stylesheets/bootstrap-slider.scss +246 -0
  149. data/vendor/assets/stylesheets/bootstrap.scss +6032 -0
  150. data/vendor/assets/stylesheets/jquery.datetimepicker.scss +568 -0
  151. metadata +120 -188
  152. data/app/assets/javascripts/admin/app.coffee +0 -1
  153. data/app/assets/javascripts/para/admin/async-progress.coffee +0 -29
  154. data/app/assets/javascripts/para/admin/filters-form.coffee +0 -11
  155. data/app/assets/javascripts/para/admin/job-tracker.coffee +0 -39
  156. data/app/assets/javascripts/para/admin/table.coffee +0 -44
  157. data/app/assets/javascripts/para/admin/tabs.coffee +0 -63
  158. data/app/assets/javascripts/para/admin/theme_actions.coffee +0 -25
  159. data/app/assets/javascripts/para/admin/tree.coffee +0 -105
  160. data/app/assets/javascripts/para/admin.coffee +0 -22
  161. data/app/assets/javascripts/para/application.js +0 -13
  162. data/app/assets/javascripts/para/inputs/material-input.coffee +0 -4
  163. data/app/assets/javascripts/para/inputs/multi-select-input.coffee +0 -174
  164. data/app/assets/javascripts/para/inputs/nested_many.coffee +0 -108
  165. data/app/assets/javascripts/para/lib/ajax.coffee +0 -11
  166. data/app/assets/javascripts/para/lib/remote-file-forms.coffee +0 -59
  167. data/app/assets/javascripts/para/lib/turbolinks-forms.coffee +0 -23
  168. data/app/assets/javascripts/para/lib/turbolinks-loading.coffee +0 -25
  169. data/app/assets/javascripts/para/lib/turbolinks-reloader.coffee +0 -19
  170. data/app/assets/stylesheets/para/admin/main.sass +0 -33
  171. data/app/assets/stylesheets/para/admin/src/_affix.sass +0 -4
  172. data/app/assets/stylesheets/para/admin/src/_alert.sass +0 -17
  173. data/app/assets/stylesheets/para/admin/src/_base.sass +0 -54
  174. data/app/assets/stylesheets/para/admin/src/_breadcrumb.sass +0 -32
  175. data/app/assets/stylesheets/para/admin/src/_buttons.sass +0 -107
  176. data/app/assets/stylesheets/para/admin/src/_checkable.sass +0 -94
  177. data/app/assets/stylesheets/para/admin/src/_common.sass +0 -202
  178. data/app/assets/stylesheets/para/admin/src/_dropdown.sass +0 -40
  179. data/app/assets/stylesheets/para/admin/src/_form.sass +0 -299
  180. data/app/assets/stylesheets/para/admin/src/_list.sass +0 -89
  181. data/app/assets/stylesheets/para/admin/src/_mixins.sass +0 -113
  182. data/app/assets/stylesheets/para/admin/src/_multi-select.sass +0 -91
  183. data/app/assets/stylesheets/para/admin/src/_navigation.sass +0 -171
  184. data/app/assets/stylesheets/para/admin/src/_navtabs.sass +0 -58
  185. data/app/assets/stylesheets/para/admin/src/_nested-many.sass +0 -75
  186. data/app/assets/stylesheets/para/admin/src/_nested_one.sass +0 -22
  187. data/app/assets/stylesheets/para/admin/src/_orderable.sass +0 -44
  188. data/app/assets/stylesheets/para/admin/src/_page-loading.sass +0 -39
  189. data/app/assets/stylesheets/para/admin/src/_pagination.sass +0 -34
  190. data/app/assets/stylesheets/para/admin/src/_panel.sass +0 -55
  191. data/app/assets/stylesheets/para/admin/src/_responsive.sass +0 -117
  192. data/app/assets/stylesheets/para/admin/src/_sorting.sass +0 -36
  193. data/app/assets/stylesheets/para/admin/src/_statcard.sass +0 -41
  194. data/app/assets/stylesheets/para/admin/src/_table.sass +0 -33
  195. data/app/assets/stylesheets/para/admin/src/_tree.sass +0 -52
  196. data/app/assets/stylesheets/para/admin.sass +0 -12
  197. data/app/assets/stylesheets/para/lib/compass/_support.scss +0 -447
  198. data/app/assets/stylesheets/para/lib/compass/css3/_box-shadow.scss +0 -88
  199. data/app/assets/stylesheets/para/lib/compass/css3/_images.scss +0 -152
  200. data/app/assets/stylesheets/para/lib/compass/css3/_inline-block.scss +0 -31
  201. data/app/assets/stylesheets/para/lib/compass/css3/_text-shadow.scss +0 -82
  202. data/app/assets/stylesheets/para/lib/compass/css3/_transform.scss +0 -590
  203. data/app/assets/stylesheets/para/lib/compass/css3/_transition.scss +0 -190
  204. data/app/assets/stylesheets/para/lib/compass/css3/_user-interface.scss +0 -71
  205. data/app/assets/stylesheets/para/lib/compass/utilities/general/_hacks.scss +0 -65
  206. data/app/assets/stylesheets/para/lib/datetimepicker.sass +0 -15
  207. data/app/assets/stylesheets/para/lib/fuelux.sass +0 -40
  208. data/app/assets/stylesheets/para/lib/jasny-bootstrap.sass +0 -97
  209. data/app/assets/stylesheets/para/lib/redactor.sass +0 -86
  210. data/app/assets/stylesheets/para/lib/selectize.sass +0 -111
  211. data/app/assets/stylesheets/para/lib/slider.sass +0 -12
  212. data/app/assets/stylesheets/para/plugins-includes.sass.erb +0 -1
  213. data/lib/para/attribute_field/redactor.rb +0 -22
  214. data/lib/para/ext/request_iframe_xhr.rb +0 -17
  215. data/lib/para/iframe_transport/middleware.rb +0 -58
  216. data/lib/para/iframe_transport.rb +0 -7
  217. data/lib/para/model_field_parsers/redactor.rb +0 -19
  218. data/vendor/assets/javascripts/jquery.iframe-transport.js +0 -260
  219. data/vendor/assets/javascripts/jquery.remote-modal-form.coffee +0 -145
  220. /data/app/assets/stylesheets/admin/{app.sass → app.scss} +0 -0
  221. /data/app/{assets/javascripts → javascripts}/para/plugins-includes.js.erb +0 -0
  222. /data/{vendor/assets/javascripts → app/javascripts/para/vendor}/Sortable.js +0 -0
  223. /data/{vendor/assets/javascripts → app/javascripts/para/vendor}/jasny-bootstrap.js +0 -0
  224. /data/{vendor/assets/javascripts → app/javascripts/para/vendor}/jquery.scrollto.js +0 -0
  225. /data/{vendor/assets/javascripts → app/javascripts/para/vendor}/jquery.sortable.js +0 -0
  226. /data/vendor/assets/stylesheets/{animate.css → animate.scss} +0 -0
  227. /data/vendor/assets/stylesheets/{hint.css → hint.scss} +0 -0
  228. /data/vendor/assets/stylesheets/{jasny-bootstrap.css → jasny-bootstrap.scss} +0 -0
@@ -1,22 +0,0 @@
1
- module Para
2
- module AttributeField
3
- class Redactor < AttributeField::Base
4
- include ActionView::Helpers::SanitizeHelper
5
- include ActionView::Helpers::TextHelper
6
-
7
- register :redactor, self
8
-
9
- def initialize(model, options = {})
10
- options.reverse_merge!(type: 'text', field_type: 'redactor')
11
- super(model, options)
12
- end
13
-
14
- def value_for(instance)
15
- (value = instance.send(name)) && truncate(
16
- sanitize(value, tags: []),
17
- length: 50
18
- )
19
- end
20
- end
21
- end
22
- end
@@ -1,17 +0,0 @@
1
- module Para
2
- module Ext
3
- module Request
4
- module IFrameXHR
5
- # Handle jquery.iframe-transport specific parameter
6
- def xml_http_request?
7
- super || iframe_request?
8
- end
9
- alias :xhr? :xml_http_request?
10
-
11
- def iframe_request?
12
- params[:'X-Requested-With'] == 'IFrame'
13
- end
14
- end
15
- end
16
- end
17
- end
@@ -1,58 +0,0 @@
1
- module Para
2
- module IframeTransport
3
- class Middleware
4
- attr_reader :app
5
-
6
- def initialize(app)
7
- @app = app
8
- end
9
-
10
- def call(env)
11
- status, headers, response_body = app.call(env)
12
-
13
- # Build a rails request to allow using its API to analyze the request
14
- # format and mode
15
- request = ActionDispatch::Request.new(
16
- Rails.application.env_config.merge(env)
17
- )
18
-
19
- # If the request is an Ajax IFrame tranport one, we add a hidden field
20
- # to the response body to pass response informations that can't be
21
- # retrieved with headers to the javascript client.
22
- if matching_request?(request)
23
- add_status_to_response(request, response_body)
24
- end
25
-
26
- [status, headers, response_body]
27
- end
28
-
29
- private
30
-
31
- def matching_request?(request)
32
- request.iframe_request? && request.format.html?
33
- end
34
-
35
- def add_status_to_response(request, response_body)
36
- response = response_body.instance_variable_get(:@response)
37
-
38
- html = Nokogiri::HTML::DocumentFragment.parse(response.body)
39
-
40
- input = Nokogiri::XML::Node.new("input", html).tap do |node|
41
- node[:type] = 'hidden'
42
- node[:'data-iframe-response-data'] = true
43
- node[:'data-type'] = request.format
44
- node[:'data-status'] = response.status
45
- node[:'data-statusText'] = response.status_message
46
- end
47
-
48
- if (body = html.at('body'))
49
- input.parent = body
50
- else
51
- html << input
52
- end
53
-
54
- response.body = html.to_html
55
- end
56
- end
57
- end
58
- end
@@ -1,7 +0,0 @@
1
- module Para
2
- module IframeTransport
3
- extend ActiveSupport::Autoload
4
-
5
- autoload :Middleware
6
- end
7
- end
@@ -1,19 +0,0 @@
1
- module Para
2
- module ModelFieldParsers
3
- class Redactor < Para::ModelFieldParsers::Base
4
- register :redactor, self
5
-
6
- def parse!
7
- %w(content description).each do |field_name|
8
- field = fields_hash[field_name]
9
-
10
- if field && field.type == :text
11
- fields_hash[field_name] = Para::AttributeField::Redactor.new(
12
- field.model, name: field_name
13
- )
14
- end
15
- end
16
- end
17
- end
18
- end
19
- end
@@ -1,260 +0,0 @@
1
- // This [jQuery](https://jquery.com/) plugin implements an `<iframe>`
2
- // [transport](https://api.jquery.com/jQuery.ajax/#extending-ajax) so that
3
- // `$.ajax()` calls support the uploading of files using standard HTML file
4
- // input fields. This is done by switching the exchange from `XMLHttpRequest`
5
- // to a hidden `iframe` element containing a form that is submitted.
6
-
7
- // The [source for the plugin](https://github.com/cmlenz/jquery-iframe-transport)
8
- // is available on [Github](https://github.com/) and licensed under the [MIT
9
- // license](https://github.com/cmlenz/jquery-iframe-transport/blob/master/LICENSE).
10
-
11
- // ## Usage
12
-
13
- // To use this plugin, you simply add an `iframe` option with the value `true`
14
- // to the Ajax settings an `$.ajax()` call, and specify the file fields to
15
- // include in the submssion using the `files` option, which can be a selector,
16
- // jQuery object, or a list of DOM elements containing one or more
17
- // `<input type="file">` elements:
18
-
19
- // $("#myform").submit(function() {
20
- // $.ajax(this.action, {
21
- // files: $(":file", this),
22
- // iframe: true
23
- // }).complete(function(data) {
24
- // });
25
- // });
26
-
27
- // The plugin will construct hidden `<iframe>` and `<form>` elements, add the
28
- // file field(s) to that form, submit the form, and process the response.
29
-
30
- // If you want to include other form fields in the form submission, include
31
- // them in the `data` option, and set the `processData` option to `false`:
32
-
33
- // $("#myform").submit(function() {
34
- // $.ajax(this.action, {
35
- // data: $(":text", this).serializeArray(),
36
- // files: $(":file", this),
37
- // iframe: true,
38
- // processData: false
39
- // }).complete(function(data) {
40
- // });
41
- // });
42
-
43
- // ### Response Data Types
44
-
45
- // As the transport does not have access to the HTTP headers of the server
46
- // response, it is not as simple to make use of the automatic content type
47
- // detection provided by jQuery as with regular XHR. If you can't set the
48
- // expected response data type (for example because it may vary depending on
49
- // the outcome of processing by the server), you will need to employ a
50
- // workaround on the server side: Send back an HTML document containing just a
51
- // `<textarea>` element with a `data-type` attribute that specifies the MIME
52
- // type, and put the actual payload in the textarea:
53
-
54
- // <textarea data-type="application/json">
55
- // {"ok": true, "message": "Thanks so much"}
56
- // </textarea>
57
-
58
- // The iframe transport plugin will detect this and pass the value of the
59
- // `data-type` attribute on to jQuery as if it was the "Content-Type" response
60
- // header, thereby enabling the same kind of conversions that jQuery applies
61
- // to regular responses. For the example above you should get a Javascript
62
- // object as the `data` parameter of the `complete` callback, with the
63
- // properties `ok: true` and `message: "Thanks so much"`.
64
-
65
- // ### Handling Server Errors
66
-
67
- // Another problem with using an `iframe` for file uploads is that it is
68
- // impossible for the javascript code to determine the HTTP status code of the
69
- // servers response. Effectively, all of the calls you make will look like they
70
- // are getting successful responses, and thus invoke the `done()` or
71
- // `complete()` callbacks. You can only communicate problems using the content
72
- // of the response payload. For example, consider using a JSON response such as
73
- // the following to indicate a problem with an uploaded file:
74
-
75
- // <textarea data-type="application/json">
76
- // {"ok": false, "message": "Please only upload reasonably sized files."}
77
- // </textarea>
78
-
79
- // ### Compatibility
80
-
81
- // This plugin has primarily been tested on Safari 5 (or later), Firefox 4 (or
82
- // later), and Internet Explorer (all the way back to version 6). While I
83
- // haven't found any issues with it so far, I'm fairly sure it still doesn't
84
- // work around all the quirks in all different browsers. But the code is still
85
- // pretty simple overall, so you should be able to fix it and contribute a
86
- // patch :)
87
-
88
- // ## Annotated Source
89
-
90
- (function($, undefined) {
91
- // Register a prefilter that checks whether the `iframe` option is set, and
92
- // switches to the "iframe" data type if it is `true`.
93
- $.ajaxPrefilter(function(options, origOptions, jqXHR) {
94
- if (options.iframe) {
95
- options.originalURL = options.url;
96
- return "iframe";
97
- }
98
- });
99
-
100
- // Register a transport for the "iframe" data type. It will only activate
101
- // when the "files" option has been set to a non-empty list of enabled file
102
- // inputs.
103
- $.ajaxTransport("iframe", function(options, origOptions, jqXHR) {
104
- var form = null,
105
- iframe = null,
106
- name = "iframe-" + $.now(),
107
- files = $(options.files).filter(":file:enabled"),
108
- markers = null,
109
- accepts = null;
110
-
111
-
112
- // This function gets called after a successful submission or an abortion
113
- // and should revert all changes made to the page to enable the
114
- // submission via this transport.
115
- function cleanUp() {
116
- files.each(function(i, file) {
117
- var $file = $(file);
118
- $file.data("clone").replaceWith($file);
119
- });
120
- form.remove();
121
- iframe.one("load", function() { iframe.remove(); });
122
- iframe.attr("src", "about:blank");
123
- }
124
-
125
- // Remove "iframe" from the data types list so that further processing is
126
- // based on the content type returned by the server, without attempting an
127
- // (unsupported) conversion from "iframe" to the actual type.
128
- options.dataTypes.shift();
129
-
130
- // Use the data from the original AJAX options, as it doesn't seem to be
131
- // copied over since jQuery 1.7.
132
- // See https://github.com/cmlenz/jquery-iframe-transport/issues/6
133
- options.data = origOptions.data;
134
-
135
- if (files.length) {
136
- form = $("<form enctype='multipart/form-data' method='post'></form>").
137
- hide().attr({action: options.originalURL, target: name});
138
-
139
- // If there is any additional data specified via the `data` option,
140
- // we add it as hidden fields to the form. This (currently) requires
141
- // the `processData` option to be set to false so that the data doesn't
142
- // get serialized to a string.
143
- if (typeof(options.data) === "string" && options.data.length > 0) {
144
- $.error("data must not be serialized");
145
- }
146
- $.each(options.data || {}, function(name, value) {
147
- if ($.isPlainObject(value)) {
148
- name = value.name;
149
- value = value.value;
150
- }
151
-
152
-
153
- $("<input type='hidden' />").attr({name: name, value: value}).
154
- appendTo(form);
155
- });
156
-
157
- // Add a hidden `X-Requested-With` field with the value `IFrame` to the
158
- // field, to help server-side code to determine that the upload happened
159
- // through this transport.
160
- $("<input type='hidden' value='IFrame' name='X-Requested-With' />").
161
- appendTo(form);
162
-
163
- // ----------------------------------------------------------------------
164
- // Modified section
165
- // ----------------------------------------------------------------------
166
-
167
- // Add CSRF token to the form since jquery-ujs adds it to the XHR request
168
- // headers and the iframe transport doesn't support them
169
- $("<input type='hidden' />").attr({name: $.rails.csrfParam(), value: $.rails.csrfToken()}).
170
- appendTo(form);
171
-
172
- // ----------------------------------------------------------------------
173
- // End of modified section
174
- // ----------------------------------------------------------------------
175
-
176
- // Borrowed straight from the JQuery source.
177
- // Provides a way of specifying the accepted data type similar to the
178
- // HTTP "Accept" header
179
- if (options.dataTypes[0] && options.accepts[options.dataTypes[0]]) {
180
- accepts = options.accepts[options.dataTypes[0]] +
181
- (options.dataTypes[0] !== "*" ? ", */*; q=0.01" : "");
182
- } else {
183
- accepts = options.accepts["*"];
184
- }
185
- $("<input type='hidden' name='X-HTTP-Accept'>").
186
- attr("value", accepts).appendTo(form);
187
-
188
- // Move the file fields into the hidden form, but first remember their
189
- // original locations in the document by replacing them with disabled
190
- // clones. This should also avoid introducing unwanted changes to the
191
- // page layout during submission.
192
- markers = files.after(function(idx) {
193
- var $this = $(this),
194
- $clone = $this.clone().prop("disabled", true);
195
- $this.data("clone", $clone);
196
- return $clone;
197
- }).next();
198
- files.appendTo(form);
199
-
200
- return {
201
-
202
- // The `send` function is called by jQuery when the request should be
203
- // sent.
204
- send: function(headers, completeCallback) {
205
- iframe = $("<iframe src='about:blank' name='" + name +
206
- "' id='" + name + "' style='display:none'></iframe>");
207
-
208
- // The first load event gets fired after the iframe has been injected
209
- // into the DOM, and is used to prepare the actual submission.
210
- iframe.one("load", function() {
211
-
212
- // The second load event gets fired when the response to the form
213
- // submission is received. The implementation detects whether the
214
- // actual payload is embedded in a `<textarea>` element, and
215
- // prepares the required conversions to be made in that case.
216
- iframe.one("load", function() {
217
- var doc = this.contentWindow ? this.contentWindow.document :
218
- (this.contentDocument ? this.contentDocument : this.document),
219
- root = doc.documentElement ? doc.documentElement : doc.body,
220
- dataInput = $(root).find("[data-iframe-response-data]").remove()[0],
221
- type = dataInput && dataInput.getAttribute("data-type") || null,
222
- status = (dataInput && dataInput.getAttribute("data-status")) || 200,
223
- statusText = dataInput && dataInput.getAttribute("data-statusText") || "OK",
224
- content = {
225
- html: root.innerHTML,
226
- text: root ? (root.textContent || root.innerText) : null
227
- };
228
-
229
- jqXHR.responseText = content.html;
230
-
231
- cleanUp();
232
- completeCallback(status, statusText, content, type ?
233
- ("Content-Type: " + type) :
234
- null);
235
- });
236
-
237
- // Now that the load handler has been set up, submit the form.
238
- form[0].submit();
239
- });
240
-
241
- // After everything has been set up correctly, the form and iframe
242
- // get injected into the DOM so that the submission can be
243
- // initiated.
244
- $("body").append(form, iframe);
245
- },
246
-
247
- // The `abort` function is called by jQuery when the request should be
248
- // aborted.
249
- abort: function() {
250
- if (iframe !== null) {
251
- iframe.unbind("load").attr("src", "about:blank");
252
- cleanUp();
253
- }
254
- }
255
-
256
- };
257
- }
258
- });
259
-
260
- })(jQuery);
@@ -1,145 +0,0 @@
1
- # Allows to handle a form in a modal with rails' jquery-ujs remote links and
2
- # forms feature, without having to write any extra javascript
3
- #
4
- class @RemoteModalForm extends Vertebra.View
5
- @setLoading = ($el) ->
6
- return unless $el and $el.length
7
-
8
- unless $el.data('loading-text')
9
- $el.data('loading-text', '<i class="fa fa-spinner fa-spin"></i>')
10
-
11
- $el.button('loading')
12
-
13
- @resetLoading = ($el) ->
14
- return unless $el and $el.length
15
- $el?.button('reset')
16
-
17
- events:
18
- 'ajax:success form[data-remote]': 'formSuccess'
19
- 'ajax:success a[data-remote]': 'pageLoaded'
20
- 'ajax:error [data-remote]': 'formError'
21
- 'ajax:beforeSend form[data-remote]': 'formBeforeSend'
22
- 'ajax:beforeSend a[data-remote]': 'linkBeforeSend'
23
- 'ajax:aborted:file [data-remote]': 'handleFormWithFiles'
24
- 'hidden.bs.modal': 'modalHidden'
25
- 'hide.bs.modal': 'modalHide'
26
-
27
- initialize: (options = {}) ->
28
- { modalMarkup, @$link, refreshOnClose } = options
29
- @replaceModalWith(modalMarkup)
30
- @refreshOnClose = if refreshOnClose? then refreshOnClose else @$link?.data('refresh-on-close')
31
- @trigger('shown')
32
-
33
- formSuccess: (e, response) ->
34
- @handleModalResponse(response)
35
- @trigger('success')
36
- @formDidSuccess = true
37
-
38
- formError: (e, jqXHR) ->
39
- @replaceModalWith(jqXHR.responseText)
40
- @trigger('error')
41
- @formDidSuccess = false
42
-
43
- # Intercept form jquery-ujs form submission when there are non-blank file
44
- # inputs in the `remote` form, so we can submit the form through FormData or
45
- # jquery.iframe-transport depending on browser support.
46
- #
47
- # Note that iframe transport does not allow us to track upload progress.
48
- #
49
- handleFormWithFiles: (e) ->
50
- if RemoteFileForm?.supported
51
- form = new RemoteFileForm(el: e.target)
52
- form.on('progress', @onFormUploadProgress)
53
- else
54
- @submitWithIframe($(e.currentTarget))
55
-
56
- return false
57
-
58
- submitWithIframe: ($form) ->
59
- jqXHR = jQuery.ajax
60
- url: $form.attr('action')
61
- method: $form.attr('method')
62
- files: $form.find(':file')
63
- iframe: true
64
- data: $form.find('input:not(:file), textarea, select').serializeArray()
65
- processData: false
66
-
67
- jqXHR
68
- .done (data) => @formSuccess(null, data)
69
- .fail (jqXHR) => @formError(null, jqXHR)
70
-
71
- onFormUploadProgress: (e) =>
72
- return unless e.originalEvent.lengthComputable
73
- # Build rounded progress
74
- progress = (e.originalEvent.loaded / e.originalEvent.total)
75
- progress = Math.round(progress * 10000) / 100
76
- # Display it in the submit button
77
- @$(':submit').text(progress + '%')
78
-
79
- pageLoaded: (e, response) ->
80
- @handleModalResponse(response)
81
-
82
- handleModalResponse: (response) ->
83
- if response and $.trim(response).length
84
- @replaceModalWith(response)
85
- else
86
- @hideModal()
87
-
88
- replaceModalWith: (modalMarkup) ->
89
- @hideModal()
90
-
91
- # We try to find a modal in the returned elements from the server
92
- $modal = $(modalMarkup).filter('.modal').eq(0)
93
- # If there are no modal, we try to find a modal inside the returned elements
94
- $modal = $modal.find('.modal') unless $modal.length
95
- # If no modal is finally found, we return and don't do anything
96
- return unless $modal.length
97
-
98
- # Initialize the returned modal
99
- $modal.appendTo('body')
100
- $modal.modal()
101
-
102
- # Configure the remote modal class to use the new modal and show it
103
- @setElement($modal)
104
- @$el.data('remote-modal-form', this)
105
- @showModal()
106
-
107
- showModal: ->
108
- @$el.simpleForm?()
109
-
110
- hideModal: (options = {}) ->
111
- @$el?.modal('hide')
112
-
113
- modalHide: (e) ->
114
- @refreshPage()
115
-
116
- modalHidden: (e) ->
117
- $(e.currentTarget).remove()
118
- @trigger('hide')
119
- @trigger('close') if @$el[0] is $(e.currentTarget)[0]
120
-
121
- formBeforeSend: (e) ->
122
- RemoteModalForm.setLoading(@$(':submit'))
123
-
124
- linkBeforeSend: (e) ->
125
- RemoteModalForm.setLoading($(e.currentTarget))
126
-
127
- refreshPage: ->
128
- Turbolinks.reloadPage() if @refreshOnClose and @formDidSuccess
129
-
130
- trigger: (event, args...) ->
131
- super(event, args...)
132
- @$el.trigger("remote-modal-form:#{ event }", args)
133
-
134
- # Lazy initialization when the link target is loaded
135
- #
136
- $(document).on 'page:change turbolinks:load', ->
137
- $('body').on 'ajax:beforeSend', '[data-remote-modal-form]', (e) ->
138
- RemoteModalForm.setLoading($(e.currentTarget))
139
-
140
- $('body').on 'ajax:error', '[data-remote-modal-form]', (e) ->
141
- RemoteModalForm.resetLoading($(e.currentTarget))
142
-
143
- $('body').on 'ajax:success', '[data-remote-modal-form]', (e, response) ->
144
- RemoteModalForm.resetLoading($(e.currentTarget))
145
- new RemoteModalForm(modalMarkup: response, $link: $(e.currentTarget))
File without changes