locomotivecms 3.0.0.pre.alpha.2 → 3.0.0.pre.alpha.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (178) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +3 -2
  3. data/README.md +1 -1
  4. data/app/api/locomotive/api/forms/membership_form.rb +13 -0
  5. data/app/api/locomotive/api/resources/membership_resource.rb +5 -3
  6. data/app/assets/javascripts/locomotive.js +2 -0
  7. data/app/assets/javascripts/locomotive/utils/backbone_patches.js.coffee +15 -1
  8. data/app/assets/javascripts/locomotive/utils/file.js.coffee +20 -0
  9. data/app/assets/javascripts/locomotive/utils/nprogress.js.coffee +5 -0
  10. data/app/assets/javascripts/locomotive/utils/rails_ujs.js.coffee +36 -0
  11. data/app/assets/javascripts/locomotive/utils/wysihtml5.js.coffee +1 -1
  12. data/app/assets/javascripts/locomotive/views/content_assets/picker_view.js.coffee +9 -17
  13. data/app/assets/javascripts/locomotive/views/editable_elements/edit_view.js.coffee +39 -0
  14. data/app/assets/javascripts/locomotive/views/editable_elements/index_view.js.coffee +104 -1
  15. data/app/assets/javascripts/locomotive/views/inputs/file_view.js.coffee +79 -10
  16. data/app/assets/javascripts/locomotive/views/inputs/rte/file_view.js.coffee +24 -4
  17. data/app/assets/javascripts/locomotive/views/inputs/rte_view.js.coffee.erb +18 -0
  18. data/app/assets/javascripts/locomotive/views/pages/new_view.js.coffee +3 -6
  19. data/app/assets/javascripts/locomotive/views/shared/drawer_view.js.coffee +24 -8
  20. data/app/assets/javascripts/locomotive/views/shared/form_view.js.coffee +21 -148
  21. data/app/assets/stylesheets/locomotive/application.scss +6 -0
  22. data/app/assets/stylesheets/locomotive/base/_form.scss +1 -0
  23. data/app/assets/stylesheets/locomotive/base/form/_base.scss +9 -0
  24. data/app/assets/stylesheets/locomotive/base/form/_file_input.scss +1 -1
  25. data/app/assets/stylesheets/locomotive/base/form/_link.scss +13 -0
  26. data/app/assets/stylesheets/locomotive/base/form/_select2.scss +28 -1
  27. data/app/assets/stylesheets/locomotive/components/_drawer.scss +8 -18
  28. data/app/assets/stylesheets/locomotive/components/_live_editing.scss +83 -0
  29. data/app/assets/stylesheets/locomotive/components/_transitions.scss +63 -1
  30. data/app/assets/stylesheets/locomotive/components/header/_base.scss +5 -1
  31. data/app/assets/stylesheets/locomotive/components/misc/_notify.scss +5 -7
  32. data/app/assets/stylesheets/locomotive/globals/_bootstrap.scss +4 -4
  33. data/app/assets/stylesheets/locomotive/globals/_mixins.scss +16 -0
  34. data/app/assets/stylesheets/locomotive/globals/_nprogress.scss +3 -0
  35. data/app/assets/stylesheets/locomotive/globals/_variables.scss +57 -49
  36. data/app/assets/stylesheets/locomotive/layouts/_live_editing.scss +29 -0
  37. data/app/controllers/locomotive/editable_elements_controller.rb +49 -2
  38. data/app/controllers/locomotive/pages_controller.rb +2 -2
  39. data/app/helpers/locomotive/custom_fields_helper.rb +1 -1
  40. data/app/helpers/locomotive/editable_elements_helper.rb +40 -0
  41. data/app/helpers/locomotive/pages_helper.rb +0 -1
  42. data/app/inputs/locomotive/array_input.rb +1 -1
  43. data/app/inputs/locomotive/file_input.rb +35 -7
  44. data/app/inputs/locomotive/rte_input.rb +2 -1
  45. data/app/inputs/locomotive/toggle_input.rb +1 -1
  46. data/app/models/locomotive/concerns/content_entry/localized.rb +4 -4
  47. data/app/models/locomotive/concerns/content_type/sync.rb +0 -5
  48. data/app/models/locomotive/concerns/page/redirect.rb +1 -1
  49. data/app/models/locomotive/content_entry.rb +5 -11
  50. data/app/models/locomotive/content_type.rb +22 -0
  51. data/app/models/locomotive/editable_control.rb +12 -27
  52. data/app/models/locomotive/editable_element.rb +8 -0
  53. data/app/models/locomotive/editable_file.rb +0 -1
  54. data/app/models/locomotive/editable_text.rb +10 -10
  55. data/app/models/locomotive/page.rb +1 -1
  56. data/app/policies/locomotive/page_policy.rb +1 -1
  57. data/app/services/locomotive/editable_element_service.rb +47 -0
  58. data/app/services/locomotive/page_parsing_service.rb +85 -31
  59. data/app/uploaders/locomotive/editable_file_uploader.rb +5 -1
  60. data/app/views/locomotive/editable_elements/_edit.html.haml +49 -0
  61. data/app/views/locomotive/editable_elements/_edit_with_content_entry.html.haml +21 -0
  62. data/app/views/locomotive/editable_elements/_form.html.haml +23 -0
  63. data/app/views/locomotive/editable_elements/index.html.haml +8 -2
  64. data/app/views/locomotive/editable_elements/index_without_preview.html.haml +33 -0
  65. data/app/views/locomotive/layouts/{preview.html.haml → live_editing.html.haml} +9 -9
  66. data/app/views/locomotive/my_account/form/_main.html.haml +1 -1
  67. data/app/views/locomotive/pages/form/_actions.html.haml +8 -1
  68. data/app/views/locomotive/pages/form/_main.html.haml +1 -1
  69. data/app/views/locomotive/pages/form/_tabs.html.haml +2 -2
  70. data/app/views/locomotive/pages/new.html.haml +1 -1
  71. data/app/views/locomotive/shared/header/_site.html.haml +1 -1
  72. data/app/views/locomotive/shared/rte/_image_popover.html.haml +2 -2
  73. data/app/views/locomotive/shared/rte/_link_popover.html.haml +1 -1
  74. data/app/views/locomotive/shared/sidebar/_page.html.haml +5 -2
  75. data/config/locales/admin_ui.en.yml +10 -16
  76. data/config/locales/inputs.en.yml +18 -11
  77. data/config/locales/simple_form.en.yml +13 -1
  78. data/config/routes.rb +3 -1
  79. data/lib/locomotive.rb +1 -1
  80. data/lib/locomotive/action_controller/responder.rb +16 -0
  81. data/lib/locomotive/carrierwave/patches.rb +54 -0
  82. data/lib/locomotive/dependencies.rb +1 -0
  83. data/lib/locomotive/engine.rb +9 -3
  84. data/lib/locomotive/middlewares.rb +1 -1
  85. data/lib/locomotive/middlewares/page_editing.rb +41 -0
  86. data/lib/locomotive/middlewares/site.rb +2 -0
  87. data/lib/locomotive/simple_form.rb +6 -5
  88. data/lib/locomotive/steam_adaptor.rb +2 -0
  89. data/lib/locomotive/version.rb +1 -1
  90. data/lib/tasks/development.rake +4 -0
  91. data/spec/dummy/config/environments/production.rb +2 -0
  92. data/spec/dummy/config/initializers/devise.rb +2 -0
  93. data/spec/dummy/config/mongoid.yml +2 -2
  94. data/spec/models/locomotive/content_entry_spec.rb +11 -2
  95. data/spec/support/factories.rb +0 -1
  96. data/vendor/assets/javascripts/locomotive/history.js +2122 -0
  97. data/vendor/assets/javascripts/locomotive/subscribe.js +206 -329
  98. metadata +44 -127
  99. data/lib/locomotive/middlewares/permalink.rb +0 -22
  100. data/lib/locomotive/previous_liquid/asset_host.rb +0 -51
  101. data/lib/locomotive/previous_liquid/drops/base.rb +0 -40
  102. data/lib/locomotive/previous_liquid/drops/content_entry.rb +0 -78
  103. data/lib/locomotive/previous_liquid/drops/content_types.rb +0 -119
  104. data/lib/locomotive/previous_liquid/drops/current_user.rb +0 -21
  105. data/lib/locomotive/previous_liquid/drops/page.rb +0 -115
  106. data/lib/locomotive/previous_liquid/drops/proxy_collection.rb +0 -64
  107. data/lib/locomotive/previous_liquid/drops/session_proxy.rb +0 -16
  108. data/lib/locomotive/previous_liquid/drops/site.rb +0 -29
  109. data/lib/locomotive/previous_liquid/drops/uploader.rb +0 -21
  110. data/lib/locomotive/previous_liquid/errors.rb +0 -8
  111. data/lib/locomotive/previous_liquid/filters/base.rb +0 -61
  112. data/lib/locomotive/previous_liquid/filters/date.rb +0 -82
  113. data/lib/locomotive/previous_liquid/filters/html.rb +0 -117
  114. data/lib/locomotive/previous_liquid/filters/misc.rb +0 -75
  115. data/lib/locomotive/previous_liquid/filters/resize.rb +0 -18
  116. data/lib/locomotive/previous_liquid/filters/text.rb +0 -53
  117. data/lib/locomotive/previous_liquid/filters/translate.rb +0 -38
  118. data/lib/locomotive/previous_liquid/patches.rb +0 -21
  119. data/lib/locomotive/previous_liquid/tags/consume.rb +0 -104
  120. data/lib/locomotive/previous_liquid/tags/csrf.rb +0 -40
  121. data/lib/locomotive/previous_liquid/tags/editable.rb +0 -4
  122. data/lib/locomotive/previous_liquid/tags/editable/base.rb +0 -88
  123. data/lib/locomotive/previous_liquid/tags/editable/control.rb +0 -41
  124. data/lib/locomotive/previous_liquid/tags/editable/file.rb +0 -43
  125. data/lib/locomotive/previous_liquid/tags/editable/text.rb +0 -79
  126. data/lib/locomotive/previous_liquid/tags/extends.rb +0 -47
  127. data/lib/locomotive/previous_liquid/tags/fetch_page.rb +0 -36
  128. data/lib/locomotive/previous_liquid/tags/google_analytics.rb +0 -39
  129. data/lib/locomotive/previous_liquid/tags/hybrid.rb +0 -25
  130. data/lib/locomotive/previous_liquid/tags/inherited_block.rb +0 -31
  131. data/lib/locomotive/previous_liquid/tags/inline_editor.rb +0 -40
  132. data/lib/locomotive/previous_liquid/tags/javascript.rb +0 -16
  133. data/lib/locomotive/previous_liquid/tags/link_to.rb +0 -43
  134. data/lib/locomotive/previous_liquid/tags/locale_switcher.rb +0 -83
  135. data/lib/locomotive/previous_liquid/tags/model_form.rb +0 -75
  136. data/lib/locomotive/previous_liquid/tags/nav.rb +0 -164
  137. data/lib/locomotive/previous_liquid/tags/paginate.rb +0 -114
  138. data/lib/locomotive/previous_liquid/tags/path_helper.rb +0 -85
  139. data/lib/locomotive/previous_liquid/tags/path_to.rb +0 -21
  140. data/lib/locomotive/previous_liquid/tags/seo.rb +0 -72
  141. data/lib/locomotive/previous_liquid/tags/session_assign.rb +0 -39
  142. data/lib/locomotive/previous_liquid/tags/snippet.rb +0 -75
  143. data/lib/locomotive/previous_liquid/tags/with_scope.rb +0 -65
  144. data/spec/fixtures/portfolio/Gemfile +0 -21
  145. data/spec/fixtures/portfolio/app/content_types/messages.yml +0 -57
  146. data/spec/fixtures/portfolio/app/content_types/projects.yml +0 -74
  147. data/spec/fixtures/portfolio/app/views/pages/404.liquid.haml +0 -10
  148. data/spec/fixtures/portfolio/app/views/pages/index.liquid.haml +0 -213
  149. data/spec/fixtures/portfolio/app/views/snippets/footer.liquid.haml +0 -2
  150. data/spec/fixtures/portfolio/config.ru +0 -3
  151. data/spec/fixtures/portfolio/config/deploy.yml +0 -18
  152. data/spec/fixtures/portfolio/config/site.yml +0 -33
  153. data/spec/fixtures/portfolio/config/translations.yml +0 -8
  154. data/spec/fixtures/portfolio/data/messages.yml +0 -1
  155. data/spec/fixtures/portfolio/data/projects.yml +0 -41
  156. data/spec/fixtures/portfolio/icon.png +0 -0
  157. data/spec/fixtures/portfolio/public/javascripts/bootstrap.min.js +0 -6
  158. data/spec/fixtures/portfolio/public/javascripts/cbpAnimatedHeader.js +0 -44
  159. data/spec/fixtures/portfolio/public/javascripts/cbpAnimatedHeader.min.js +0 -11
  160. data/spec/fixtures/portfolio/public/javascripts/classie.js +0 -80
  161. data/spec/fixtures/portfolio/public/javascripts/contact_me.js +0 -65
  162. data/spec/fixtures/portfolio/public/javascripts/freelancer.js +0 -37
  163. data/spec/fixtures/portfolio/public/javascripts/jqBootstrapValidation.js +0 -912
  164. data/spec/fixtures/portfolio/public/samples/portfolio/cabin.png +0 -0
  165. data/spec/fixtures/portfolio/public/samples/portfolio/cake.png +0 -0
  166. data/spec/fixtures/portfolio/public/samples/portfolio/circus.png +0 -0
  167. data/spec/fixtures/portfolio/public/samples/portfolio/game.png +0 -0
  168. data/spec/fixtures/portfolio/public/samples/portfolio/safe.png +0 -0
  169. data/spec/fixtures/portfolio/public/samples/portfolio/submarine.png +0 -0
  170. data/spec/fixtures/portfolio/public/samples/profile.png +0 -0
  171. data/spec/fixtures/portfolio/public/stylesheets/bootstrap.min.css +0 -7
  172. data/spec/fixtures/portfolio/public/stylesheets/freelancer.css +0 -445
  173. data/spec/lib/locomotive/liquid/tags/editable/file_spec.rb +0 -72
  174. data/spec/lib/locomotive/liquid/tags/editable/text_spec.rb +0 -85
  175. data/spec/lib/locomotive/liquid/tags/extends_spec.rb +0 -58
  176. data/vendor/assets/javascripts/locomotive/editable_field.js +0 -50
  177. data/vendor/assets/javascripts/locomotive/form_submit_notification.js +0 -39
  178. data/vendor/assets/javascripts/locomotive/slugify.js +0 -47
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 10adf1633c36bc535a1fee5de2d222f04b412144
4
- data.tar.gz: 941c8279d7f786e77f16a659745c9d3c74166172
3
+ metadata.gz: d4e648a311d3ce09779e9d4fed45788a010785e6
4
+ data.tar.gz: 27930ac44850b8afc52dc064057092c20433212a
5
5
  SHA512:
