Add warning when uploading a file

This commit is contained in:
Luis Ramos
2020-09-29 11:43:14 +01:00
parent be35f97622
commit 3b682bc47f
5 changed files with 49 additions and 5 deletions

View File

@@ -90,7 +90,3 @@ angular.module("admin.enterprises")
$scope.translation = (key) ->
t('js.admin.enterprises.form.images.' + key)
$scope.show_terms_and_conditions_warning = (event) ->
unless confirm("All your buyers will have to agree to the Terms and Conditions again at checkout. Are you sure?")
event.preventDefault()

View File

@@ -0,0 +1,29 @@
angular.module("admin.enterprises").directive 'termsAndConditionsWarning', ($compile, $templateCache, DialogDefaults, $timeout) ->
restrict: 'A'
scope: true
link: (scope, element, attr) ->
# This file input click handler will hold the browser file input dialog and show a warning modal
scope.hold_file_input_and_show_warning_modal = (event) ->
event.preventDefault()
scope.template = $compile($templateCache.get('admin/modals/terms_and_conditions_warning.html'))(scope)
scope.template.dialog(DialogDefaults)
scope.template.dialog('open')
scope.$apply()
element.bind 'click', scope.hold_file_input_and_show_warning_modal
# When the user presses continue in the warning modal, we open the browser file input dialog
scope.continue = ->
scope.template.dialog('close')
# unbind warning modal handler and click file input again to open the browser file input dialog
element.unbind('click').trigger('click')
# afterwards, bind warning modal handler again so that the warning is shown the next time
$timeout ->
element.bind 'click', scope.hold_file_input_and_show_warning_modal
return
scope.close = ->
scope.template.dialog('close')
return