-
-
-
-
- <%- @T('Import from') %>
-
-
-
-
-
- diff --git a/app/assets/javascripts/app/controllers/default_route.js.coffee b/app/assets/javascripts/app/controllers/default_route.js.coffee index 682a6929f..0329e319e 100644 --- a/app/assets/javascripts/app/controllers/default_route.js.coffee +++ b/app/assets/javascripts/app/controllers/default_route.js.coffee @@ -7,6 +7,11 @@ class Index extends App.Controller if window.location.pathname.substr(0,5) is '/test' return + # check if import is active + if @Config.get('import_mode') + @navigate '#import' + return + # route to getting started screen if !@Config.get('system_init_done') @navigate '#getting_started' diff --git a/app/assets/javascripts/app/controllers/getting_started.js.coffee b/app/assets/javascripts/app/controllers/getting_started.js.coffee index f2ae337e9..81b0b1700 100644 --- a/app/assets/javascripts/app/controllers/getting_started.js.coffee +++ b/app/assets/javascripts/app/controllers/getting_started.js.coffee @@ -6,10 +6,16 @@ class Index extends App.ControllerContent if @authenticate(true) @navigate '#' + return # set title @title 'Get Started' + # if not import backend exists, go ahead + if !App.Config.get('ImportPlugins') + @navigate 'getting_started/base' + return + @fetch() release: => @@ -30,6 +36,11 @@ class Index extends App.ControllerContent @navigate '#login' return + # check if import is active + if data.import_mode == true + @navigate '#import/' + data.import_backend + return + # render page @render() ) @@ -55,6 +66,7 @@ class Base extends App.ControllerContent if @authenticate(true) @navigate '#' + return # set title @title 'Configure Base' @@ -79,6 +91,11 @@ class Base extends App.ControllerContent @navigate '#login' return + # check if import is active + if data.import_mode == true + @navigate '#import/' + data.import_backend + return + # render page @render() ) @@ -263,6 +280,7 @@ class Admin extends App.ControllerContent if @authenticate(true) @navigate '#' + return # set title @title 'Create Admin' @@ -290,6 +308,11 @@ class Admin extends App.ControllerContent @navigate '#login' return + # check if import is active + if data.import_mode == true + @navigate '#import/' + data.import_backend + return + # load group collection App.Collection.load( type: 'Group', data: data.groups ) @@ -393,9 +416,6 @@ class Agent extends App.ControllerContent id: 'getting_started', type: 'GET', url: @apiPath + '/getting_started', - data: { -# view: @view, - } processData: true, success: (data, status, xhr) => @@ -404,6 +424,11 @@ class Agent extends App.ControllerContent @navigate '#getting_started/admin' return + # check if import is active + if data.import_mode == true + @navigate '#import/' + data.import_backend + return + # load group collection App.Collection.load( type: 'Group', data: data.groups ) @@ -469,44 +494,4 @@ class Agent extends App.ControllerContent } ) - -App.Config.set( 'getting_started/agents', Agent, 'Routes' ) - -class Import extends App.ControllerContent - className: 'getstarted fit' - - constructor: -> - super - - # set title - @title 'Import' - - @fetch() - - fetch: -> - - # get data - @ajax( - id: 'getting_started', - type: 'GET', - url: @apiPath + '/getting_started', - data: { -# view: @view, - } - processData: true, - success: (data, status, xhr) => - - # redirect to login if master user already exists - if data.setup_done - @navigate '#login' - return - - # render page - @render() - ) - - render: -> - - @html App.view('getting_started/import')() - -App.Config.set( 'getting_started/import', Import, 'Routes' ) +App.Config.set( 'getting_started/agents', Agent, 'Routes' ) \ No newline at end of file diff --git a/app/assets/javascripts/app/controllers/import.js.coffee b/app/assets/javascripts/app/controllers/import.js.coffee index 6428afda0..fca9c66ed 100644 --- a/app/assets/javascripts/app/controllers/import.js.coffee +++ b/app/assets/javascripts/app/controllers/import.js.coffee @@ -1,18 +1,12 @@ -class Index extends App.ControllerContent +class Import extends App.ControllerContent className: 'getstarted fit' - events: - 'submit form': 'submit', - 'click .submit': 'submit', - constructor: -> super # set title - @title 'Get Started' - @navupdate '#get_started' + @title 'Import' - @master_user = 0 @fetch() fetch: -> @@ -22,17 +16,17 @@ class Index extends App.ControllerContent id: 'getting_started', type: 'GET', url: @apiPath + '/getting_started', - data: { -# view: @view, - } processData: true, success: (data, status, xhr) => - # get meta data - @master_user = data.master_user + # redirect to login if master user already exists + if data.setup_done + @navigate '#login' + return - # load group collection - App.Collection.load( type: 'Group', data: data.groups ) + if data.import_mode == true + @navigate '#import/' + data.import_backend + return # render page @render() @@ -40,113 +34,10 @@ class Index extends App.ControllerContent render: -> - # check authentication, redirect to login if master user already exists - #if !@master_user && !@authenticate() - # @navigate '#login' + items = App.Config.get('ImportPlugins') - @html App.view('getting_started')( - master_user: @master_user + @html App.view('import/index')( + items: items ) - new App.ControllerForm( - el: @el.find('#form-master') - model: App.User - screen: 'signup' - autofocus: true - ) - new App.ControllerForm( - el: @el.find('#form-agent') - model: App.User - screen: 'invite_agent' - autofocus: true - ) - - if !@master_user - @el.find('.agent_user').removeClass('hide') - - submit: (e) -> - e.preventDefault() - @params = @formParam(e.target) - - # if no login is given, use emails as fallback - if !@params.login && @params.email - @params.login = @params.email - - # set invite flag - @params.invite = true - - # find agent role - role = App.Role.findByAttribute( 'name', 'Agent' ) - if role - @params.role_ids = role.id - else - @params.role_ids = [0] - - @log 'notice', 'updateAttributes', @params - user = new App.User - user.load(@params) - - errors = user.validate() - if errors - @log 'error', errors - @formValidate( form: e.target, errors: errors ) - return false - - # save user - user.save( - done: => - if @master_user - @master_user = false - App.Auth.login( - data: { - username: @params.login - password: @params.password - }, - success: @relogin -# error: @error, - ) - @Config.set('system_init_done', true) - App.Event.trigger 'notify', { - type: 'success' - msg: App.i18n.translateContent( 'Welcome to %s!', @Config.get('product_name') ) - timeout: 2500 - } - - else - - App.Event.trigger 'notify', { - type: 'success' - msg: App.i18n.translateContent( 'Invitation sent!' ) - timeout: 3500 - } - - # rerender page - @render() - - fail: (data) -> - App.Event.trigger 'notify', { - type: 'error' - msg: App.i18n.translateContent( 'Can\'t create user!' ) - timeout: 2500 - } -# @modalHide() - ) - - relogin: (data, status, xhr) => - @log 'notice', 'relogin:success', data - - # add notify - App.Event.trigger 'notify:removeall' -# @notify -# type: 'success', -# msg: 'Thanks for joining. Email sent to "' + @params.email + '". Please verify your email address.' - - @el.find('.master_user').addClass('hide') - @el.find('.agent_user').removeClass('hide') - @el.find('.tabs .tab.active').removeClass('active') - @el.find('.tabs .invite_agents').addClass('active') -# @el.find('.master_user').fadeOut('slow', => -# @el.find('.agent_user').fadeIn() -# ) - -App.Config.set( 'import', Index, 'Routes' ) +App.Config.set( 'import', Import, 'Routes' ) \ No newline at end of file diff --git a/app/assets/javascripts/app/controllers/import_otrs.js.coffee b/app/assets/javascripts/app/controllers/import_otrs.js.coffee new file mode 100644 index 000000000..11afbd641 --- /dev/null +++ b/app/assets/javascripts/app/controllers/import_otrs.js.coffee @@ -0,0 +1,149 @@ +class Index extends App.ControllerContent + className: 'getstarted fit' + elements: + '.input-feedback': 'urlStatus' + '[data-target=otrs-start-migration]': 'nextStartMigration' + '.otrs-link-error': 'linkErrorMessage' + events: + 'click .js-otrs-link': 'showLink' + 'click .js-download': 'startDownload' + 'click .js-migration-start': 'startMigration' + 'keyup #otrs-link': 'updateUrl' + + constructor: -> + super + + # set title + @title 'Import' + + @fetch() + + fetch: -> + + # get data + @ajax( + id: 'getting_started', + type: 'GET', + url: @apiPath + '/getting_started', + processData: true, + success: (data, status, xhr) => + + # redirect to login if master user already exists + if data.setup_done + @navigate '#login' + return + + # check if import is active + if data.import_mode == true && data.import_backend != 'otrs' + @navigate '#import/' + data.import_backend + return + + # render page + @render() + + if data.import_mode == true + @showImportState() + @updateMigration() + else + showDownload = => + @$('[data-slide=otrs-prepare]').toggleClass('hide') + @$('[data-slide=otrs-plugin]').toggleClass('hide') + @delay( showDownload, 2500 ) + ) + + render: -> + @html App.view('import/otrs')() + + startDownload: (e) => + e.preventDefault() + @$('.js-otrs-link').removeClass('hide') + + showLink: (e) => + e.preventDefault() + @$('[data-slide=otrs-plugin]').toggleClass('hide') + @$('[data-slide=otrs-link]').toggleClass('hide') + + showImportState: => + @$('[data-slide=otrs-prepare]').addClass('hide') + @$('[data-slide=otrs-plugin]').addClass('hide') + @$('[data-slide=otrs-link]').addClass('hide') + @$('[data-slide=otrs-import]').removeClass('hide') + + updateUrl: (e) => + url = $(e.target).val() + @urlStatus.attr('data-state', 'loading') + @linkErrorMessage.text('') + + # get data + callback = => + @ajax( + id: 'import_otrs_url', + type: 'POST', + url: @apiPath + '/import/otrs/url_check', + data: JSON.stringify( { url:url} ) + processData: true, + success: (data, status, xhr) => + + # validate form + console.log(data) + if data.result is 'ok' + @urlStatus.attr('data-state', 'success') + @linkErrorMessage.text('') + @nextStartMigration.removeClass('hide') + else + @urlStatus.attr('data-state', 'error') + @linkErrorMessage.text( data.message_human || data.message ) + @nextStartMigration.addClass('hide') + + ) + @delay( callback, 700, 'import_otrs_url' ) + + startMigration: (e) => + e.preventDefault() + @showImportState() + @ajax( + id: 'import_start', + type: 'POST', + url: @apiPath + '/import/otrs/import_start', + processData: true, + success: (data, status, xhr) => + + # validate form + console.log(data) + if data.result is 'ok' + @delay( @updateMigration, 3000 ) + ) + + + updateMigration: => + @showImportState() + @ajax( + id: 'import_status', + type: 'GET', + url: @apiPath + '/import/otrs/import_status', + processData: true, + success: (data, status, xhr) => + + # validate form + console.log(data) + for key, item of data.data + element = @$('.js-' + key.toLowerCase() ) + element.find('.js-done').text(item.done) + element.find('.js-total').text(item.total) + element.find('progress').attr('max', item.total ) + element.find('progress').attr('value', item.done ) + if item.total is item.done + element.addClass('is-done') + else + element.removeClass('is-done') + + @delay( @updateMigration, 3000 ) + ) + +App.Config.set( 'import/otrs', Index, 'Routes' ) +App.Config.set( 'otrs', { + image: 'otrs-logo.png' + title: 'OTRS' + name: 'OTRS' + url: '#import/otrs' +}, 'ImportPlugins' ) diff --git a/app/assets/javascripts/app/views/getting_started/import.jst.eco b/app/assets/javascripts/app/views/getting_started/import.jst.eco deleted file mode 100644 index f5c207081..000000000 --- a/app/assets/javascripts/app/views/getting_started/import.jst.eco +++ /dev/null @@ -1,23 +0,0 @@ -