From 99e975161241d48e14e1e6f49ada37bb9ff55914 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Tue, 10 Apr 2012 21:57:18 +0200 Subject: [PATCH] Improved getting started. --- Gemfile.lock | 65 ++++++++++- .../app/controllers/getting_started.js.coffee | 101 ++++++++++++++---- app/assets/javascripts/app/index.js.coffee | 15 +++ .../app/views/getting_started.jst.eco | 15 ++- app/controllers/getting_started_controller.rb | 28 +++++ app/controllers/users_controller.rb | 16 ++- config/routes.rb | 3 + 7 files changed, 210 insertions(+), 33 deletions(-) create mode 100644 app/controllers/getting_started_controller.rb diff --git a/Gemfile.lock b/Gemfile.lock index 05b682254..a522c2d2d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,5 +1,5 @@ GEM - remote: https://rubygems.org/ + remote: http://rubygems.org/ specs: actionmailer (3.2.2) actionpack (= 3.2.2) @@ -28,6 +28,7 @@ GEM activesupport (3.2.2) i18n (~> 0.6) multi_json (~> 1.0) + addressable (2.2.7) arel (3.0.2) builder (3.0.0) coffee-rails (3.2.2) @@ -37,9 +38,25 @@ GEM coffee-script-source execjs coffee-script-source (1.2.0) + daemons (1.1.8) + delayed_job (3.0.1) + activesupport (~> 3.0) + delayed_job_active_record (0.3.2) + activerecord (> 2.1.0) + delayed_job (~> 3.0.0) + eco (1.0.0) + coffee-script + eco-source + execjs + eco-source (1.1.0.rc.1) erubis (2.7.0) execjs (1.3.0) multi_json (~> 1.0) + faraday (0.7.6) + addressable (~> 2.2) + multipart-post (~> 1.1) + rack (~> 1.1) + hashie (1.2.0) hike (1.2.1) i18n (0.6.0) journey (1.0.3) @@ -47,12 +64,35 @@ GEM railties (>= 3.2.0, < 5.0) thor (~> 0.14) json (1.6.6) + koala (1.3.0) + faraday (~> 0.7.0) + multi_json (~> 1.0) mail (2.4.4) i18n (>= 0.4.0) mime-types (~> 1.16) treetop (~> 1.4.8) mime-types (1.18) multi_json (1.2.0) + multipart-post (1.1.5) + oauth (0.4.5) + oauth2 (0.5.2) + faraday (~> 0.7) + multi_json (~> 1.0) + omniauth (1.0.2) + hashie (~> 1.2) + rack + omniauth-facebook (1.2.0) + omniauth-oauth2 (~> 1.0.0) + omniauth-linkedin (0.0.6) + omniauth-oauth (~> 1.0.0) + omniauth-oauth (1.0.0) + oauth + omniauth (~> 1.0) + omniauth-oauth2 (1.0.0) + oauth2 (~> 0.5.0) + omniauth (~> 1.0) + omniauth-twitter (0.0.8) + omniauth-oauth (~> 1.0) polyglot (0.3.3) rack (1.4.1) rack-cache (1.2) @@ -84,6 +124,7 @@ GEM railties (~> 3.2.0) sass (>= 3.1.10) tilt (~> 1.3) + simple_oauth (0.1.5) sprockets (2.1.2) hike (~> 1.2) rack (~> 1.0) @@ -94,6 +135,11 @@ GEM treetop (1.4.10) polyglot polyglot (>= 0.3.1) + twitter (2.1.0) + activesupport (>= 2.3.9, < 4) + faraday (~> 0.7) + multi_json (~> 1.0) + simple_oauth (~> 0.1) tzinfo (0.3.32) uglifier (1.2.4) execjs (>= 0.3.0) @@ -103,10 +149,21 @@ PLATFORMS ruby DEPENDENCIES - coffee-rails (~> 3.2.1) + coffee-rails (~> 3.2.2) + daemons + delayed_job_active_record + eco jquery-rails json + koala + mail + mime-types + omniauth + omniauth-facebook + omniauth-linkedin + omniauth-twitter rails (= 3.2.2) - sass-rails (~> 3.2.3) + sass-rails (~> 3.2.4) sqlite3 - uglifier (>= 1.0.3) + twitter + uglifier (>= 1.2.3) diff --git a/app/assets/javascripts/app/controllers/getting_started.js.coffee b/app/assets/javascripts/app/controllers/getting_started.js.coffee index f9b4398a7..93d1e9544 100644 --- a/app/assets/javascripts/app/controllers/getting_started.js.coffee +++ b/app/assets/javascripts/app/controllers/getting_started.js.coffee @@ -11,26 +11,53 @@ class Index extends App.Controller super # check authentication - return if !@authenticate() +# return if !@authenticate() # set title @title 'Get Started' - - @render() - @navupdate '#get_started' - - render: -> - @html App.view('getting_started')( - form: @formGen( model: App.User, required: 'invite_agent' ), + + @master_user = 0 + +# @render() + @fetch() + + fetch: -> + + # get data + @ajax = new App.Ajax + @ajax.ajax( + type: 'GET', + url: '/getting_started', + data: { +# view: @view, + } + processData: true, + success: (data, status, xhr) => + + # get meta data + @master_user = data.master_user + + # load group collection + @loadCollection( type: 'Group', data: data.groups ) + + # load role collection + @loadCollection( type: 'Role', data: data.roles ) + + # render page + @render() ) - cancel: -> - @log 'cancel....' - @navigate 'login' + render: -> + @html App.view('getting_started')( + form_agent: @formGen( model: App.User, required: 'invite_agent' ), + form_master: @formGen( model: App.User, required: 'signup' ), + master_user: @master_user, + ) + if !@master_user + @el.find('.agent_user').removeClass('hide') submit: (e) -> - @log 'submit' e.preventDefault() @params = @formParam(e.target) @@ -38,13 +65,16 @@ class Index extends App.Controller if !@params.login && @params.email @params.login = @params.email - # find agent role - role = App.Role.findByAttribute("name", "Agent") - @params.role_ids = role.id - # 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 'updateAttributes', @params user = new App.User user.load(@params) @@ -61,14 +91,41 @@ class Index extends App.Controller # send email # clear form - @render() +# @fetch() + auth = new App.Auth + auth.login( + data: { + username: @params.login, + password: @params.password, + }, + success: @success +# error: @error, + ) # error: => # @modalHide() ) -Config.Routes['getting_started'] = Index -#class App.GetStarted extends App.Router -# routes: -# 'getting_started': Index -#Config.Controller.push App.GetStarted; \ No newline at end of file + success: (data, status, xhr) => + @log 'login:success', data + + if @master_user + # login check + auth = new App.Auth + auth.loginCheck() + + # add notify + Spine.trigger 'notify:removeall' +# @notify +# type: 'success', +# msg: 'Thanks for joining. Email sent to "' + @params.email + '". Please verify your email address.' + + @el.find('.master_user').fadeOut('slow', => + @el.find('.agent_user').fadeIn() + ) + # redirect to # +# @navigate '#getting_started' +# @fetch() + + +Config.Routes['getting_started'] = Index diff --git a/app/assets/javascripts/app/index.js.coffee b/app/assets/javascripts/app/index.js.coffee index 6f137d4f1..368f914af 100644 --- a/app/assets/javascripts/app/index.js.coffee +++ b/app/assets/javascripts/app/index.js.coffee @@ -92,6 +92,21 @@ class App.Auth extends App.Ajax success: (data, status, xhr) => console.log 'logincheck:success', data + # if session is not valid + if data.error + + # update config + for key, value of data.config + window.Config[key] = value + + # empty session + window.Session = {} + + # rebuild navbar with new navbar items + Spine.trigger 'navrebuild' + + return false; + # set avatar if !data.session.image data.session.image = 'http://placehold.it/48x48' diff --git a/app/assets/javascripts/app/views/getting_started.jst.eco b/app/assets/javascripts/app/views/getting_started.jst.eco index 428e076a5..561994d4b 100644 --- a/app/assets/javascripts/app/views/getting_started.jst.eco +++ b/app/assets/javascripts/app/views/getting_started.jst.eco @@ -4,12 +4,21 @@
-
+ <% if @master_user: %> +
+

Master Agent

+
+ <%- @form_master %> + +
+
+ <% end %> +

Invite Agents

- <%- @form %> + <%- @form_agent %> +
-

Tour

diff --git a/app/controllers/getting_started_controller.rb b/app/controllers/getting_started_controller.rb new file mode 100644 index 000000000..1fec2cccd --- /dev/null +++ b/app/controllers/getting_started_controller.rb @@ -0,0 +1,28 @@ +class GettingStartedController < ApplicationController + + def index + + # check if first user already exists + master_user = 0 + count = User.all.count() + if count == 1 + master_user = 1 + end + + # get all groups + @groups = Group.where( :active => true ) + @roles = Role.where( :active => true ) + + # return result + respond_to do |format| + format.json { + render :json => { + :master_user => master_user, + :groups => @groups, + :roles => @roles, + } + } + end + end + +end \ No newline at end of file diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index eda3b0580..006860483 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -55,16 +55,23 @@ class UsersController < ApplicationController # POST /users.json def create @user = User.new(params[:user]) -# params[:user][:role_ids] = params[:role_ids] -# logger.debug params[:user].inspect @user.created_by_id = (current_user && current_user.id) || 1 respond_to do |format| if @user.save # if it's a signup, add user to customer role if @user.created_by_id == 1 - role_id = Role.where( :name => 'Customer' ).first.id - @user.role_ids = [role_id] + + # check if it's first user + count = User.all.count() + role_ids = [] + if count <= 2 + role_ids.push Role.where( :name => 'Admin' ).first.id + role_ids.push Role.where( :name => 'Agent' ).first.id + else + role_ids.push Role.where( :name => 'Customer' ).first.id + end + @user.role_ids = role_ids # else do assignment as defined else @@ -78,6 +85,7 @@ class UsersController < ApplicationController # send inviteation if needed if params[:invite] + # logger.debug('IIIIIIIIIIIIIIIIIIIIIIIIIIIIII') # exit '123' end diff --git a/config/routes.rb b/config/routes.rb index 745aec42d..f52c1dab2 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -39,6 +39,9 @@ Zammad::Application.routes.draw do # networks resources :networks, :only => [:create, :show, :index, :update, :destroy] + # getting_started + match '/getting_started', :to => 'getting_started#index' + # sessions resources :sessions, :only => [:create, :destroy, :show] match '/signin', :to => 'sessions#create'