Loading users
diff --git a/xos/core/xoslib/static/js/xosContentProvider.js b/xos/core/xoslib/static/js/xosContentProvider.js
index 0baadbb..ff5bfe3 100644
--- a/xos/core/xoslib/static/js/xosContentProvider.js
+++ b/xos/core/xoslib/static/js/xosContentProvider.js
@@ -54,7 +54,7 @@
}
};
})
-.service('ContentProvider', function($resource) {
+.service('ContentProvider', function($resource, $q, User) {
return $resource('/hpcapi/contentproviders/:id/', {id: '@id'}, {
'update': {method: 'PUT'}
});
@@ -326,7 +326,7 @@
}
};
})
-.directive('contentProviderUsers', function($routeParams, ContentProvider, User, lodash) {
+.directive('contentProviderUsers', function($routeParams, ContentProvider, User, lodash, $q) {
return{
restrict: 'E',
controllerAs: 'vm',
@@ -339,7 +339,20 @@
this.cp_users = [];
if($routeParams.id) {
- ContentProvider.get({id: $routeParams.id}).$promise
+ User.query().$promise
+ .then(function(users) {
+ _this.users = users;
+ return ContentProvider.get({id: $routeParams.id}).$promise;
+ })
+ .then(function(res) {
+ for(var i = 0; i < res.users.length; i++) {
+ var url = res.users[i];
+ var id = parseInt(url.substr(url.length - 2).replace('/',''));
+
+ res.users[i] = lodash.find(_this.users, {id: id});
+ }
+ return res;
+ })
.then(function(cp) {
_this.cp = cp;
}).catch(function(e) {
@@ -350,22 +363,30 @@
});
}
- User.query().$promise
- .then(function(users) {
- _this.users = users;
- }).catch(function(e) {
- _this.result = {
- status: 0,
- msg: e.data.detail
- };
- });
-
this.addUserToCp = function(user) {
- _this.cp_users.push(user);
+ _this.cp.users.push(user);
};
this.removeUserFromCp = function(user) {
- lodash.remove(_this.cp_users, user);
+ lodash.remove(_this.cp.users, user);
+ };
+
+ this.saveContentProvider = function(cp) {
+
+ cp.$update()
+ .then(function() {
+ _this.result = {
+ status: 1,
+ msg: 'Content Provider Saved'
+ };
+
+ })
+ .catch(function(e) {
+ _this.result = {
+ status: 0,
+ msg: e.data.detail
+ };
+ });
};
}
};
diff --git a/xos/core/xoslib/static/templates/contentProvider/cp_user.html b/xos/core/xoslib/static/templates/contentProvider/cp_user.html
index e53dadf..0d08984 100644
--- a/xos/core/xoslib/static/templates/contentProvider/cp_user.html
+++ b/xos/core/xoslib/static/templates/contentProvider/cp_user.html
@@ -14,7 +14,6 @@
<div class="span10">
<div ng-repeat="item in vm.cp.users" class="well">
<div class="row-fluid">
- {{item}}
<div class="span3">
{{item.firstname}}
</div>
@@ -32,8 +31,17 @@
</div>
</div>
<hr>
- <form>
- <select ng-model="vm.user" ng-options="u as u.username for u in vm.users" ng-change="vm.addUserToCp(vm.user)"></select>
+ <form ng-submit="vm.saveContentProvider(vm.cp)">
+ <div class="row-fluid">
+ <div class="span8">
+ <select ng-model="vm.user" ng-options="u as u.username for u in vm.users" ng-change="vm.addUserToCp(vm.user)"></select>
+ </div>
+ <div class="span4 text-right">
+ <button class="btn btn-success" disabled="disabled">
+ Save
+ </button>
+ </div>
+ </div>
</form>
</div>
</div>
\ No newline at end of file