Skip to content

Commit 2d0a436

Browse files
committed
Implemented tenant creation for MPA.
1 parent dfc0243 commit 2d0a436

File tree

3 files changed

+53
-17
lines changed

3 files changed

+53
-17
lines changed

src/AbpCompanyName.AbpProjectName.WebMpa/Views/Tenants/Index.cshtml

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
</div>
3535
</div>
3636

37-
<div class="modal fade" id="TenantCreateModal" tabindex="-1" role="dialog" aria-labelledby="TenantCreateModalLabel">
37+
<div class="modal fade" id="TenantCreateModal" tabindex="-1" role="dialog" aria-labelledby="TenantCreateModalLabel" data-backdrop="static">
3838
<div class="modal-dialog" role="document">
3939
<div class="modal-content">
4040
<form name="tenantCreateForm" role="form" novalidate class="form-validation">
@@ -45,30 +45,27 @@
4545
</div>
4646
<div class="modal-body">
4747

48-
<div class="form-group form-md-line-input form-md-floating-label no-hint">
48+
<div class="form-group">
4949
<label>@L("TenancyName")</label>
50-
<input auto-focus class="form-control" type="text" name="TenancyName" ng-model="vm.tenant.tenancyName" required maxlength="@Tenant.MaxTenancyNameLength" ng-pattern="/@Tenant.TenancyNameRegex/">
51-
</div>
52-
<div>
53-
<span class="help-block text-danger" ng-show="!tenantCreateForm.TenancyName.$valid && tenantCreateForm.TenancyName.$dirty">@L("TenantName_Regex_Description")</span>
50+
<input class="form-control" type="text" name="TenancyName" required maxlength="@Tenant.MaxTenancyNameLength" minlength="2">
5451
</div>
5552

56-
<div class="form-group form-md-line-input form-md-floating-label no-hint">
53+
<div class="form-group">
5754
<label>@L("Name")</label>
58-
<input type="text" name="Name" class="form-control" ng-model="vm.tenant.name" required maxlength="@Tenant.MaxNameLength">
55+
<input type="text" name="Name" class="form-control" required maxlength="@Tenant.MaxNameLength">
5956
</div>
6057

61-
<div class="form-group form-md-line-input form-md-floating-label no-hint">
58+
<div class="form-group">
6259
<label>@L("AdminEmailAddress")</label>
63-
<input type="email" name="AdminEmailAddress" class="form-control" ng-model="vm.tenant.adminEmailAddress" required maxlength="@AbpCompanyName.AbpProjectName.Users.User.MaxEmailAddressLength">
60+
<input type="email" name="AdminEmailAddress" class="form-control" required maxlength="@AbpCompanyName.AbpProjectName.Users.User.MaxEmailAddressLength">
6461
</div>
6562

6663
<p>@L("DefaultPasswordIs", AbpCompanyName.AbpProjectName.Users.User.DefaultPassword)</p>
6764

6865
</div>
6966
<div class="modal-footer">
7067
<button type="button" class="btn btn-default" data-dismiss="modal">@L("Cancel")</button>
71-
<button id="TenantCreateModalSaveButton" type="submit" class="btn btn-primary blue" ng-disabled="tenantCreateForm.$invalid"><i class="fa fa-save"></i> <span>@L("Save")</span></button>
68+
<button type="submit" class="btn btn-primary blue" ng-disabled="tenantCreateForm.$invalid"><i class="fa fa-save"></i> <span>@L("Save")</span></button>
7269
</div>
7370
</form>
7471
</div>
Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,29 @@
11
(function() {
22
$(function() {
33

4-
$('#TenantCreateModalSaveButton').click(function(e) {
4+
var _tenantService = abp.services.app.tenant;
5+
var _$modal = $('#TenantCreateModal');
6+
var _$form = _$modal.find('form');
7+
8+
_$form.validate();
9+
10+
_$form.find('button[type="submit"]').click(function (e) {
511
e.preventDefault();
6-
alert('saving...');
7-
});
812

13+
if (!_$form.valid()) {
14+
return;
15+
}
16+
17+
var tenant = _$form.serializeFormToObject(); //serializeFormToObject is defined in main.js
18+
19+
_tenantService.createTenant(tenant).done(function () {
20+
_$modal.modal('hide');
21+
location.reload(true); //reload page to see new tenant!
22+
});
23+
});
24+
25+
_$modal.on('shown.bs.modal', function () {
26+
_$modal.find('input:not([type=hidden]):first').focus();
27+
});
928
});
1029
})();
Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
1-
(function() {
2-
//...
3-
})();
1+
(function($) {
2+
3+
if (!$) {
4+
return;
5+
}
6+
7+
$.fn.serializeFormToObject = function () {
8+
//serialize to array
9+
var data = $(this).serializeArray();
10+
11+
//add also disabled items
12+
$(':disabled[name]', this).each(function () {
13+
data.push({ name: this.name, value: $(this).val() });
14+
});
15+
16+
//map to object
17+
var obj = {};
18+
data.map(function (x) { obj[x.name] = x.value; });
19+
20+
return obj;
21+
}
22+
23+
})(jQuery);

0 commit comments

Comments
 (0)