-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #91 from rescuedcode/add_company_switcher
Add company switcher
- Loading branch information
Showing
8 changed files
with
81 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
app/assets/javascripts/views/_shared/company_switcher.js.coffee
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
@ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters