the upgrade script v1.1 did not work correctly + fix issue #403 (more generally, enhance the way jQuery modals were used within the back-office) + select the first inverse_of value of a has_many field (UI)
This commit is contained in:
parent
b751e3d990
commit
3a4654e8f7
@ -69,5 +69,7 @@
|
||||
doc.head.appendChild(stylesheet);
|
||||
}
|
||||
|
||||
$.ui.dialog.prototype.overlayEl = function() { return this.overlay.$el; }
|
||||
|
||||
})();
|
||||
|
||||
|
@ -83,3 +83,10 @@ class Locomotive.Views.ApplicationView extends Backbone.View
|
||||
locale = $(@).attr('data-locale')
|
||||
window.addParameterToURL 'content_locale', locale
|
||||
|
||||
unique_dialog_zindex: ->
|
||||
# returns the number of jQuery UI modals created in order to set a valid zIndex for each of them.
|
||||
# Each modal window should have a different zIndex, otherwise there will be conflicts between them.
|
||||
window.Locomotive.jQueryModals ||= 0
|
||||
|
||||
998 + window.Locomotive.jQueryModals++
|
||||
|
||||
|
@ -12,7 +12,10 @@ class Locomotive.Views.ContentAssets.PickerView extends Locomotive.Views.Shared.
|
||||
ich.content_asset_picker
|
||||
|
||||
fetch_assets: ->
|
||||
@collection.fetch()
|
||||
@_reset()
|
||||
@collection.fetch
|
||||
success: () =>
|
||||
@open()
|
||||
|
||||
build_uploader: (el, link) ->
|
||||
link.bind 'click', (event) ->
|
||||
|
@ -70,10 +70,10 @@ class Locomotive.Views.ContentEntries.FormView extends Locomotive.Views.Shared.F
|
||||
|
||||
enable_has_many_fields: ->
|
||||
unless @model.isNew()
|
||||
_.each @model.get('has_many_custom_fields'), (field, index) =>
|
||||
_.each @model.get('has_many_custom_fields'), (field) =>
|
||||
name = field[0]; inverse_of = field[1]
|
||||
new_entry = new Locomotive.Models.ContentEntry(@options["#{name}_new_entry"])
|
||||
view = new Locomotive.Views.Shared.Fields.HasManyView model: @model, name: name, new_entry: new_entry, inverse_of: inverse_of, index: index
|
||||
view = new Locomotive.Views.Shared.Fields.HasManyView model: @model, name: name, new_entry: new_entry, inverse_of: inverse_of
|
||||
|
||||
if view.ui_enabled()
|
||||
@_has_many_field_views.push(view)
|
||||
|
@ -23,17 +23,12 @@ class Locomotive.Views.ContentEntries.PopupFormView extends Locomotive.Views.Con
|
||||
@close()
|
||||
|
||||
create_dialog: ->
|
||||
# FIXME (Did): each modal window should have a different zIndex, otherwise there will be conflicts
|
||||
zIndex = 998 + @options.index
|
||||
|
||||
@dialog = $(@el).dialog
|
||||
autoOpen: false
|
||||
modal: true
|
||||
zIndex: zIndex
|
||||
zIndex: window.application_view.unique_dialog_zindex()
|
||||
width: 770,
|
||||
create: (event, ui) =>
|
||||
$('.ui-widget-overlay').bind 'click', => @close()
|
||||
|
||||
$(@el).prev().find('.ui-dialog-title').html(@$('h2').html())
|
||||
@$('h2').remove()
|
||||
actions = @$('.dialog-actions').appendTo($(@el).parent()).addClass('ui-dialog-buttonpane ui-widget-content ui-helper-clearfix')
|
||||
@ -42,6 +37,7 @@ class Locomotive.Views.ContentEntries.PopupFormView extends Locomotive.Views.Con
|
||||
actions.find('input[type=submit]').click (event) => @save(event)
|
||||
|
||||
open: (event, ui, extra) =>
|
||||
$(@el).dialog('overlayEl').bind 'click', => @close()
|
||||
# nothing to do
|
||||
|
||||
open: ->
|
||||
@ -60,6 +56,7 @@ class Locomotive.Views.ContentEntries.PopupFormView extends Locomotive.Views.Con
|
||||
close: (event) ->
|
||||
event.stopPropagation() & event.preventDefault() if event?
|
||||
@clear_errors()
|
||||
$(@el).dialog('overlayEl').unbind('click')
|
||||
$(@el).dialog('close')
|
||||
|
||||
center: ->
|
||||
|
@ -12,8 +12,6 @@ class Locomotive.Views.ContentTypes.FormView extends Locomotive.Views.Shared.For
|
||||
initialize: ->
|
||||
@model = new Locomotive.Models.ContentType(@options.content_type)
|
||||
|
||||
window.foo = @model
|
||||
|
||||
Backbone.ModelBinding.bind @
|
||||
|
||||
render: ->
|
||||
|
@ -58,11 +58,18 @@ class Locomotive.Views.ContentTypes.CustomFieldEntryView extends Backbone.View
|
||||
fetch_inverse_of_list: ->
|
||||
@$('li.input.inverse-of select option').remove()
|
||||
|
||||
_.each @inverse_of_list[@model.get('type')], (data) =>
|
||||
list = @inverse_of_list[@model.get('type')] || []
|
||||
|
||||
_.each list, (data) =>
|
||||
if data.class_name == @model.get('class_name')
|
||||
option = new Option(data.label, data.name, data.class_name == @model.get('inverse_of') || @inverse_of_list.length == 1)
|
||||
option = new Option(data.label, data.name, data.name == @model.get('inverse_of') || list.length == 1)
|
||||
@$('li.input.inverse-of select').append(option)
|
||||
|
||||
# by default, select the first option
|
||||
if !@model.get('inverse_of')? && list.length > 0
|
||||
@model.set
|
||||
inverse_of: list[0].name
|
||||
|
||||
render_select_options_view: ->
|
||||
@select_options_view = new Locomotive.Views.ContentTypes.SelectOptionsView
|
||||
model: @model
|
||||
|
@ -16,14 +16,14 @@ class Locomotive.Views.Pages.FormView extends Locomotive.Views.Shared.FormView
|
||||
|
||||
@model = new Locomotive.Models.Page(@options.page)
|
||||
|
||||
window.foo = @model
|
||||
|
||||
@touched_url = false
|
||||
|
||||
@image_picker_view = new Locomotive.Views.ThemeAssets.ImagePickerView
|
||||
collection: new Locomotive.Models.ThemeAssetsCollection()
|
||||
on_select: @insert_image
|
||||
|
||||
@image_picker_view.render()
|
||||
|
||||
Backbone.ModelBinding.bind @
|
||||
|
||||
@editable_elements_view = new Locomotive.Views.EditableElements.EditAllView(collection: @model.get('editable_elements'))
|
||||
@ -58,7 +58,7 @@ class Locomotive.Views.Pages.FormView extends Locomotive.Views.Shared.FormView
|
||||
open_image_picker: (event) ->
|
||||
event.stopPropagation() & event.preventDefault()
|
||||
@image_picker_view.editor = @editor
|
||||
@image_picker_view.render()
|
||||
@image_picker_view.fetch_assets()
|
||||
|
||||
insert_image: (path) ->
|
||||
text = "{{ '#{path}' | theme_image_url }}"
|
||||
|
@ -11,11 +11,9 @@ class Locomotive.Views.Shared.AssetPickerView extends Backbone.View
|
||||
@collection.bind('remove', @remove_asset)
|
||||
|
||||
render: ->
|
||||
@_reset()
|
||||
|
||||
$(@el).html(@template()())
|
||||
|
||||
@fetch_assets()
|
||||
@create_dialog()
|
||||
|
||||
return @
|
||||
|
||||
@ -29,34 +27,32 @@ class Locomotive.Views.Shared.AssetPickerView extends Backbone.View
|
||||
# please overide build_uploader
|
||||
|
||||
create_dialog: ->
|
||||
@dialog = $(@el).dialog
|
||||
@dialog ||= $(@el).dialog
|
||||
autoOpen: false
|
||||
modal: true
|
||||
zIndex: 996
|
||||
zIndex: window.application_view.unique_dialog_zindex()
|
||||
width: 650,
|
||||
create: (event, ui) =>
|
||||
$('.ui-widget-overlay').bind 'click', => @close()
|
||||
|
||||
$(@el).prev().find('.ui-dialog-title').html(@$('h2').html())
|
||||
@$('h2').remove()
|
||||
actions = @$('.dialog-actions').appendTo($(@el).parent()).addClass('ui-dialog-buttonpane ui-widget-content ui-helper-clearfix')
|
||||
|
||||
actions.find('#close-link').click (event) => @close(event)
|
||||
|
||||
input = actions.find('input[type=file]')
|
||||
link = actions.find('#upload-link')
|
||||
|
||||
@build_uploader(input, link)
|
||||
|
||||
open: (event, ui, extra) =>
|
||||
actions = $(@el).parent().find('.ui-dialog-buttonpane')
|
||||
el = actions.find('input[type=file]')
|
||||
link = actions.find('#upload-link')
|
||||
|
||||
@build_uploader(el, link)
|
||||
|
||||
@open()
|
||||
$(@el).dialog('overlayEl').bind 'click', => @close()
|
||||
|
||||
open: ->
|
||||
$(@el).dialog('open')
|
||||
|
||||
close: (event) ->
|
||||
event.stopPropagation() & event.preventDefault() if event?
|
||||
$(@el).dialog('overlayEl').unbind('click')
|
||||
$(@el).dialog('close')
|
||||
|
||||
shake: ->
|
||||
@ -71,8 +67,6 @@ class Locomotive.Views.Shared.AssetPickerView extends Backbone.View
|
||||
|
||||
@_refresh()
|
||||
|
||||
setTimeout (=> @create_dialog()), 30 # disable flickering
|
||||
|
||||
add_asset: (asset, first) ->
|
||||
# please overide add_asset (the 'first' param is to know if it comes from the first collection fetch)
|
||||
|
||||
@ -95,6 +89,4 @@ class Locomotive.Views.Shared.AssetPickerView extends Backbone.View
|
||||
_on_refresh: ->
|
||||
|
||||
_reset: ->
|
||||
$('.ui-widget-overlay').unbind 'click'
|
||||
@$('.actions input[type=file]').remove()
|
||||
@dialog.dialog('destroy') if @dialog?
|
||||
# for nothing to do
|
||||
|
@ -70,7 +70,6 @@ class Locomotive.Views.Shared.Fields.HasManyView extends Backbone.View
|
||||
el: $("##{@options.name}-template-entry")
|
||||
parent_view: @
|
||||
model: @options.new_entry.clone() # by default, it does not matter
|
||||
index: @options.index
|
||||
|
||||
@target_entry_view.render()
|
||||
|
||||
|
@ -19,6 +19,8 @@ class Locomotive.Views.Snippets.FormView extends Locomotive.Views.Shared.FormVie
|
||||
collection: new Locomotive.Models.ThemeAssetsCollection()
|
||||
on_select: @insert_image
|
||||
|
||||
@image_picker_view.render()
|
||||
|
||||
Backbone.ModelBinding.bind @
|
||||
|
||||
render: ->
|
||||
@ -38,7 +40,7 @@ class Locomotive.Views.Snippets.FormView extends Locomotive.Views.Shared.FormVie
|
||||
open_image_picker: (event) ->
|
||||
event.stopPropagation() & event.preventDefault()
|
||||
@image_picker_view.editor = @editor
|
||||
@image_picker_view.render()
|
||||
@image_picker_view.fetch_assets()
|
||||
|
||||
insert_image: (path) ->
|
||||
text = "{{ '#{path}' | theme_image_url }}"
|
||||
|
@ -15,10 +15,10 @@ class Locomotive.Views.ThemeAssets.FormView extends Locomotive.Views.Shared.Form
|
||||
|
||||
@model = new Locomotive.Models.ThemeAsset(@options.theme_asset)
|
||||
|
||||
window.foo = @model
|
||||
|
||||
@image_picker_view = new Locomotive.Views.ThemeAssets.ImagePickerView on_select: @insert_image
|
||||
|
||||
@image_picker_view.render()
|
||||
|
||||
Backbone.ModelBinding.bind @
|
||||
|
||||
render: ->
|
||||
@ -72,10 +72,10 @@ class Locomotive.Views.ThemeAssets.FormView extends Locomotive.Views.Shared.Form
|
||||
open_image_picker: (event) ->
|
||||
event.stopPropagation() & event.preventDefault()
|
||||
@image_picker_view.editor = @editor
|
||||
@image_picker_view.render()
|
||||
@image_picker_view.fetch_assets()
|
||||
|
||||
insert_image: (path) ->
|
||||
text = "{{ '#{path}' | theme_image_url }}"
|
||||
text = "'#{path}'"
|
||||
@editor.replaceSelection(text)
|
||||
@image_picker_view.close()
|
||||
|
||||
|
@ -15,7 +15,12 @@ class Locomotive.Views.ThemeAssets.ImagePickerView extends Locomotive.Views.Shar
|
||||
ich.theme_image_picker
|
||||
|
||||
fetch_assets: ->
|
||||
@collection.fetch data: { content_type: 'image' }
|
||||
@_reset()
|
||||
@collection.fetch
|
||||
data:
|
||||
content_type: 'image'
|
||||
success: () =>
|
||||
@open()
|
||||
|
||||
build_uploader: (el, link) ->
|
||||
link.bind 'click', (event) ->
|
||||
@ -38,3 +43,6 @@ class Locomotive.Views.ThemeAssets.ImagePickerView extends Locomotive.Views.Shar
|
||||
add_asset: (asset) ->
|
||||
@$('ul.list').append(ich.theme_asset(asset.toJSON()))
|
||||
@_refresh()
|
||||
|
||||
_reset: ->
|
||||
@$('ul.list').empty()
|
@ -43,13 +43,16 @@
|
||||
'collection': new Locomotive.Models.ContentAssetsCollection()
|
||||
});
|
||||
|
||||
view.render();
|
||||
|
||||
// Register commands
|
||||
ed.addCommand('locomotiveMedia', function() {
|
||||
view.options.on_select = function(asset) {
|
||||
insertImage(ed, asset);
|
||||
view.close();
|
||||
}
|
||||
view.render();
|
||||
|
||||
view.fetch_assets();
|
||||
});
|
||||
|
||||
// Register buttons
|
||||
|
@ -60,7 +60,7 @@
|
||||
|
||||
.ui-dialog-content {
|
||||
position: relative;
|
||||
z-index: 1040;
|
||||
z-index: 1200;
|
||||
|
||||
text-align: left;
|
||||
|
||||
@ -124,14 +124,14 @@
|
||||
top: 8px;
|
||||
right: 10px;
|
||||
|
||||
z-index: 1003;
|
||||
z-index: 1203;
|
||||
|
||||
a, input[type=submit] {
|
||||
@include light-button;
|
||||
}
|
||||
|
||||
input[type=file] {
|
||||
z-index: 1003;
|
||||
z-index: 1203;
|
||||
}
|
||||
|
||||
} // .button-wrapper
|
||||
|
@ -145,7 +145,7 @@ module Locomotive
|
||||
def escape_shortcut_urls(text)
|
||||
return if text.blank?
|
||||
|
||||
text.gsub(/[("'](\/(stylesheets|javascripts|images|media)\/(([^;.]+)\/)*([a-z_\-0-9]+)\.[a-z]{2,3})[)"']/) do |path|
|
||||
text.gsub(/[("'](\/(stylesheets|javascripts|images|media)\/(([^;.]+)\/)*([a-zA-Z_\-0-9]+)\.[a-z]{2,3})[)"']/) do |path|
|
||||
|
||||
sanitized_path = path.gsub(/[("')]/, '').gsub(/^\//, '')
|
||||
|
||||
|
@ -38,7 +38,7 @@ end
|
||||
# localize redirect_url
|
||||
collection = db.collections.detect { |c| c.name == 'locomotive_pages' }
|
||||
collection.find.each do |page|
|
||||
next if !page['redirect'] || page['redirect_url'].is_a?(Hash)
|
||||
next unless page['redirect_url'].is_a?(String)
|
||||
|
||||
locale = get_locale(page['site_id'])
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user