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:
did 2012-05-29 15:53:48 -07:00
parent b751e3d990
commit 3a4654e8f7
17 changed files with 67 additions and 49 deletions

View File

@ -69,5 +69,7 @@
doc.head.appendChild(stylesheet); doc.head.appendChild(stylesheet);
} }
$.ui.dialog.prototype.overlayEl = function() { return this.overlay.$el; }
})(); })();

View File

@ -83,3 +83,10 @@ class Locomotive.Views.ApplicationView extends Backbone.View
locale = $(@).attr('data-locale') locale = $(@).attr('data-locale')
window.addParameterToURL 'content_locale', 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++

View File

@ -12,7 +12,10 @@ class Locomotive.Views.ContentAssets.PickerView extends Locomotive.Views.Shared.
ich.content_asset_picker ich.content_asset_picker
fetch_assets: -> fetch_assets: ->
@collection.fetch() @_reset()
@collection.fetch
success: () =>
@open()
build_uploader: (el, link) -> build_uploader: (el, link) ->
link.bind 'click', (event) -> link.bind 'click', (event) ->

View File

@ -70,10 +70,10 @@ class Locomotive.Views.ContentEntries.FormView extends Locomotive.Views.Shared.F
enable_has_many_fields: -> enable_has_many_fields: ->
unless @model.isNew() 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] name = field[0]; inverse_of = field[1]
new_entry = new Locomotive.Models.ContentEntry(@options["#{name}_new_entry"]) 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() if view.ui_enabled()
@_has_many_field_views.push(view) @_has_many_field_views.push(view)

View File

@ -23,17 +23,12 @@ class Locomotive.Views.ContentEntries.PopupFormView extends Locomotive.Views.Con
@close() @close()
create_dialog: -> create_dialog: ->
# FIXME (Did): each modal window should have a different zIndex, otherwise there will be conflicts
zIndex = 998 + @options.index
@dialog = $(@el).dialog @dialog = $(@el).dialog
autoOpen: false autoOpen: false
modal: true modal: true
zIndex: zIndex zIndex: window.application_view.unique_dialog_zindex()
width: 770, width: 770,
create: (event, ui) => create: (event, ui) =>
$('.ui-widget-overlay').bind 'click', => @close()
$(@el).prev().find('.ui-dialog-title').html(@$('h2').html()) $(@el).prev().find('.ui-dialog-title').html(@$('h2').html())
@$('h2').remove() @$('h2').remove()
actions = @$('.dialog-actions').appendTo($(@el).parent()).addClass('ui-dialog-buttonpane ui-widget-content ui-helper-clearfix') 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) actions.find('input[type=submit]').click (event) => @save(event)
open: (event, ui, extra) => open: (event, ui, extra) =>
$(@el).dialog('overlayEl').bind 'click', => @close()
# nothing to do # nothing to do
open: -> open: ->
@ -60,6 +56,7 @@ class Locomotive.Views.ContentEntries.PopupFormView extends Locomotive.Views.Con
close: (event) -> close: (event) ->
event.stopPropagation() & event.preventDefault() if event? event.stopPropagation() & event.preventDefault() if event?
@clear_errors() @clear_errors()
$(@el).dialog('overlayEl').unbind('click')
$(@el).dialog('close') $(@el).dialog('close')
center: -> center: ->

View File

@ -12,8 +12,6 @@ class Locomotive.Views.ContentTypes.FormView extends Locomotive.Views.Shared.For
initialize: -> initialize: ->
@model = new Locomotive.Models.ContentType(@options.content_type) @model = new Locomotive.Models.ContentType(@options.content_type)
window.foo = @model
Backbone.ModelBinding.bind @ Backbone.ModelBinding.bind @
render: -> render: ->

View File

@ -58,11 +58,18 @@ class Locomotive.Views.ContentTypes.CustomFieldEntryView extends Backbone.View
fetch_inverse_of_list: -> fetch_inverse_of_list: ->
@$('li.input.inverse-of select option').remove() @$('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') 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) @$('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: -> render_select_options_view: ->
@select_options_view = new Locomotive.Views.ContentTypes.SelectOptionsView @select_options_view = new Locomotive.Views.ContentTypes.SelectOptionsView
model: @model model: @model

View File

@ -16,14 +16,14 @@ class Locomotive.Views.Pages.FormView extends Locomotive.Views.Shared.FormView
@model = new Locomotive.Models.Page(@options.page) @model = new Locomotive.Models.Page(@options.page)
window.foo = @model
@touched_url = false @touched_url = false
@image_picker_view = new Locomotive.Views.ThemeAssets.ImagePickerView @image_picker_view = new Locomotive.Views.ThemeAssets.ImagePickerView
collection: new Locomotive.Models.ThemeAssetsCollection() collection: new Locomotive.Models.ThemeAssetsCollection()
on_select: @insert_image on_select: @insert_image
@image_picker_view.render()
Backbone.ModelBinding.bind @ Backbone.ModelBinding.bind @
@editable_elements_view = new Locomotive.Views.EditableElements.EditAllView(collection: @model.get('editable_elements')) @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) -> open_image_picker: (event) ->
event.stopPropagation() & event.preventDefault() event.stopPropagation() & event.preventDefault()
@image_picker_view.editor = @editor @image_picker_view.editor = @editor
@image_picker_view.render() @image_picker_view.fetch_assets()
insert_image: (path) -> insert_image: (path) ->
text = "{{ '#{path}' | theme_image_url }}" text = "{{ '#{path}' | theme_image_url }}"

View File

@ -11,11 +11,9 @@ class Locomotive.Views.Shared.AssetPickerView extends Backbone.View
@collection.bind('remove', @remove_asset) @collection.bind('remove', @remove_asset)
render: -> render: ->
@_reset()
$(@el).html(@template()()) $(@el).html(@template()())
@fetch_assets() @create_dialog()
return @ return @
@ -29,34 +27,32 @@ class Locomotive.Views.Shared.AssetPickerView extends Backbone.View
# please overide build_uploader # please overide build_uploader
create_dialog: -> create_dialog: ->
@dialog = $(@el).dialog @dialog ||= $(@el).dialog
autoOpen: false autoOpen: false
modal: true modal: true
zIndex: 996 zIndex: window.application_view.unique_dialog_zindex()
width: 650, width: 650,
create: (event, ui) => create: (event, ui) =>
$('.ui-widget-overlay').bind 'click', => @close()
$(@el).prev().find('.ui-dialog-title').html(@$('h2').html()) $(@el).prev().find('.ui-dialog-title').html(@$('h2').html())
@$('h2').remove() @$('h2').remove()
actions = @$('.dialog-actions').appendTo($(@el).parent()).addClass('ui-dialog-buttonpane ui-widget-content ui-helper-clearfix') actions = @$('.dialog-actions').appendTo($(@el).parent()).addClass('ui-dialog-buttonpane ui-widget-content ui-helper-clearfix')
actions.find('#close-link').click (event) => @close(event) actions.find('#close-link').click (event) => @close(event)
open: (event, ui, extra) => input = actions.find('input[type=file]')
actions = $(@el).parent().find('.ui-dialog-buttonpane')
el = actions.find('input[type=file]')
link = actions.find('#upload-link') link = actions.find('#upload-link')
@build_uploader(el, link) @build_uploader(input, link)
@open() open: (event, ui, extra) =>
$(@el).dialog('overlayEl').bind 'click', => @close()
open: -> open: ->
$(@el).dialog('open') $(@el).dialog('open')
close: (event) -> close: (event) ->
event.stopPropagation() & event.preventDefault() if event? event.stopPropagation() & event.preventDefault() if event?
$(@el).dialog('overlayEl').unbind('click')
$(@el).dialog('close') $(@el).dialog('close')
shake: -> shake: ->
@ -71,8 +67,6 @@ class Locomotive.Views.Shared.AssetPickerView extends Backbone.View
@_refresh() @_refresh()
setTimeout (=> @create_dialog()), 30 # disable flickering
add_asset: (asset, first) -> add_asset: (asset, first) ->
# please overide add_asset (the 'first' param is to know if it comes from the first collection fetch) # 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: -> _on_refresh: ->
_reset: -> _reset: ->
$('.ui-widget-overlay').unbind 'click' # for nothing to do
@$('.actions input[type=file]').remove()
@dialog.dialog('destroy') if @dialog?

View File

@ -70,7 +70,6 @@ class Locomotive.Views.Shared.Fields.HasManyView extends Backbone.View
el: $("##{@options.name}-template-entry") el: $("##{@options.name}-template-entry")
parent_view: @ parent_view: @
model: @options.new_entry.clone() # by default, it does not matter model: @options.new_entry.clone() # by default, it does not matter
index: @options.index
@target_entry_view.render() @target_entry_view.render()

View File

@ -19,6 +19,8 @@ class Locomotive.Views.Snippets.FormView extends Locomotive.Views.Shared.FormVie
collection: new Locomotive.Models.ThemeAssetsCollection() collection: new Locomotive.Models.ThemeAssetsCollection()
on_select: @insert_image on_select: @insert_image
@image_picker_view.render()
Backbone.ModelBinding.bind @ Backbone.ModelBinding.bind @
render: -> render: ->
@ -38,7 +40,7 @@ class Locomotive.Views.Snippets.FormView extends Locomotive.Views.Shared.FormVie
open_image_picker: (event) -> open_image_picker: (event) ->
event.stopPropagation() & event.preventDefault() event.stopPropagation() & event.preventDefault()
@image_picker_view.editor = @editor @image_picker_view.editor = @editor
@image_picker_view.render() @image_picker_view.fetch_assets()
insert_image: (path) -> insert_image: (path) ->
text = "{{ '#{path}' | theme_image_url }}" text = "{{ '#{path}' | theme_image_url }}"

View File

@ -15,10 +15,10 @@ class Locomotive.Views.ThemeAssets.FormView extends Locomotive.Views.Shared.Form
@model = new Locomotive.Models.ThemeAsset(@options.theme_asset) @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 = new Locomotive.Views.ThemeAssets.ImagePickerView on_select: @insert_image
@image_picker_view.render()
Backbone.ModelBinding.bind @ Backbone.ModelBinding.bind @
render: -> render: ->
@ -72,10 +72,10 @@ class Locomotive.Views.ThemeAssets.FormView extends Locomotive.Views.Shared.Form
open_image_picker: (event) -> open_image_picker: (event) ->
event.stopPropagation() & event.preventDefault() event.stopPropagation() & event.preventDefault()
@image_picker_view.editor = @editor @image_picker_view.editor = @editor
@image_picker_view.render() @image_picker_view.fetch_assets()
insert_image: (path) -> insert_image: (path) ->
text = "{{ '#{path}' | theme_image_url }}" text = "'#{path}'"
@editor.replaceSelection(text) @editor.replaceSelection(text)
@image_picker_view.close() @image_picker_view.close()

View File

@ -15,7 +15,12 @@ class Locomotive.Views.ThemeAssets.ImagePickerView extends Locomotive.Views.Shar
ich.theme_image_picker ich.theme_image_picker
fetch_assets: -> fetch_assets: ->
@collection.fetch data: { content_type: 'image' } @_reset()
@collection.fetch
data:
content_type: 'image'
success: () =>
@open()
build_uploader: (el, link) -> build_uploader: (el, link) ->
link.bind 'click', (event) -> link.bind 'click', (event) ->
@ -38,3 +43,6 @@ class Locomotive.Views.ThemeAssets.ImagePickerView extends Locomotive.Views.Shar
add_asset: (asset) -> add_asset: (asset) ->
@$('ul.list').append(ich.theme_asset(asset.toJSON())) @$('ul.list').append(ich.theme_asset(asset.toJSON()))
@_refresh() @_refresh()
_reset: ->
@$('ul.list').empty()

View File

@ -43,13 +43,16 @@
'collection': new Locomotive.Models.ContentAssetsCollection() 'collection': new Locomotive.Models.ContentAssetsCollection()
}); });
view.render();
// Register commands // Register commands
ed.addCommand('locomotiveMedia', function() { ed.addCommand('locomotiveMedia', function() {
view.options.on_select = function(asset) { view.options.on_select = function(asset) {
insertImage(ed, asset); insertImage(ed, asset);
view.close(); view.close();
} }
view.render();
view.fetch_assets();
}); });
// Register buttons // Register buttons

View File

@ -60,7 +60,7 @@
.ui-dialog-content { .ui-dialog-content {
position: relative; position: relative;
z-index: 1040; z-index: 1200;
text-align: left; text-align: left;
@ -124,14 +124,14 @@
top: 8px; top: 8px;
right: 10px; right: 10px;
z-index: 1003; z-index: 1203;
a, input[type=submit] { a, input[type=submit] {
@include light-button; @include light-button;
} }
input[type=file] { input[type=file] {
z-index: 1003; z-index: 1203;
} }
} // .button-wrapper } // .button-wrapper

View File

@ -145,7 +145,7 @@ module Locomotive
def escape_shortcut_urls(text) def escape_shortcut_urls(text)
return if text.blank? 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(/^\//, '') sanitized_path = path.gsub(/[("')]/, '').gsub(/^\//, '')

View File

@ -38,7 +38,7 @@ end
# localize redirect_url # localize redirect_url
collection = db.collections.detect { |c| c.name == 'locomotive_pages' } collection = db.collections.detect { |c| c.name == 'locomotive_pages' }
collection.find.each do |page| 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']) locale = get_locale(page['site_id'])