2011-11-10 01:43:19 +00:00
|
|
|
class Locomotive.Views.ApplicationView extends Backbone.View
|
|
|
|
|
|
|
|
el: 'body'
|
|
|
|
|
|
|
|
render: ->
|
|
|
|
@render_flash_messages(@options.flash)
|
|
|
|
|
2011-11-16 10:19:57 +00:00
|
|
|
@add_submenu_behaviours()
|
|
|
|
|
2011-11-16 00:39:16 +00:00
|
|
|
@center_ui_dialog()
|
|
|
|
|
2011-12-12 09:35:42 +00:00
|
|
|
@enable_sites_picker()
|
|
|
|
|
2012-01-14 00:38:09 +00:00
|
|
|
@enable_content_locale_picker()
|
|
|
|
|
2011-12-12 09:35:42 +00:00
|
|
|
# render page view
|
2011-11-10 12:29:59 +00:00
|
|
|
if @options.view?
|
2011-11-21 01:27:05 +00:00
|
|
|
@view = new @options.view(@options.view_data || {})
|
2011-11-10 12:29:59 +00:00
|
|
|
@view.render()
|
|
|
|
|
2011-11-21 01:27:05 +00:00
|
|
|
window.Locomotive.tinyMCE.defaultSettings.language = window.locale # set the default tinyMCE language
|
|
|
|
window.Locomotive.tinyMCE.minimalSettings.language = window.locale
|
2011-11-18 23:20:37 +00:00
|
|
|
|
2011-11-10 01:43:19 +00:00
|
|
|
return @
|
|
|
|
|
|
|
|
render_flash_messages: (messages) ->
|
|
|
|
_.each messages, (couple) ->
|
|
|
|
$.growl couple[0], couple[1]
|
2011-11-16 00:39:16 +00:00
|
|
|
|
|
|
|
center_ui_dialog: ->
|
|
|
|
$(window).resize ->
|
|
|
|
$('.ui-dialog-content:visible').dialog('option', 'position', 'center')
|
2011-11-16 10:19:57 +00:00
|
|
|
|
|
|
|
add_submenu_behaviours: ->
|
2011-11-23 13:01:15 +00:00
|
|
|
$('#submenu ul li.hoverable').each ->
|
|
|
|
timer = null
|
|
|
|
link = $(@)
|
2012-01-18 00:54:26 +00:00
|
|
|
(popup = link.find('.popup')).removeClass('popup').addClass('submenu-popup'
|
2011-11-23 13:01:15 +00:00
|
|
|
).bind('show', ->
|
2012-01-18 00:54:26 +00:00
|
|
|
link.find('a').addClass('hover') & popup.css(
|
|
|
|
top: link.offset().top + link.height() - 2
|
|
|
|
left: link.offset().left - parseInt(popup.css('padding-left'))
|
|
|
|
).show()
|
2011-11-23 13:01:15 +00:00
|
|
|
).bind('hide', ->
|
|
|
|
link.find('a').removeClass('hover') & $(@).hide()
|
|
|
|
).bind('mouseleave', -> popup.trigger('hide')
|
|
|
|
).bind 'mouseenter', -> clearTimeout(timer)
|
|
|
|
|
|
|
|
$(document.body).append(popup)
|
|
|
|
|
|
|
|
link.hover(
|
|
|
|
-> popup.trigger('show')
|
|
|
|
-> timer = window.setTimeout (-> popup.trigger('hide')), 30
|
|
|
|
)
|
2011-11-16 10:19:57 +00:00
|
|
|
|
|
|
|
css = $('#submenu > ul').attr('class')
|
|
|
|
$("#submenu > ul > li.#{css}").addClass('on') if css != ''
|
|
|
|
|
2011-12-12 09:35:42 +00:00
|
|
|
enable_sites_picker: ->
|
|
|
|
link = @$('#sites-picker-link')
|
|
|
|
picker = @$('#sites-picker')
|
|
|
|
|
|
|
|
return if picker.size() == 0
|
|
|
|
|
|
|
|
left = link.position().left + link.parent().position().left - (picker.width() - link.width())
|
|
|
|
picker.css('left', left)
|
|
|
|
|
|
|
|
link.bind 'click', (event) ->
|
|
|
|
event.stopPropagation() & event.preventDefault()
|
|
|
|
picker.toggle()
|
|
|
|
|
2012-01-14 00:38:09 +00:00
|
|
|
enable_content_locale_picker: ->
|
|
|
|
link = @$('#content-locale-picker-link')
|
|
|
|
picker = @$('#content-locale-picker')
|
|
|
|
|
|
|
|
return if picker.size() == 0
|
|
|
|
|
|
|
|
link.bind 'click', (event) ->
|
|
|
|
event.stopPropagation() & event.preventDefault()
|
|
|
|
picker.toggle()
|
|
|
|
|
2012-02-07 10:59:55 +00:00
|
|
|
picker.find('li').bind 'click', (event) ->
|
2012-02-09 10:36:10 +00:00
|
|
|
locale = $(@).attr('data-locale')
|
2012-01-14 00:38:09 +00:00
|
|
|
window.addParameterToURL 'content_locale', locale
|
|
|
|
|
2012-05-29 22:53:48 +00:00
|
|
|
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++
|
|
|
|
|