Skip to content
Snippets Groups Projects
Commit d0a6371b authored by Allen Gilliland's avatar Allen Gilliland
Browse files

superadmin orgs were not actually using our form processing on the controller.

parent 4c1f9dda
Branches
Tags
No related merge requests found
......@@ -2,7 +2,8 @@
/*global _*/
var OrganizationControllers = angular.module('superadmin.organization.controllers', [
'corvus.services'
'corvus.services',
'metabase.forms'
]);
OrganizationControllers.controller('OrganizationListController', ['$scope', 'Organization',
......@@ -31,30 +32,37 @@ OrganizationControllers.controller('OrganizationListController', ['$scope', 'Org
}
]);
OrganizationControllers.controller('OrganizationDetailController', ['$scope', '$routeParams', '$location', 'Organization',
function($scope, $routeParams, $location, Organization) {
OrganizationControllers.controller('OrganizationDetailController', ['$scope', '$routeParams', '$location', 'Organization', 'MetabaseForm',
function($scope, $routeParams, $location, Organization, MetabaseForm) {
var formFields = {
slug: 'slug',
name: 'name',
description: 'description',
logo_url: 'logo_url'
};
$scope.organization = undefined;
// initialize on load
if ($routeParams.orgId) {
// editing an existing organization
Organization.get({
'orgId': $routeParams.orgId
},
function(org) {
$scope.organization = org;
},
function(error) {
console.log("Error getting organization: ", error);
// TODO - should be a 404 response
});
'orgId': $routeParams.orgId
}, function (org) {
$scope.organization = org;
}, function (error) {
console.log("Error getting organization: ", error);
// TODO - should be a 404 response
});
// provide a relevant save() function
$scope.save = function(organization) {
Organization.update(organization, function(org) {
MetabaseForm.clearFormErrors($scope.form, formFields);
Organization.update(organization, function (org) {
$scope.organization = org;
}, function(error) {
console.log(error);
$scope.form.success = true;
}, function (error) {
MetabaseForm.parseFormErrors($scope.form, formFields, error);
});
};
......@@ -64,15 +72,13 @@ OrganizationControllers.controller('OrganizationDetailController', ['$scope', '$
// provide a relevant save() function
$scope.save = function(organization) {
// TODO - some simple validation checks
Organization.create(organization,
function(org) {
$location.path('/superadmin/organization/' + org.id);
},
function(error) {
console.log(error);
});
MetabaseForm.clearFormErrors($scope.form, formFields);
Organization.create(organization, function (org) {
$scope.form.success = true;
$location.path('/superadmin/organization/' + org.id);
},function (error) {
MetabaseForm.parseFormErrors($scope.form, formFields, error);
});
};
}
......
......@@ -14,12 +14,12 @@
<div class="Form-field" ng-class="{'Form--fieldError': form.slug.$error.message !== undefined}">
<mb-form-label form="form" display-name="Slug" field-name="slug"></mb-form-label>
<input class="Form-input Form-offset full" name="slug" placeholder="A short name to go in URLs" ng-model="organization.slug" required />
<input class="Form-input Form-offset full" name="slug" placeholder="A short name to go in URLs" ng-model="organization.slug" ng-disabled="organization.id" required />
</div>
<div class="Form-field" ng-class="{'Form--fieldError': form.name.$error.message !== undefined}">
<mb-form-label form="form" display-name="Name" field-name="name"></mb-form-label>
<input class="Form-input Form-offset full" name="name" ng-model="organization.name" placeholder="What is the name of your organization?" required />
<input class="Form-input Form-offset full" name="name" ng-model="organization.name" placeholder="What is the name of your organization?" />
<span class="Form-charm"></span>
</div>
......@@ -39,6 +39,8 @@
<button class="Button" ng-class="{'Button--primary': form.$valid}" ng-click="save(organization)" ng-disabled="!form.$valid">
Save
</button>
<span class="Form--fieldError" ng-show="form.$error.message">{{form.$error.message}}</span>
<span class="FormSuccess" ng-if="form.success" cv-delayed-call="form.success = undefined">Successfully saved</span>
</div>
</form>
</div>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment