Skip to content

Commit

Permalink
[MNOE-857] Setup divisions when creating a new organization based on …
Browse files Browse the repository at this point in the history
…user role
  • Loading branch information
MAhsenArif committed Jan 26, 2018
1 parent 31e5c60 commit 6d36585
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
@App.controller 'CreateStep1Controller', ($scope, $document, $state, toastr, MnoeAdminConfig, MnoeOrganizations, MnoeMarketplace, MnoErrorsHandler) ->
@App.controller 'CreateStep1Controller', ($scope, $document, $state, toastr, MnoeAdminConfig, MnoeOrganizations, MnoeMarketplace, MnoErrorsHandler, MnoeCurrentUser, MnoeSubTenants) ->
'ngInject'
vm = this

vm.organization = {}
vm.appSearch = ""
vm.subTenantLoading = true
vm.isAdmin = false
vm.selectedSubTenants = {}
vm.sub_tenants = []

vm.toggleApp = (app) ->
app.checked = !app.checked
Expand All @@ -26,6 +30,8 @@
# List of checked apps
vm.organization.app_nids = _.map(_.filter(vm.marketplace.apps, {checked: true}), 'nid') if MnoeAdminConfig.isAppManagementEnabled()

vm.organization.sub_tenant_ids = Object.keys vm.selectedSubTenants

MnoeOrganizations.create(vm.organization).then(
(response) ->
toastr.success('mnoe_admin_panel.dashboard.customers.create_customer.toastr_success', {extraData: {organization_name: vm.organization.name}})
Expand All @@ -49,4 +55,21 @@
vm.marketplace = angular.copy(response.data)
) if MnoeAdminConfig.isAppManagementEnabled()

loadSubTenants = ->
MnoeSubTenants.list(null, null, 'name.desc').then(
(response) ->
vm.sub_tenants = response.data
).finally(-> vm.subTenantLoading = false)

MnoeCurrentUser.getUser().then(
# Display the layout
vm.user = MnoeCurrentUser.user
vm.isAdmin = vm.user.admin_role == 'admin'
if vm.isAdmin
loadSubTenants()
else
vm.selectedSubTenants[vm.user.mnoe_sub_tenant_id] = true
vm.subTenantLoading = false
)

return
32 changes: 31 additions & 1 deletion src/app/views/customers/create-step-1/create-step-1.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,37 @@ <h1 translate>mnoe_admin_panel.dashboard.customers.create_customer.create_custom
</mno-widget-body>
</mno-widget>

<button type="submit" class="btn btn-danger pull-right top-buffer-2" ng-click="vm.submitOrganisation()" ng-disabled="vm.isLoading">
<mno-widget ng-if="vm.isAdmin" icon="fa-institution" heading="{{'mnoe_admin_panel.dashboard.customers.create_customer.division_details' | translate}}" class="top-buffer-2" is-loading="vm.subTenantLoading">
<mno-widget-header></mno-widget-header>
<mno-widget-body>
<div class='row'>
<div class='col-lg-6 col-md-offset-3'>
<table class='table table-striped table-centered'>
<thead>
<tr>
<th class='col-lg-3'>Division Name</th>
</tr>
</thead>
<tbody ng-show='vm.subTenantLoading'>
<tr>
<td colspan='6' class='text-center'>Loading ...</td>
</tr>
</tbody>
<tbody ng-show='!vm.subTenantLoading'>
<tr ng-repeat='sub_tenant in vm.sub_tenants'>
<td>{{sub_tenant.name}}</td>
<td class='text-center'>
<input type='checkbox' ng-model='vm.selectedSubTenants[sub_tenant.id]'>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</mno-widget-body>
</mno-widget>

<button type="submit" class="btn btn-danger pull-right top-buffer-2" ng-click="vm.submitOrganisation()" ng-disabled="vm.isLoading || vm.selectedSubTenants.length == 0">
<span ng-show="vm.isLoading">
<i class="fa fa-spinner fa-pulse fa-fw"></i>
</span>
Expand Down
1 change: 1 addition & 0 deletions src/locales/en-AU.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"mnoe_admin_panel.dashboard.customers.invite_user_modal.toastr_error": "An error occurred while sending an email to {email}. Please try again...",
"mnoe_admin_panel.dashboard.customers.create_customer.create_customer": "Create a new customer",
"mnoe_admin_panel.dashboard.customers.create_customer.organization_details": "Organisation details",
"mnoe_admin_panel.dashboard.customers.create_customer.division_details": "Division details",
"mnoe_admin_panel.dashboard.customers.create_customer.organization_name": "Organisation name",
"mnoe_admin_panel.dashboard.customers.create_customer.name": "Name",
"mnoe_admin_panel.dashboard.customers.create_customer.required.name": "Name is required",
Expand Down

0 comments on commit 6d36585

Please sign in to comment.