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.
- checksums.yaml +4 -4
- data/Gemfile +3 -2
- data/README.md +1 -1
- data/app/api/locomotive/api/forms/membership_form.rb +13 -0
- data/app/api/locomotive/api/resources/membership_resource.rb +5 -3
- data/app/assets/javascripts/locomotive.js +2 -0
- data/app/assets/javascripts/locomotive/utils/backbone_patches.js.coffee +15 -1
- data/app/assets/javascripts/locomotive/utils/file.js.coffee +20 -0
- data/app/assets/javascripts/locomotive/utils/nprogress.js.coffee +5 -0
- data/app/assets/javascripts/locomotive/utils/rails_ujs.js.coffee +36 -0
- data/app/assets/javascripts/locomotive/utils/wysihtml5.js.coffee +1 -1
- data/app/assets/javascripts/locomotive/views/content_assets/picker_view.js.coffee +9 -17
- data/app/assets/javascripts/locomotive/views/editable_elements/edit_view.js.coffee +39 -0
- data/app/assets/javascripts/locomotive/views/editable_elements/index_view.js.coffee +104 -1
- data/app/assets/javascripts/locomotive/views/inputs/file_view.js.coffee +79 -10
- data/app/assets/javascripts/locomotive/views/inputs/rte/file_view.js.coffee +24 -4
- data/app/assets/javascripts/locomotive/views/inputs/rte_view.js.coffee.erb +18 -0
- data/app/assets/javascripts/locomotive/views/pages/new_view.js.coffee +3 -6
- data/app/assets/javascripts/locomotive/views/shared/drawer_view.js.coffee +24 -8
- data/app/assets/javascripts/locomotive/views/shared/form_view.js.coffee +21 -148
- data/app/assets/stylesheets/locomotive/application.scss +6 -0
- data/app/assets/stylesheets/locomotive/base/_form.scss +1 -0
- data/app/assets/stylesheets/locomotive/base/form/_base.scss +9 -0
- data/app/assets/stylesheets/locomotive/base/form/_file_input.scss +1 -1
- data/app/assets/stylesheets/locomotive/base/form/_link.scss +13 -0
- data/app/assets/stylesheets/locomotive/base/form/_select2.scss +28 -1
- data/app/assets/stylesheets/locomotive/components/_drawer.scss +8 -18
- data/app/assets/stylesheets/locomotive/components/_live_editing.scss +83 -0
- data/app/assets/stylesheets/locomotive/components/_transitions.scss +63 -1
- data/app/assets/stylesheets/locomotive/components/header/_base.scss +5 -1
- data/app/assets/stylesheets/locomotive/components/misc/_notify.scss +5 -7
- data/app/assets/stylesheets/locomotive/globals/_bootstrap.scss +4 -4
- data/app/assets/stylesheets/locomotive/globals/_mixins.scss +16 -0
- data/app/assets/stylesheets/locomotive/globals/_nprogress.scss +3 -0
- data/app/assets/stylesheets/locomotive/globals/_variables.scss +57 -49
- data/app/assets/stylesheets/locomotive/layouts/_live_editing.scss +29 -0
- data/app/controllers/locomotive/editable_elements_controller.rb +49 -2
- data/app/controllers/locomotive/pages_controller.rb +2 -2
- data/app/helpers/locomotive/custom_fields_helper.rb +1 -1
- data/app/helpers/locomotive/editable_elements_helper.rb +40 -0
- data/app/helpers/locomotive/pages_helper.rb +0 -1
- data/app/inputs/locomotive/array_input.rb +1 -1
- data/app/inputs/locomotive/file_input.rb +35 -7
- data/app/inputs/locomotive/rte_input.rb +2 -1
- data/app/inputs/locomotive/toggle_input.rb +1 -1
- data/app/models/locomotive/concerns/content_entry/localized.rb +4 -4
- data/app/models/locomotive/concerns/content_type/sync.rb +0 -5
- data/app/models/locomotive/concerns/page/redirect.rb +1 -1
- data/app/models/locomotive/content_entry.rb +5 -11
- data/app/models/locomotive/content_type.rb +22 -0
- data/app/models/locomotive/editable_control.rb +12 -27
- data/app/models/locomotive/editable_element.rb +8 -0
- data/app/models/locomotive/editable_file.rb +0 -1
- data/app/models/locomotive/editable_text.rb +10 -10
- data/app/models/locomotive/page.rb +1 -1
- data/app/policies/locomotive/page_policy.rb +1 -1
- data/app/services/locomotive/editable_element_service.rb +47 -0
- data/app/services/locomotive/page_parsing_service.rb +85 -31
- data/app/uploaders/locomotive/editable_file_uploader.rb +5 -1
- data/app/views/locomotive/editable_elements/_edit.html.haml +49 -0
- data/app/views/locomotive/editable_elements/_edit_with_content_entry.html.haml +21 -0
- data/app/views/locomotive/editable_elements/_form.html.haml +23 -0
- data/app/views/locomotive/editable_elements/index.html.haml +8 -2
- data/app/views/locomotive/editable_elements/index_without_preview.html.haml +33 -0
- data/app/views/locomotive/layouts/{preview.html.haml → live_editing.html.haml} +9 -9
- data/app/views/locomotive/my_account/form/_main.html.haml +1 -1
- data/app/views/locomotive/pages/form/_actions.html.haml +8 -1
- data/app/views/locomotive/pages/form/_main.html.haml +1 -1
- data/app/views/locomotive/pages/form/_tabs.html.haml +2 -2
- data/app/views/locomotive/pages/new.html.haml +1 -1
- data/app/views/locomotive/shared/header/_site.html.haml +1 -1
- data/app/views/locomotive/shared/rte/_image_popover.html.haml +2 -2
- data/app/views/locomotive/shared/rte/_link_popover.html.haml +1 -1
- data/app/views/locomotive/shared/sidebar/_page.html.haml +5 -2
- data/config/locales/admin_ui.en.yml +10 -16
- data/config/locales/inputs.en.yml +18 -11
- data/config/locales/simple_form.en.yml +13 -1
- data/config/routes.rb +3 -1
- data/lib/locomotive.rb +1 -1
- data/lib/locomotive/action_controller/responder.rb +16 -0
- data/lib/locomotive/carrierwave/patches.rb +54 -0
- data/lib/locomotive/dependencies.rb +1 -0
- data/lib/locomotive/engine.rb +9 -3
- data/lib/locomotive/middlewares.rb +1 -1
- data/lib/locomotive/middlewares/page_editing.rb +41 -0
- data/lib/locomotive/middlewares/site.rb +2 -0
- data/lib/locomotive/simple_form.rb +6 -5
- data/lib/locomotive/steam_adaptor.rb +2 -0
- data/lib/locomotive/version.rb +1 -1
- data/lib/tasks/development.rake +4 -0
- data/spec/dummy/config/environments/production.rb +2 -0
- data/spec/dummy/config/initializers/devise.rb +2 -0
- data/spec/dummy/config/mongoid.yml +2 -2
- data/spec/models/locomotive/content_entry_spec.rb +11 -2
- data/spec/support/factories.rb +0 -1
- data/vendor/assets/javascripts/locomotive/history.js +2122 -0
- data/vendor/assets/javascripts/locomotive/subscribe.js +206 -329
- metadata +44 -127
- data/lib/locomotive/middlewares/permalink.rb +0 -22
- data/lib/locomotive/previous_liquid/asset_host.rb +0 -51
- data/lib/locomotive/previous_liquid/drops/base.rb +0 -40
- data/lib/locomotive/previous_liquid/drops/content_entry.rb +0 -78
- data/lib/locomotive/previous_liquid/drops/content_types.rb +0 -119
- data/lib/locomotive/previous_liquid/drops/current_user.rb +0 -21
- data/lib/locomotive/previous_liquid/drops/page.rb +0 -115
- data/lib/locomotive/previous_liquid/drops/proxy_collection.rb +0 -64
- data/lib/locomotive/previous_liquid/drops/session_proxy.rb +0 -16
- data/lib/locomotive/previous_liquid/drops/site.rb +0 -29
- data/lib/locomotive/previous_liquid/drops/uploader.rb +0 -21
- data/lib/locomotive/previous_liquid/errors.rb +0 -8
- data/lib/locomotive/previous_liquid/filters/base.rb +0 -61
- data/lib/locomotive/previous_liquid/filters/date.rb +0 -82
- data/lib/locomotive/previous_liquid/filters/html.rb +0 -117
- data/lib/locomotive/previous_liquid/filters/misc.rb +0 -75
- data/lib/locomotive/previous_liquid/filters/resize.rb +0 -18
- data/lib/locomotive/previous_liquid/filters/text.rb +0 -53
- data/lib/locomotive/previous_liquid/filters/translate.rb +0 -38
- data/lib/locomotive/previous_liquid/patches.rb +0 -21
- data/lib/locomotive/previous_liquid/tags/consume.rb +0 -104
- data/lib/locomotive/previous_liquid/tags/csrf.rb +0 -40
- data/lib/locomotive/previous_liquid/tags/editable.rb +0 -4
- data/lib/locomotive/previous_liquid/tags/editable/base.rb +0 -88
- data/lib/locomotive/previous_liquid/tags/editable/control.rb +0 -41
- data/lib/locomotive/previous_liquid/tags/editable/file.rb +0 -43
- data/lib/locomotive/previous_liquid/tags/editable/text.rb +0 -79
- data/lib/locomotive/previous_liquid/tags/extends.rb +0 -47
- data/lib/locomotive/previous_liquid/tags/fetch_page.rb +0 -36
- data/lib/locomotive/previous_liquid/tags/google_analytics.rb +0 -39
- data/lib/locomotive/previous_liquid/tags/hybrid.rb +0 -25
- data/lib/locomotive/previous_liquid/tags/inherited_block.rb +0 -31
- data/lib/locomotive/previous_liquid/tags/inline_editor.rb +0 -40
- data/lib/locomotive/previous_liquid/tags/javascript.rb +0 -16
- data/lib/locomotive/previous_liquid/tags/link_to.rb +0 -43
- data/lib/locomotive/previous_liquid/tags/locale_switcher.rb +0 -83
- data/lib/locomotive/previous_liquid/tags/model_form.rb +0 -75
- data/lib/locomotive/previous_liquid/tags/nav.rb +0 -164
- data/lib/locomotive/previous_liquid/tags/paginate.rb +0 -114
- data/lib/locomotive/previous_liquid/tags/path_helper.rb +0 -85
- data/lib/locomotive/previous_liquid/tags/path_to.rb +0 -21
- data/lib/locomotive/previous_liquid/tags/seo.rb +0 -72
- data/lib/locomotive/previous_liquid/tags/session_assign.rb +0 -39
- data/lib/locomotive/previous_liquid/tags/snippet.rb +0 -75
- data/lib/locomotive/previous_liquid/tags/with_scope.rb +0 -65
- data/spec/fixtures/portfolio/Gemfile +0 -21
- data/spec/fixtures/portfolio/app/content_types/messages.yml +0 -57
- data/spec/fixtures/portfolio/app/content_types/projects.yml +0 -74
- data/spec/fixtures/portfolio/app/views/pages/404.liquid.haml +0 -10
- data/spec/fixtures/portfolio/app/views/pages/index.liquid.haml +0 -213
- data/spec/fixtures/portfolio/app/views/snippets/footer.liquid.haml +0 -2
- data/spec/fixtures/portfolio/config.ru +0 -3
- data/spec/fixtures/portfolio/config/deploy.yml +0 -18
- data/spec/fixtures/portfolio/config/site.yml +0 -33
- data/spec/fixtures/portfolio/config/translations.yml +0 -8
- data/spec/fixtures/portfolio/data/messages.yml +0 -1
- data/spec/fixtures/portfolio/data/projects.yml +0 -41
- data/spec/fixtures/portfolio/icon.png +0 -0
- data/spec/fixtures/portfolio/public/javascripts/bootstrap.min.js +0 -6
- data/spec/fixtures/portfolio/public/javascripts/cbpAnimatedHeader.js +0 -44
- data/spec/fixtures/portfolio/public/javascripts/cbpAnimatedHeader.min.js +0 -11
- data/spec/fixtures/portfolio/public/javascripts/classie.js +0 -80
- data/spec/fixtures/portfolio/public/javascripts/contact_me.js +0 -65
- data/spec/fixtures/portfolio/public/javascripts/freelancer.js +0 -37
- data/spec/fixtures/portfolio/public/javascripts/jqBootstrapValidation.js +0 -912
- data/spec/fixtures/portfolio/public/samples/portfolio/cabin.png +0 -0
- data/spec/fixtures/portfolio/public/samples/portfolio/cake.png +0 -0
- data/spec/fixtures/portfolio/public/samples/portfolio/circus.png +0 -0
- data/spec/fixtures/portfolio/public/samples/portfolio/game.png +0 -0
- data/spec/fixtures/portfolio/public/samples/portfolio/safe.png +0 -0
- data/spec/fixtures/portfolio/public/samples/portfolio/submarine.png +0 -0
- data/spec/fixtures/portfolio/public/samples/profile.png +0 -0
- data/spec/fixtures/portfolio/public/stylesheets/bootstrap.min.css +0 -7
- data/spec/fixtures/portfolio/public/stylesheets/freelancer.css +0 -445
- data/spec/lib/locomotive/liquid/tags/editable/file_spec.rb +0 -72
- data/spec/lib/locomotive/liquid/tags/editable/text_spec.rb +0 -85
- data/spec/lib/locomotive/liquid/tags/extends_spec.rb +0 -58
- data/vendor/assets/javascripts/locomotive/editable_field.js +0 -50
- data/vendor/assets/javascripts/locomotive/form_submit_notification.js +0 -39
- data/vendor/assets/javascripts/locomotive/slugify.js +0 -47
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d4e648a311d3ce09779e9d4fed45788a010785e6
|
4
|
+
data.tar.gz: 27930ac44850b8afc52dc064057092c20433212a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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: '
|
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
|
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
|
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
|
-
|
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
|
@@ -1,6 +1,20 @@
|
|
1
|
-
|
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
|
+
)()
|
@@ -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
|
-
|
45
|
-
title = $link.attr('title')
|
46
|
-
url = $link.attr('href')
|
40
|
+
event.stopPropagation() & event.preventDefault()
|
47
41
|
|
48
|
-
|
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
|
-
|
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 &&
|
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: '
|
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
|
-
|
27
|
-
|
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
|
-
|
30
|
-
@$file.click()
|
48
|
+
window.application_view.drawer_view.close()
|
31
49
|
|
32
|
-
|
33
|
-
|
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
|
-
|
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)
|