6
- metadata.gz: b1023a316c88d96e7eb64e5b77c88027e1071f9b536fdd59d8db139a85f86160c44b8245f70829bd1fa8a91241dcc9bf4b6d87d10d9ad17298a99b11277367e3
7
- data.tar.gz: bfd4756b7844f6013e639960b21a4ce8461a32b2c9af5cb6332d8a40abdf93eb294435975523a5d78173c491a7b9d120948e21f58b74fec81261235e7d58ec4d
6
+ metadata.gz: a199883b73bc3ba82d6e103bd9afbd6a1f87c7d3819dc38b78af40f869d699a353cfb9b5f0bbeceffbe0f6884ec3c07935f321635fc45e3d84e6c0501fa32be6
7
+ data.tar.gz: be98674b892846c91b6001dc6fd17e8d85b90b4e2b24737acefee63f9db30b116612b356ab66618a67d4a4f8ba17a6700c2f4fe8283e34744613317281558336
data/Gemfile CHANGED
@@ -22,7 +22,7 @@ group :development do
22
22
  # gem 'custom_fields', github: 'locomotivecms/custom_fields', ref: '15cceb66ed'
23
23
 
24
24
  # gem 'locomotivecms_steam', path: '../in_progress/steam', require: false
25
- # gem 'locomotivecms_steam', github: 'locomotivecms/steam', ref: '7e41d29d6a', require: false
25
+ # gem 'locomotivecms_steam', github: 'locomotivecms/steam', ref: 'c56798fc5d4a332', require: false
26
26
 
