diff --git a/app/assets/javascripts/app/controllers/_application_controller_generic.js.coffee b/app/assets/javascripts/app/controllers/_application_controller_generic.js.coffee index 0123a8ecd..6fd2f6b22 100644 --- a/app/assets/javascripts/app/controllers/_application_controller_generic.js.coffee +++ b/app/assets/javascripts/app/controllers/_application_controller_generic.js.coffee @@ -228,6 +228,48 @@ class App.ControllerGenericDescription extends App.ControllerModal e.preventDefault() @hide() +class App.ControllerModalLoading extends App.Controller + className: 'modal fade' + + constructor: -> + super + + if @container + @el.addClass('modal--local') + + @render() + + @el.modal + keyboard: false + show: true + backdrop: false + container: @container + + render: -> + @html App.view('generic/modal_loader')( + head: @head + message: App.i18n.translateContent(@message) + ) + + update: (message, translate = true) => + if translate + message = App.i18n.translateContent(message) + @$('.js-loading').html(message) + + hideIcon: => + @$('.js-loadingIcon').addClass('hide') + + showIcon: => + @$('.js-loadingIcon').removeClass('hide') + + hide: (delay) => + remove = => + @el.remove() + if !delay + remove() + return + App.Delay.set(remove, delay * 1000) + class App.ControllerGenericDestroyConfirm extends App.ControllerModal constructor: -> super diff --git a/app/assets/javascripts/app/controllers/translation.js.coffee b/app/assets/javascripts/app/controllers/translation.js.coffee index 38627565c..50e2779d7 100644 --- a/app/assets/javascripts/app/controllers/translation.js.coffee +++ b/app/assets/javascripts/app/controllers/translation.js.coffee @@ -52,80 +52,83 @@ class Index extends App.ControllerContent pushChanges: => locale = @$('[name="locale"]').val() - @modal = new App.ControllerModal( - head: 'Pushing own translations...' - message: 'Pushing own translations to i18n.zammad.com, Thanks for contributing!' - cancel: false - close: false - shown: true + @loader = new App.ControllerModalLoading( + head: 'Push my changes' + message: 'Pushing translations to i18n.zammad.com' container: @el.closest('.content') ) @ajax( id: 'translations' type: 'PUT' - url: @apiPath + '/translations/push' + url: "#{@apiPath}/translations/push" data: JSON.stringify(locale: locale) processData: false success: (data, status, xhr) => - @modal.hide() + @loader.update('Thanks for contributing!') + @loader.hideIcon() + @loader.hide(2) error: => - @modal.hide() + @loader.hide() ) resetChanges: => locale = @$('[name="locale"]').val() - @modal = new App.ControllerModal( - head: 'Reseting changes...' - message: 'Reseting changes own translation changes...' - cancel: false - close: false - shown: true + @loader = new App.ControllerModalLoading( + head: 'Reset changes' + message: 'Reseting changes...' container: @el.closest('.content') ) @ajax( id: 'translations' type: 'POST' - url: @apiPath + '/translations/reset' + url: "#{@apiPath}/translations/reset" data: JSON.stringify(locale: locale) processData: false success: (data, status, xhr) => App.Event.trigger('i18n:translation_todo_reload') App.Event.trigger('i18n:translation_list_reload') @hideAction() - @modal.hide() + @loader.hide() error: => - @modal.hide() + @loader.hide() ) syncChanges: => locale = @$('[name="locale"]').val() - @modal = new App.ControllerModal( - head: 'Syncing with latest translations...' - message: 'Syncing with latest translations!' - cancel: false - close: false - shown: true + @loader = new App.ControllerModalLoading( + head: 'Get latest translations' + message: 'Getting latest translations from i18n.zammad.com' container: @el.closest('.content') ) + hide = => + @hideAction() + App.Event.trigger('i18n:translation_todo_reload') + App.Event.trigger('i18n:translation_list_reload') + @loader.hide(1) + + locales = App.Locale.all() + locale = locales.shift() + @_syncChanges(locale, locales, @loader, hide) + + _syncChanges: (locale, locales, loader, hide) => @ajax( id: 'translations' - type: 'POST' - url: @apiPath + '/translations/sync' - data: JSON.stringify(locale: locale) + type: 'GET' + url: "#{@apiPath}/translations/sync/#{locale.locale}" processData: false - success: (data, status, xhr) => - App.Event.trigger('i18n:translation_todo_reload') - App.Event.trigger('i18n:translation_list_reload') - @hideAction() - @modal.hide() - error: => - @modal.hide() - ) + complete: (data, status, xhr) => + loader.update(locale.name, false) + locale = locales.shift() + if _.isEmpty(locales) + hide() + return + @_syncChanges(locale, locales, loader, hide) + ) class TranslationToDo extends App.Controller hasChanges: false @@ -149,6 +152,7 @@ class TranslationToDo extends App.Controller return if !App.i18n.getNotTranslated(@locale) + @html '' return listNotTranslated = [] diff --git a/app/assets/javascripts/app/views/generic/modal_loader.jst.eco b/app/assets/javascripts/app/views/generic/modal_loader.jst.eco new file mode 100644 index 000000000..a8a18aac1 --- /dev/null +++ b/app/assets/javascripts/app/views/generic/modal_loader.jst.eco @@ -0,0 +1,20 @@ +