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;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -5,11 +5,13 @@
|
||||||
<% 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>
|
||||||
|
|
Loading…
Reference in a new issue