Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
Checking mergeability… Don't worry, you can still create the pull request.
  • 4 commits
  • 8 files changed
  • 0 commit comments
  • 2 contributors
Commits on Feb 18, 2013
@Veejay Veejay Feature [#39518117] Re-add company switcher
Added the feature back to the app, but just like the year filter, it
needs to be DRY'd up before the merge happens.
d79e24b
Commits on Feb 19, 2013
@Veejay Veejay Feature [#39518117] Re-add company switcher
Moved company switcher to general layout template to avoid duplication.
dba1753
@Veejay Veejay Feature [#39518117] Re-add company switcher
Removes unneeded modification to company decorator.
0fb96a4
Commits on Mar 19, 2013
@fermion fermion Merge pull request #91 from rescuedcode/add_company_switcher
Add company switcher
5c2102a
View
1  app/assets/javascripts/models/user.js.coffee
@@ -81,6 +81,7 @@ class window.StaffPlan.Models.User extends StaffPlan.Model
first_name: @get("first_name")
last_name: @get("last_name")
email: @get("email")
+ current_company_id: @get("current_company_id")
dateChanged: (event) ->
event.preventDefault()
View
1  app/assets/javascripts/staffplan-app.coffee
@@ -22,6 +22,7 @@ window.StaffPlan =
initialize: (data) ->
@users = new StaffPlan.Collections.Users data.users
@projects = new StaffPlan.Collections.Projects data.projects
+ @userCompanies = data.userCompanies
@clients = new StaffPlan.Collections.Clients data.clients
@assignments = new StaffPlan.Collections.Assignments data.assignments
@currentCompany = data.currentCompany
View
18 app/assets/javascripts/templates/shared.templates.js.coffee
@@ -13,6 +13,24 @@ _templates =
</ul>
</div>
'''
+ companySwitcher: '''
+ <div class="btn-group btn-mini">
+ <a class="btn btn-mini dropdown-toggle" data-toggle="dropdown" data-bypass href="#">
+ {{currentCompanyName}}
+ <span class="caret"></span>
+ </a>
+ <ul class="dropdown-menu">
+ {{#each companies}}
+ <li>
+ <a href="#" data-company-id="{{id}}" class="switcher" data-bypass>
+ {{name}}
+ </a>
+ </li>
+ {{/each}}
+ </ul>
+ </div>
+ '''
StaffPlan.Templates.Shared =
yearFilter: Handlebars.compile _templates.yearFilter
+ companySwitcher: Handlebars.compile _templates.companySwitcher
View
6 app/assets/javascripts/views/_shared/_staffplan.view.js.coffee
@@ -4,5 +4,9 @@ class StaffPlan.View extends Support.CompositeView
@$el.html StaffPlan.Templates.Layouts.application
currentUserId: StaffPlan.currentUser.id
+
+ if StaffPlan.userCompanies.length > 1
+ companySwitcher = new StaffPlan.Views.Shared.CompanySwitcher
+ @$el.find('header .inner ul:first').append companySwitcher.render().el
- $( document.body ).trigger( 'view:rendered' );
+ $( document.body ).trigger( 'view:rendered' );
View
25 app/assets/javascripts/views/_shared/company_switcher.js.coffee
@@ -0,0 +1,25 @@
+class StaffPlan.Views.Shared.CompanySwitcher extends Backbone.View
+ tagName: "li"
+ className: "company-switcher"
+
+ initialize: ->
+
+ events:
+ "click a.switcher": "changeCompany"
+
+ changeCompany: (event) ->
+ event.preventDefault()
+ event.stopPropagation()
+ selectedCompanyId = $(event.target).data('company-id')
+ user = StaffPlan.users.get StaffPlan.currentUser.id
+ user.save {current_company_id: selectedCompanyId},
+ success: (model, response, options) ->
+ window.location.href = "/staffplans/#{user.id}"
+ , error: (model, xhr, options) ->
+ alert "An error occurred while switching companies. Please try again."
+ render: ->
+ @$el.html StaffPlan.Templates.Shared.companySwitcher
+ userId: StaffPlan.currentUser.id
+ companies: _.select(StaffPlan.userCompanies, (obj) -> (obj.id isnt StaffPlan.currentCompany.id))
+ currentCompanyName: StaffPlan.currentCompany.name
+ @
View
22 app/assets/stylesheets/screen.css.scss
@@ -168,6 +168,28 @@ body {
line-height: 24px;
}
+ &.company-switcher {
+
+ li {
+ margin-left: 5px;
+ }
+
+ a {
+ line-height: 26px;
+ }
+ span.caret {
+ margin-top: 11px;
+ }
+
+ ul {
+ z-index: 9999;
+
+ li {
+ display: block;
+ }
+ }
+ }
+
&.year-filter {
li {
View
8 app/decorators/user_decorator.rb
@@ -96,6 +96,14 @@ def project_json(project)
end
end
end
+
+ def companies_as_json
+ Jbuilder.encode do |json|
+ json.array! user.companies do |json, company|
+ json.(company, :id, :name)
+ end
+ end
+ end
def current_company_selector
init_haml_helpers
View
1  app/views/shared/_backbone_bootstrap.html.haml
@@ -2,6 +2,7 @@
:erb
{
"users": <%= current_user.current_company.users_json %>,
+ "userCompanies": <%= current_user.decorate.companies_as_json %>,
"clients": <%= current_user.current_company.clients_as_json %>,
"assignments": <%= current_user.current_company.assignments_as_json %>,
"currentCompany": <%= current_user.current_company.self_as_json %>,

No commit comments for this range

Something went wrong with that request. Please try again.