Improved closing modal dialog, ask user if form has changed.
This commit is contained in:
parent
c66e22bef9
commit
ff93c7f22c
3 changed files with 54 additions and 24 deletions
|
@ -700,6 +700,8 @@ class App.ControllerModal extends App.Controller
|
||||||
headPrefix: ''
|
headPrefix: ''
|
||||||
shown: true
|
shown: true
|
||||||
closeOnAnyClick: false
|
closeOnAnyClick: false
|
||||||
|
initalFormParams: {}
|
||||||
|
initalFormParamsIgnore: false
|
||||||
|
|
||||||
events:
|
events:
|
||||||
'submit form': 'submit'
|
'submit form': 'submit'
|
||||||
|
@ -746,10 +748,10 @@ class App.ControllerModal extends App.Controller
|
||||||
centerButtons: @centerButtons
|
centerButtons: @centerButtons
|
||||||
leftButtons: @leftButtons
|
leftButtons: @leftButtons
|
||||||
)
|
)
|
||||||
modal.find('.modal-body').html content
|
modal.find('.modal-body').html(content)
|
||||||
if !@initRenderingDone
|
if !@initRenderingDone
|
||||||
@initRenderingDone = true
|
@initRenderingDone = true
|
||||||
@html modal
|
@html(modal)
|
||||||
else
|
else
|
||||||
@$('.modal-dialog').replaceWith(modal)
|
@$('.modal-dialog').replaceWith(modal)
|
||||||
@post()
|
@post()
|
||||||
|
@ -761,6 +763,8 @@ class App.ControllerModal extends App.Controller
|
||||||
@el
|
@el
|
||||||
|
|
||||||
render: =>
|
render: =>
|
||||||
|
@initalFormParamsIgnore = false
|
||||||
|
|
||||||
if @buttonSubmit is true
|
if @buttonSubmit is true
|
||||||
@buttonSubmit = 'Submit'
|
@buttonSubmit = 'Submit'
|
||||||
if @buttonCancel is true
|
if @buttonCancel is true
|
||||||
|
@ -775,19 +779,18 @@ class App.ControllerModal extends App.Controller
|
||||||
if @small
|
if @small
|
||||||
@el.addClass('modal--small')
|
@el.addClass('modal--small')
|
||||||
|
|
||||||
@el.modal
|
@el.modal(
|
||||||
keyboard: @keyboard
|
keyboard: @keyboard
|
||||||
show: true
|
show: true
|
||||||
backdrop: @backdrop
|
backdrop: @backdrop
|
||||||
container: @container
|
container: @container
|
||||||
.on
|
).on(
|
||||||
'show.bs.modal': @onShow
|
'show.bs.modal': @localOnShow
|
||||||
'shown.bs.modal': @onShown
|
'shown.bs.modal': @localOnShown
|
||||||
'hide.bs.modal': @onClose
|
'hide.bs.modal': @localOnClose
|
||||||
'hidden.bs.modal': =>
|
'hidden.bs.modal': @localOnClosed
|
||||||
@onClosed()
|
'dismiss.bs.modal': @localOnCancel
|
||||||
$('.modal').remove()
|
)
|
||||||
'dismiss.bs.modal': @onCancel
|
|
||||||
|
|
||||||
if @closeOnAnyClick
|
if @closeOnAnyClick
|
||||||
@el.on('click', =>
|
@el.on('click', =>
|
||||||
|
@ -797,6 +800,7 @@ class App.ControllerModal extends App.Controller
|
||||||
close: (e) =>
|
close: (e) =>
|
||||||
if e
|
if e
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
|
@initalFormParamsIgnore = true
|
||||||
@el.modal('hide')
|
@el.modal('hide')
|
||||||
|
|
||||||
formParams: =>
|
formParams: =>
|
||||||
|
@ -804,28 +808,50 @@ class App.ControllerModal extends App.Controller
|
||||||
return @formParam(@container.find('.modal form'))
|
return @formParam(@container.find('.modal form'))
|
||||||
return @formParam(@$('.modal form'))
|
return @formParam(@$('.modal form'))
|
||||||
|
|
||||||
onShow: ->
|
localOnShow: (e) =>
|
||||||
|
@onShow(e)
|
||||||
|
|
||||||
|
onShow: (e) ->
|
||||||
# do nothing
|
# do nothing
|
||||||
|
|
||||||
onShown: =>
|
localOnShown: (e) =>
|
||||||
|
@onShown(e)
|
||||||
|
|
||||||
|
onShown: (e) =>
|
||||||
@$('input:not([disabled]):not([type="hidden"]):not(".btn"), textarea').first().focus()
|
@$('input:not([disabled]):not([type="hidden"]):not(".btn"), textarea').first().focus()
|
||||||
|
@initalFormParams = @formParams()
|
||||||
|
|
||||||
|
localOnClose: (e) =>
|
||||||
|
diff = difference(@initalFormParams, @formParams())
|
||||||
|
if @initalFormParamsIgnore is false && !_.isEmpty(diff)
|
||||||
|
if !confirm(App.i18n.translateContent('The form content has been changed, discarded changes?'))
|
||||||
|
e.preventDefault()
|
||||||
|
return
|
||||||
|
@onClose(e)
|
||||||
|
|
||||||
onClose: ->
|
onClose: ->
|
||||||
# do nothing
|
# do nothing
|
||||||
|
|
||||||
onClosed: ->
|
localOnClosed: (e) =>
|
||||||
|
@onClosed(e)
|
||||||
|
$('.modal').remove()
|
||||||
|
|
||||||
|
onClosed: (e) ->
|
||||||
# do nothing
|
# do nothing
|
||||||
|
|
||||||
onSubmit: ->
|
localOnCancel: (e) =>
|
||||||
# do nothing
|
@onCancel(e)
|
||||||
|
|
||||||
onCancel: ->
|
onCancel: (e) ->
|
||||||
# do nothing
|
# do nothing
|
||||||
|
|
||||||
cancel: (e) =>
|
cancel: (e) =>
|
||||||
@close(e)
|
@close(e)
|
||||||
@onCancel(e)
|
@onCancel(e)
|
||||||
|
|
||||||
|
onSubmit: (e) ->
|
||||||
|
# do nothing
|
||||||
|
|
||||||
submit: (e) =>
|
submit: (e) =>
|
||||||
e.stopPropagation()
|
e.stopPropagation()
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
|
|
|
@ -516,7 +516,9 @@
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
this.setValue();
|
this.setValue();
|
||||||
this._trigger('hide');
|
// 2018-01-22 trigger locale hide event - conflicts with modal hide
|
||||||
|
//this._trigger('hide');
|
||||||
|
this._trigger('hide.bs.datepicker');
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -1,15 +1,17 @@
|
||||||
<div class="sidebar-block">
|
<div class="sidebar-block">
|
||||||
<%- @user.avatar("50", "", "userInfo-avatar") %>
|
<%- @user.avatar("50", "", "userInfo-avatar") %>
|
||||||
<h3 title="<%- @Ti( 'Name') %>"><%= @user.displayName() %></h3>
|
<h3 title="<%- @Ti('Name') %>"><%= @user.displayName() %></h3>
|
||||||
</div>
|
</div>
|
||||||
<% for row in @userData: %>
|
<% for row in @userData: %>
|
||||||
<% if @user[row.name] || row.name is 'note': %>
|
<% if @user[row.name] || row.name is 'note': %>
|
||||||
<div class="sidebar-block">
|
<div class="sidebar-block">
|
||||||
|
<label><%- @T(row.display) %></label>
|
||||||
<% if row.tag isnt 'richtext': %>
|
<% if row.tag isnt 'richtext': %>
|
||||||
<label><%- @T(row.display) %></label>
|
<% if row.link: %><a href="<%- row.link %><%= @user[row.name] %>" target="_blank"><%- @P(@user, row.name) %></a>
|
||||||
<%- @P(@user, row.name) %>
|
<% else: %>
|
||||||
|
<%- @P(@user, row.name) %>
|
||||||
|
<% end %>
|
||||||
<% else: %>
|
<% else: %>
|
||||||
<label><%- @T(row.display) %></label>
|
|
||||||
<div contenteditable="true" data-name="<%= row.name %>" data-type="update" data-placeholder="<%- @Ti('Add a Note') %>"><%- @user[row.name] %></div>
|
<div contenteditable="true" data-name="<%= row.name %>" data-type="update" data-placeholder="<%- @Ti('Add a Note') %>"><%- @user[row.name] %></div>
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
|
@ -17,7 +19,7 @@
|
||||||
<% end %>
|
<% end %>
|
||||||
<% if !_.isEmpty(@user['accounts']): %>
|
<% if !_.isEmpty(@user['accounts']): %>
|
||||||
<div class="sidebar-block">
|
<div class="sidebar-block">
|
||||||
<label><%- @T( 'Linked Accounts' ) %></label>
|
<label><%- @T('Linked Accounts') %></label>
|
||||||
<% for account of @user['accounts']: %>
|
<% for account of @user['accounts']: %>
|
||||||
<a href="<%= @user['accounts'][account]['link'] %>" target="_blank"><%= account %></a>
|
<a href="<%= @user['accounts'][account]['link'] %>" target="_blank"><%= account %></a>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
@ -26,7 +28,7 @@
|
||||||
<% if !_.isEmpty(@user['links']): %>
|
<% if !_.isEmpty(@user['links']): %>
|
||||||
<% for link in @user['links']: %>
|
<% for link in @user['links']: %>
|
||||||
<div class="sidebar-block">
|
<div class="sidebar-block">
|
||||||
<label><%- @T( link['title'] ) %></label>
|
<label><%- @T(link['title']) %></label>
|
||||||
<% for item in link['items']: %>
|
<% for item in link['items']: %>
|
||||||
<% if item['url']: %>
|
<% if item['url']: %>
|
||||||
<a href="<%= item['url'] %>" title="<%- @Ti( item['title'] ) %>" style="<%= item['style'] %>" data-type="<%= item['data'] %>" class="<%= item['class'] %>" <% if link.new_window: %>target="_blank"<% end %>>
|
<a href="<%= item['url'] %>" title="<%- @Ti( item['title'] ) %>" style="<%= item['style'] %>" data-type="<%= item['data'] %>" class="<%= item['class'] %>" <% if link.new_window: %>target="_blank"<% end %>>
|
||||||
|
|
Loading…
Reference in a new issue