move display users roles to a knockout bind to prepare update mode

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1228215 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Olivier Lamy 2012-01-06 15:00:56 +00:00
parent f752ebe059
commit cfd88272a0
3 changed files with 22 additions and 11 deletions

View File

@ -61,10 +61,11 @@
<button class="btn" id="user-create-form-cancel-button">${i18n('cancel')}</button> <button class="btn" id="user-create-form-cancel-button">${i18n('cancel')}</button>
</form> </form>
</div> </div>
<div class="span6 columns" id="user-edit-roles-view" style="display:none"> <div class="span6 columns" id="user-edit-roles" style="display:none">
<div class="page-header"> <div class="page-header">
<h3>${$.i18n.prop('effective.roles')}</h3> <h3>${$.i18n.prop('effective.roles')}</h3>
</div> </div>
<div id="user-edit-roles-view"></div>
</div> </div>
</div> </div>

View File

@ -99,6 +99,8 @@
<script id="user_edit_roles_tmpl" type="text/x-jquery-tmpl"> <script id="user_edit_roles_tmpl" type="text/x-jquery-tmpl">
<ul> <ul>
${name} {{each $data.roles}}
<li>${$value.name}</li>
{{/each}}
</ul> </ul>
</script> </script>

View File

@ -61,7 +61,7 @@ $(function() {
window.redbackModel.createUser=true; window.redbackModel.createUser=true;
$("#main-content #user-edit").remove(); $("#main-content #user-edit").remove();
$('#main-content #user-create').show(); $('#main-content #user-create').show();
ko.renderTemplate("redback/user-edit-tmpl", new user(), null, $("#createUserForm").get(0),"replaceChildren"); ko.renderTemplate("redback/user-edit-tmpl", new User(), null, $("#createUserForm").get(0),"replaceChildren");
$("#main-content #createUserForm #user-create").delegate("#user-create-form-cancel-button", "click keydown", function(e) { $("#main-content #createUserForm #user-create").delegate("#user-create-form-cancel-button", "click keydown", function(e) {
e.preventDefault(); e.preventDefault();
activateUsersGridTab(); activateUsersGridTab();
@ -146,13 +146,22 @@ $(function() {
user.update(); user.update();
}); });
$.ajax("restServices/redbackServices/roleManagementService/getEffectivelyAssignedRoles/"+user.username(), { $("#user-edit-roles").show();
$( "#user-edit-roles-view" ).append(smallSpinnerImg());
$.ajax("restServices/redbackServices/roleManagementService/getEffectivelyAssignedRoles/"+encodeURIComponent(user.username()), {
type: "GET", type: "GET",
async: false, async: false,
dataType: 'json', dataType: 'json',
success: function(data) { success: function(data) {
$( "#user-edit-roles-view" ).append( jQuery("#user_edit_roles_tmpl" ).tmpl( data.role ) );
$("#user-edit-roles-view").show(); $("#user-edit-roles-view").show();
var mappedRoles = $.map(data.role, function(item) {
return mapRole(item);
});
//$( "#user-edit-roles-view" ).append( jQuery("#user_edit_roles_tmpl" ).tmpl( data.role ) );
viewModel.roles=mappedRoles;
$( "#user-edit-roles-view").attr("data-bind",'template: {name:"user_edit_roles_tmpl"}');
ko.applyBindings(viewModel,$("#user-edit-roles-view").get(0));
removeSmallSpinnerImg();
} }
} }
); );
@ -160,6 +169,11 @@ $(function() {
} }
} }
userViewModel=function(user) {
this.user=user;
this.roles = ko.observableArray(new Array());
}
/** /**
* called from the menu to display tabs with users grid * called from the menu to display tabs with users grid
*/ */
@ -185,12 +199,6 @@ $(function() {
$("#users-view-tabs-content #users-view").addClass("active"); $("#users-view-tabs-content #users-view").addClass("active");
} }
userViewModel=function(user) {
this.user=user;
}
activateUsersGridTab=function(){ activateUsersGridTab=function(){
$("#main-content #users-view-tabs li").removeClass("active"); $("#main-content #users-view-tabs li").removeClass("active");
$("#main-content #users-view-tabs-content div").removeClass("active"); $("#main-content #users-view-tabs-content div").removeClass("active");