27
27
  # gem 'locomotive-aloha-rails', path: '../gems/aloha-rails' # for Developers
28
28
  # gem 'locomotive-tinymce-rails', path: '../gems/tinymce-rails' # for Developers
@@ -42,7 +42,8 @@ group :development do
42
42
  gem 'binding_of_caller'
43
43
 
44
44
  # gem 'unicorn-rails' # Using unicorn_rails instead of webrick (default server)
45
- gem 'thin'
45
+ # gem 'thin'
46
+ gem 'puma'
46
47
  end
47
48
 
48
49
  group :test do
data/README.md CHANGED
@@ -18,7 +18,7 @@ Visit the Locomotive official website [here](http://www.locomotivecms.com) for m
18
18
 
19
19
  As you can see from the commit logs, we are intensively working on the new V3 version. We kept all the features from our stable [v2 version](https://github.com/locomotivecms/engine/tree/v2.5.x), we just replace the UI, upgrade the gems and refactor our code.
20
20
 
21
- **[UPDATES]** Finally, we've been doing much more than we planed at first. We extracted the rendering functionality from the Engine and make it a gem named [Steam](https://github.com/locomotivecms/steam). This gem is also now used by [Wagon](https://github.com/locomotivecms/wagon) (version 2.0 in progress) which makes sure you get the same result between Wagon and Engine when you preview a page.
21
+ **[UPDATES]** Finally, we've been doing much more than we planned at first. We extracted the rendering functionality from the Engine and make it a gem named [Steam](https://github.com/locomotivecms/steam). This gem is also now used by [Wagon](https://github.com/locomotivecms/wagon) (version 2.0 in progress) which makes sure you get the same result between Wagon and Engine when you preview a page.
22
22
  And last but not least, we added a Ruby API client for Locomotive that we called [Coal](https://github.com/locomotivecms/coal). That client consumes the API from Engine which embeds now GrapeAPI. [Nic Boie](https://github.com/boie0025) is in charge of it. Kudos to him!
23
23
 
24
24
  **TRELLO** [here](https://trello.com/b/kRiy1dZu/locomotive-v3)
@@ -4,6 +4,19 @@ module Locomotive
4
4
 
5
5
  class MembershipForm < BaseForm
6
6
  attrs :account_id, :role
7
+
8
+ attr_accessor :site
9
+ attr_reader :account_email
10
+
11
+ def initialize(site, attributes = {})
12
+ self.site = site
13
+ super(attributes)
14
+ end
15
+
16
+ def account_email=(email)
17
+ self.account_id = Account.find_by(email: email).try(:_id)
18
+ @account_email = email
19
+ end
7
20
  end
8
21
 
9
22
  end
@@ -13,7 +13,7 @@ module Locomotive
13
13
  end
14
14
 
15
15
  desc 'Index of memberships'
16
- get :index do
16
+ get do
17
17
  authorize(memberships, :index?)
18
18
 
19
19
  present memberships, with: entity_klass
@@ -38,12 +38,13 @@ module Locomotive
38
38
  requires :membership, type: Hash do
39
39
  optional :role
40
40
  optional :account_id
41
+ optional :account_email
41
42
  end
42
43
  end
43
44
  post do
44
45
  authorize Membership, :create?
45
46
 
46
- form = form_klass.new(membership_params)
47
+ form = form_klass.new(current_site, membership_params)
47
48
  persist_from_form(form)
48
49
 
49
50
  present membership, with: entity_klass, policy: current_policy
@@ -60,7 +61,8 @@ module Locomotive
60
61
  end
61
62
  put ':id' do
62
63
  authorize membership, :update?
63
- form = form_klass.new(membership_params)
64
+
65
+ form = form_klass.new(current_site, membership_params)
64
66
  persist_from_form(form)
65
67
 
66
68
  present membership, with: entity_klass
@@ -12,6 +12,8 @@
12
12
  //= require backbone
13
13
  //= require codemirror
14
14
  //= require select2
15
+ //= require nprogress
16
+ //= require nprogress-ajax
15
17
  //= require locomotive/vendor
16
18
  //= require ./locomotive/application
17
19
 
@@ -1,6 +1,20 @@
1
- # https://github.com/jashkenas/backbone/issues/2822
1
+
2
2
  View = Backbone.View
3
+
3
4
  Backbone.View = View.extend
5
+ # https://github.com/jashkenas/backbone/issues/2822
4
6
  constructor: (options) ->
5
7
  @options = options || {}
6
8
  View.apply(@, arguments)
9
+
10
+ replace: ($new_el) ->
11
+ $(@el).hide()
12
+
13
+ $new_el.insertAfter($(@el))
14
+
15
+ _view = new @constructor(el: $new_el)
16
+ _view.render()
17
+
18
+ @remove()
19
+
20
+ _view
@@ -0,0 +1,20 @@
1
+ (->
2
+ window.remote_file_to_base64 = (url, callback) ->
3
+ xhr = new XMLHttpRequest()
4
+ xhr.open('GET', url, true)
5
+ xhr.responseType = 'blob'
6
+
7
+ xhr.onload = (event) ->
8
+ if this.status == 200
9
+ blob = this.response
10
+
11
+ reader = new window.FileReader()
12
+ reader.readAsDataURL(blob)
13
+ reader.onloadend = -> callback(reader.result)
14
+ else
15
+ callback(null)
16
+
17
+ xhr.onerror = (event) -> callback(null)
18
+
19
+ xhr.send()
20
+ )()
@@ -0,0 +1,5 @@
1
+ NProgress.configure
2
+ showSpinner: false
3
+ ease: 'ease'
4
+ speed: 500
5
+ parent: '.content'
@@ -1,3 +1,5 @@
1
+ # Feature: Confirm on action
2
+
1
3
  $.rails.safe_confirm = (question) ->
2
4
  prompt(question.question) == question.answer
3
5
 
@@ -18,3 +20,37 @@ $.rails.allowAction = (element) ->
18
20
  callback = $.rails.fire(element, 'confirm:complete', [answer])
19
21
 
20
22
  answer && callback
23
+
24
+ # Feature: AJAX File upload
25
+ # Enhance the form: upload files in AJAX without monkey patching jQuery-UJS
26
+ # Information: https://github.com/rails/jquery-ujs/issues/374
27
+ $.rails.ajax = (options) ->
28
+ if _.isArray(options.data) # FormData
29
+ $.ajax(_.extend(options, contentType: false))
30
+ else
31
+ $.ajax(options)
32
+
33
+ $ ->
34
+ # Tell the server to return flash messages in the header of the response
35
+ $('body').delegate $.rails.formSubmitSelector, 'ajax:beforeSend', (event, xhr, settings) ->
36
+ xhr.setRequestHeader('X-Flash', true)
37
+
38
+ # Once we receive the response from the server, we display a notification
39
+ # and also reset the submit button to its initial state (bootstrap)
40
+ $('body').delegate $.rails.formSubmitSelector, 'ajax:complete', (event, xhr, status) ->
41
+ $(this).find('button[type=submit], input[type=submit]').button('reset')
42
+
43
+ if message = xhr.getResponseHeader('X-Message')
44
+ type = if status == 'success' then 'success' else 'error'
45
+ Locomotive.notify decodeURIComponent($.parseJSON(message)), type
46
+
47
+ # We do not want forms to be aborted because of a file input
48
+ $('body').delegate $.rails.formSubmitSelector, 'ajax:aborted:file', (element) ->
49
+ $.rails.handleRemote($(this))
50
+ false
51
+
52
+ # Use the "new" FormData object (HTML5) to store the data, especially the uploaded files
53
+ $('body').delegate $.rails.formSubmitSelector, 'ajax:beforeSend', (event, xhr, settings) ->
54
+ settings.data = new FormData($(this)[0])
55
+ $(this).find('input[type=file]').each -> settings.data.append($(this).attr('name'), this.files[0])
56
+ true
@@ -30,7 +30,7 @@ wysihtml5.commands.strike =
30
30
  console.log "[insertFile] exec(#{command}, #{param})"
31
31
 
32
32
  state: (composer, command) ->
33
- console.log "[insertFile] state(#{command})"
33
+ # console.log "[insertFile] state(#{command})"
34
34
  wysihtml5.commands.insertImage.state(composer, command, "IMG")
35
35
  # wysihtml5.commands.formatBlock.state(composer, "formatBlock", null, CLASS_NAME, REG_EXP)
36
36
 
@@ -17,9 +17,6 @@ class Locomotive.Views.ContentAssets.PickerView extends Backbone.View
17
17
  'a.refresh'
18
18
  ]
19
19
 
20
- initialize: ->
21
- @editor = @options.parent_view.editor
22
-
23
20
  render: ->
24
21
  console.log '[PickerView] rendering'
25
22
 
@@ -39,21 +36,17 @@ class Locomotive.Views.ContentAssets.PickerView extends Backbone.View
39
36
 
40
37
  select: (event) ->
41
38
  console.log '[PickerView] select'
42
- event.stopPropagation() & event.preventDefault()
43
39
 
44
- $link = $(event.target)
45
- title = $link.attr('title')
46
- url = $link.attr('href')
40
+ event.stopPropagation() & event.preventDefault()
47
41
 
48
- if $link.data('image')
49
- @editor.composer.commands.exec 'insertImage',
50
- src: url
51
- title: title
52
- else
53
- html = "<a href='#{url}' title='#{title}'>#{title}</a>"
54
- @editor.composer.commands.exec 'insertHTML', html
42
+ $link = $(event.target)
55
43
 
56
- @options.parent_view.hide()
44
+ PubSub.publish 'file_picker.select',
45
+ parent_view: @options.parent_view
46
+ image: $link.data('image')
47
+ title: $link.attr('title')
48
+ url: $link.attr('href')
49
+ filename: $link.attr('href').split(/[\\/]/).pop()
57
50
 
58
51
  open_edit_drawer: (event) ->
59
52
  console.log '[PickerView] open_edit_drawer'
@@ -69,8 +62,7 @@ class Locomotive.Views.ContentAssets.PickerView extends Backbone.View
69
62
  hide_from_drawer: (stack_size) ->
70
63
  console.log '[PickerView] hide_from_drawer'
71
64
  # we might need to re-open this view further
72
- if @options.parent_view && stack_size == 0
73
- @options.parent_view.opened.picker = false
65
+ @options.parent_view.hide_from_picker(stack_size) if @options.parent_view && @options.parent_view.hide_from_picker
74
66
 
75
67
  remove: ->
76
68
  console.log '[PickerView] remove'
@@ -0,0 +1,39 @@
1
+ Locomotive.Views.EditableElements ||= {}
2
+
3
+ class Locomotive.Views.EditableElements.EditView extends Locomotive.Views.Shared.FormView
4
+
5
+ el: '.content > .inner'
6
+
7
+ render: ->
8
+ super
9
+
10
+ $('form.edit_page').on 'ajax:success', (event, data, status, xhr) =>
11
+ if @need_reload?
12
+ window.location.reload()
13
+ else
14
+ @refresh_inputs $(data)
15
+
16
+ $('.info-row select[name=block]').select2().on 'change', (event) =>
17
+ @filter_elements_by(event.val)
18
+
19
+ # editable control elements
20
+ $('.editable-elements .form-group.input.select select').select2().on 'change', (event) =>
21
+ @need_reload = true
22
+
23
+ refresh_inputs: ($html) ->
24
+ @inputs = _.map @inputs, (view) =>
25
+ return view unless view.need_refresh?
26
+
27
+ dom_id = $(view.el).attr('id')
28
+ $new_el = $html.find("##{dom_id}")
29
+
30
+ view.replace $new_el if $new_el.size() > 0
31
+
32
+ filter_elements_by: (block) ->
33
+ @$('.editable-elements .form-group.input').each ->
34
+ $el = $(this)
35
+
36
+ if block == '' || (block == '_unknown' && $el.data('block') == '') || $el.data('block') == block
37
+ $el.parent().show()
38
+ else
39
+ $el.parent().hide()
@@ -2,4 +2,107 @@ Locomotive.Views.EditableElements ||= {}
2
2
 
3
3
  class Locomotive.Views.EditableElements.IndexView extends Backbone.View
4
4
 
5
- el: '#content'
5
+ el: '.wrapper'
6
+
7
+ events:
8
+ 'click .expand-button': 'expand_preview'
9
+ 'click .close-button': 'shrink_preview'
10
+
11
+ expand_preview: (event) ->
12
+ $('body').addClass('full-width-preview')
13
+
14
+ shrink_preview: (event) ->
15
+ $('body').removeClass('full-width-preview')
16
+
17
+ initialize: ->
18
+ _.bindAll(@, 'refresh_elements', 'refresh_image', 'refresh_image_on_remove', 'refresh_text')
19
+
20
+ view_options = if $('body').hasClass('live-editing') then {} else { el: '.main' }
21
+
22
+ @edit_view = new Locomotive.Views.EditableElements.EditView(view_options)
23
+ @pubsub_text_token = PubSub.subscribe('inputs.text_changed', @refresh_text)
24
+
25
+ @pubsub_image_changed_token = PubSub.subscribe('inputs.image_changed', @refresh_image)
26
+ @pubsub_image_removed_token = PubSub.subscribe('inputs.image_removed', @refresh_image_on_remove)
27
+
28
+ $('.preview iframe').load (event) => @on_iframe_load(event)
29
+
30
+ render: ->
31
+ super()
32
+ @edit_view.render()
33
+
34
+ refresh_elements: (type, view, callback) ->
35
+ $parent_view = $(view.el).parent()
36
+ element_id = $parent_view.find('input[name*="[humanized_id]"]').val().replace(/_/g, '-')
37
+ dom_id = "locomotive-editable-#{type}-#{element_id}"
38
+
39
+ $iframe_document = $($('iframe')[0].contentWindow.document)
40
+
41
+ callback($iframe_document.find("##{dom_id}"), dom_id, $iframe_document)
42
+
43
+ refresh_image_on_remove: (msg, data) ->
44
+ data.url = $(data.view.el).parent().find('input[name*="[default_source_url]"]').val()
45
+ @refresh_image(msg, data)
46
+
47
+ refresh_image: (msg, data) ->
48
+ @refresh_elements 'image', data.view, ($elements, dom_id, $iframe_document) ->
49
+ current_image_url = data.view.$('input[name*="[content]"]').val()
50
+ image_url = data.url || current_image_url
51
+
52
+ if $elements.size() > 0
53
+ $elements.each ->
54
+ if this.nodeName == 'IMG'
55
+ $(this).attr('src', image_url)
56
+ else
57
+ $(this).css("background-image", "url('" + image_url + "')")
58
+ else
59
+ # looking for DIVs with background-url property matching the previous image url
60
+ $el = $iframe_document.find("*[style*='#{current_image_url}']").attr('id', dom_id)
61
+ $el.css("background-image", "url('" + image_url + "')")
62
+
63
+ # looking for IMGs with src attribute matching the previous image url
64
+ $el = $iframe_document.find("img[src*='#{current_image_url}']").attr('id', dom_id)
65
+ $el.attr('src', image_url)
66
+
67
+ refresh_text: (msg, data) ->
68
+ @refresh_elements 'text', data.view, ($elements) ->
69
+ $elements.each -> $(this).html(data.content)
70
+
71
+ on_iframe_load: (event) ->
72
+ $iframe = $('.preview iframe')
73
+ $target_window = $iframe[0].contentWindow
74
+ editable_elements_path = null
75
+
76
+ # unable to display the iframe in the frame because it set 'X-Frame-Options' to 'SAMEORIGIN'
77
+ try
78
+ $iframe_document = $($target_window.document)
79
+ editable_elements_path = $iframe_document.find('meta[name=locomotive-editable-elements-path]').attr('content')
80
+ catch e
81
+ # reload the iframe with the previous url and display an error message
82
+ $iframe.attr('src', @preview_url)
83
+ Locomotive.notify $iframe.data('redirection-error'), 'warning'
84
+ return
85
+
86
+ # store the url
87
+ @preview_url = $('.preview iframe')[0].contentWindow.document.location.href
88
+
89
+ if editable_elements_path?
90
+ unless editable_elements_path == (window.location.pathname + window.location.search)
91
+ History.replaceState({ live_editing: true, url: @preview_url }, '', editable_elements_path)
92
+
93
+ @replace_edit_view(editable_elements_path)
94
+
95
+ replace_edit_view: (url) ->
96
+ $(@edit_view.el).load url, =>
97
+ @edit_view.remove()
98
+ @edit_view = new Locomotive.Views.EditableElements.EditView()
99
+ @edit_view.render()
100
+
101
+ remove: ->
102
+ super
103
+
104
+ @edit_view.remove()
105
+
106
+ PubSub.unsubscribe(@pubsub_image_changed_token)
107
+ PubSub.unsubscribe(@pubsub_image_removed_token)
108
+ PubSub.unsubscribe(@pubsub_text_token)
@@ -6,34 +6,78 @@ class Locomotive.Views.Inputs.FileView extends Backbone.View
6
6
  'change input[type=file]': 'change_file'
7
7
  'click a.choose': 'begin_choose_file'
8
8
  'click a.change': 'begin_change_file'
9
+ 'click a.content-assets': 'open_content_assets_drawer'
9
10
  'click a.cancel': 'cancel_new_file'
10
11
  'click a.delete': 'mark_file_as_deleted'
11
12
 
12
13
  initialize: ->
14
+ _.bindAll(@, 'use_content_asset')
15
+
13
16
  @$file = @$('input[type=file]')
14
- @$remove_file = @$('input[type=hidden]')
17
+ @$remove_file = @$('input[type=hidden].remove')
18
+ @$remote_url = @$('input[type=hidden].remote-url')
15
19
  @$current_file = @$('.current-file')
16
20
  @$no_file = @$('.no-file')
17
21
  @$new_file = @$('.new-file')
18
22
 
19
- @$choose_btn = @$('.buttons .choose')
20
- @$change_btn = @$('.buttons .change')
23
+ @$choose_btn = @$('.buttons > .choose')
24
+ @$change_btn = @$('.buttons > .change')
21
25
  @$cancel_btn = @$('.buttons .cancel')
22
26
  @$delete_btn = @$('.buttons .delete')
23
27
 
24
28
  @persisted_file = @$('.row').data('persisted-file')
25
29
 
26
- render: ->
27
- # do nothing
30
+ @pubsub_token = PubSub.subscribe 'file_picker.select', @use_content_asset
31
+
32
+ begin_change_file: -> @$file.click()
33
+ begin_choose_file: -> @$file.click()
34
+
35
+ open_content_assets_drawer: (event) ->
36
+ event.stopPropagation() & event.preventDefault()
37
+
38
+ $(event.target).closest('.btn-group').removeClass('open')
39
+
40
+ window.application_view.drawer_view.open(
41
+ $(event.target).attr('href'),
42
+ Locomotive.Views.ContentAssets.PickerView,
43
+ { parent_view: @ })
44
+
45
+ use_content_asset: (msg, data) ->
46
+ return unless data.parent_view.cid == @.cid
28
47
 
29
- begin_change_file: ->
30
- @$file.click()
48
+ window.application_view.drawer_view.close()
31
49
 
32
- begin_choose_file: ->
33
- @$file.click()
50
+ url = @absolute_url(data.url)
51
+
52
+ window.remote_file_to_base64 url, (base64) =>
53
+ if base64
54
+ @update_ui_on_changing_file(data.title)
55
+
56
+ # add the filename to the base64 string
57
+ base64 = base64.replace(';base64,', ";#{data.filename};base64,")
58
+
59
+ @$remote_url.val(base64)
60
+
61
+ if data.image
62
+ @$new_file.html("<img src='#{url}' /> #{@$new_file.html()}")
63
+
64
+ PubSub.publish 'inputs.image_changed', { view: @, url: url }
65
+ else
66
+ Locomotive.notify 'Unable to load the asset', 'error'
34
67
 
35
68
  change_file: (event) ->
36
- text = if event.target.files then event.target.files[0].name else 'New file'
69
+ file = if event.target.files then event.target.files[0] else null
70
+ text = if file? then file.name else 'New file'
71
+
72
+ @update_ui_on_changing_file(text)
73
+
74
+ if file.type.match('image.*')
75
+ @image_to_base_64 file, (base64) =>
76
+ @$new_file.html("<img src='#{base64}' /> #{@$new_file.html()}")
77
+
78
+ PubSub.publish 'inputs.image_changed', { view: @, url: base64, file: file }
79
+
80
+ update_ui_on_changing_file: (text) ->
37
81
  @$new_file.html(text)
38
82
 
39
83
  # show new file, hide the current one
@@ -46,6 +90,9 @@ class Locomotive.Views.Inputs.FileView extends Backbone.View
46
90
  # hide the new file
47
91
  @hideEl(@$new_file)
48
92
 
93
+ # reset remote url
94
+ @$remote_url.val('')
95
+
49
96
  # reset the file input
50
97
  @$file.wrap('<form>').closest('form').get(0).reset()
51
98
  @$file.unwrap()
@@ -71,6 +118,8 @@ class Locomotive.Views.Inputs.FileView extends Backbone.View
71
118
  # display the choose button
72
119
  @showEl(@$choose_btn)
73
120
 
121
+ PubSub.publish 'inputs.image_changed', { view: @ }
122
+
74
123
  mark_file_as_deleted: (event) ->
75
124
  # set true (or 1) as value for the remove_<method> hidden field
76
125
  @$remove_file.val('1')
@@ -81,5 +130,25 @@ class Locomotive.Views.Inputs.FileView extends Backbone.View
81
130
  # hide the change / delete buttons, show the cancel button
82
131
  @hideEl(@$change_btn) && @hideEl(@$delete_btn) && @showEl(@$cancel_btn)
83
132
 
133
+ PubSub.publish 'inputs.image_removed', { view: @ }
134
+
135
+ image_to_base_64: (file, callback) ->
136
+ reader = new FileReader()
137
+ reader.onload = (e) -> callback(e.target.result)
138
+ reader.readAsDataURL(file)
139
+
140
+ absolute_url: (url) ->
141
+ return url if url.indexOf('http') == 0
142
+
143
+ http = location.protocol
144
+ slashes = http.concat("//")
145
+ slashes.concat(window.location.host).concat(url)
146
+
84
147
  showEl: (el) -> el.removeClass('hide')
85
148
  hideEl: (el) -> el.addClass('hide')
149
+
150
+ need_refresh: -> true
151
+
152
+ remove: ->
153
+ super
154
+ PubSub.unsubscribe(@pubsub_token)