diff --git a/ui/index.jsp b/ui/index.jsp index fd6eaf0fb52..a645c04fade 100644 --- a/ui/index.jsp +++ b/ui/index.jsp @@ -1414,7 +1414,7 @@ - + diff --git a/ui/scripts/projects.js b/ui/scripts/projects.js index 690c4931095..0e8b24e87b6 100644 --- a/ui/scripts/projects.js +++ b/ui/scripts/projects.js @@ -2,14 +2,28 @@ cloudStack.projects = { add: function(args) { setTimeout(function() { - args.response.success({ + $.ajax({ + url: createURL('createProject'), data: { + account: args.context.users[0].account, + domainId: args.context.users[0].domainid, name: args.data['project-name'], - displayText: args.data['project-display-text'], - users: [] + displayText: args.data['project-display-text'] + }, + dataType: 'json', + async: true, + success: function(data) { + args.response.success({ + data: { + id: data.createprojectresponse.id, + name: args.data['project-name'], + displayText: args.data['project-display-text'], + users: [] + } + }); } }); - }, 1000); + }, 100); }, addUserForm: { noSelect: true, @@ -20,8 +34,8 @@ select: function(args) { args.response.success({ data: [ - { name: 'user', description: 'User' }, - { name: 'admin', description: 'Admin' } + { name: 'User', description: 'User' }, + { name: 'Admin', description: 'Admin' } ] }); } @@ -31,15 +45,26 @@ add: { label: 'Invite', action: function(args) { - setTimeout(function() { - cloudStack.context.projects[0].users.push(args.data); - args.response.success({ - notification: { - label: 'Added user to project', - poll: testData.notifications.testPoll - } - }); - }, 100); + $.ajax({ + url: createURL('addAccountToProject'), + data: { + projectId: cloudStack.context.projects[0].id, + account: args.data.username + }, + dataType: 'json', + async: true, + success: function(data) { + args.response.success({ + _custom: { + jobId: data.addaccounttoprojectresponse.jobid + }, + notification: { + label: 'Added user to project', + poll: pollAsyncJobResult + } + }); + } + }); } }, actionPreFilter: function(args) { @@ -83,25 +108,50 @@ // Project users data provider dataProvider: function(args) { - var data = cloudStack.context.projects ? - cloudStack.context.projects[0].users : []; - - setTimeout(function() { - args.response.success({ - data: data - }); - }, 100); + $.ajax({ + url: createURL('listProjectAccounts'), + data: { + role: 'Admin, User', + projectId: cloudStack.context.projects[0].id + }, + dataType: 'json', + async: true, + success: function(data) { + args.response.success({ + data: $.map(data.listprojectaccountsresponse.projectaccount, function(elem) { + return { + id: elem.accountid, + username: elem.account, + role: elem.role + }; + }) + }); + } + }); } }, // Project listing data provider dataProvider: function(args) { var user = args.context.users[0]; - setTimeout(function() { - args.response.success({ - data: user.username == 'bfederle' ? [] : testData.data.projects - }); - }, 200); + + $.ajax({ + url: createURL('listProjects'), + data: { + accountId: user.userid + }, + dataType: 'json', + async: true, + success: function(data) { + args.response.success({ + data: $.map(data.listprojectsresponse.project, function(elem) { + return $.extend(elem, { + displayText: elem.displaytext + }); + }) + }); + } + }); } }; } (cloudStack, testData)); \ No newline at end of file