User profile editing and password
This commit is contained in:
@@ -1,28 +0,0 @@
|
||||
(function() {
|
||||
'use strict';
|
||||
|
||||
window.app.controller('EditProfileController',
|
||||
function($http, model) {
|
||||
var vm = this;
|
||||
|
||||
vm.profile = model;
|
||||
vm.save = save;
|
||||
|
||||
function save() {
|
||||
vm.saving = true;
|
||||
vm.errorMessage = null;
|
||||
vm.success = false;
|
||||
|
||||
$http.post("/Profile/Update", vm.profile)
|
||||
.success(function() {
|
||||
vm.success = true;
|
||||
})
|
||||
.error(function(msg) {
|
||||
vm.errorMessage = msg;
|
||||
})
|
||||
.finally(function() {
|
||||
vm.saving = false;
|
||||
});
|
||||
}
|
||||
});
|
||||
})();
|
||||
@@ -0,0 +1,13 @@
|
||||
(function() {
|
||||
"use strict";
|
||||
|
||||
window.app.controller("ProfileController",
|
||||
[
|
||||
'$scope', 'profileSvc',
|
||||
function ($scope, profileSvc) {
|
||||
var vm = this;
|
||||
|
||||
vm.profile = profileSvc.profile;
|
||||
}
|
||||
]);
|
||||
})();
|
||||
@@ -0,0 +1,43 @@
|
||||
(function() {
|
||||
"use strict";
|
||||
|
||||
window.app.directive('profileEdit', function (){
|
||||
return {
|
||||
scope: {
|
||||
profile: "="
|
||||
},
|
||||
templateUrl: '/profile/template/profileEdit.tmpl.cshtml',
|
||||
controller: controller,
|
||||
controllerAs: 'vm'
|
||||
}
|
||||
});
|
||||
|
||||
controller.$inject = ['$scope', 'profileSvc'];
|
||||
function controller($scope, profileSvc) {
|
||||
var vm = this;
|
||||
vm.profile = $scope.profile;
|
||||
|
||||
vm.saving = false;
|
||||
vm.success = false;
|
||||
vm.errorMessages = [];
|
||||
vm.save = save;
|
||||
|
||||
function save() {
|
||||
vm.saving = true;
|
||||
vm.success = false;
|
||||
angular.copy([], vm.errorMessages);
|
||||
|
||||
profileSvc.update(vm.profile)
|
||||
.success(function () {
|
||||
vm.success = true;
|
||||
vm.form.$setPristine();
|
||||
})
|
||||
.error(function (data) {
|
||||
vm.errorMessages = angular.copy(data.errorMessages, vm.errorMessages);
|
||||
})
|
||||
.finally(function () {
|
||||
vm.saving = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
})();
|
||||
@@ -0,0 +1,32 @@
|
||||
(function() {
|
||||
window.app.factory("profileSvc",
|
||||
[
|
||||
"$http",
|
||||
function($http) {
|
||||
var profile = {};
|
||||
|
||||
loadProfile();
|
||||
|
||||
var svc = {
|
||||
update: update,
|
||||
profile: profile
|
||||
};
|
||||
|
||||
return svc;
|
||||
|
||||
function loadProfile() {
|
||||
$http.post("/Profile/Get")
|
||||
.success(function(data) {
|
||||
angular.copy(data, profile);
|
||||
});
|
||||
}
|
||||
|
||||
function update(updatedProfile) {
|
||||
return $http.post("/Profile/Update", updatedProfile)
|
||||
.success(function(data) {
|
||||
angular.copy(data, profile);
|
||||
});
|
||||
}
|
||||
}
|
||||
]);
|
||||
})();
|
||||
@@ -0,0 +1,28 @@
|
||||
@using InventoryTraker.Web.Helpers
|
||||
@model InventoryTraker.Web.Models.ProfileForm
|
||||
<form novalidate
|
||||
name="vm.form"
|
||||
ng-submit="vm.form.$valid && vm.save()">
|
||||
<fieldset ng-disabled="vm.saving">
|
||||
<div class="panel">
|
||||
<div class="panel-body">
|
||||
|
||||
<status-message message="vm.statusMessage"></status-message>
|
||||
<error-list errors="vm.errorMessages"></error-list>
|
||||
<div class="alert alert-success" ng-show="vm.success && vm.form.$pristine">
|
||||
<span class="fa fa-check"></span>
|
||||
Changes saved
|
||||
</div>
|
||||
|
||||
@Html.Angular().FormForModel("vm.profile")
|
||||
|
||||
</div>
|
||||
|
||||
<div class="panel-footer">
|
||||
<button class="btn btn-success" ng-disabled="vm.form.$invalid || vm.form.$pristine">Save</button>
|
||||
<a class="btn btn-default" href="/">Cancel</a>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</fieldset>
|
||||
</form>
|
||||
Reference in New Issue
Block a user