Index: lams_central/web/includes/javascript/orgGrouping.js =================================================================== RCS file: /usr/local/cvsroot/lams_central/web/includes/javascript/orgGrouping.js,v diff -u -r1.2.2.4 -r1.2.2.5 --- lams_central/web/includes/javascript/orgGrouping.js 31 Oct 2016 16:16:34 -0000 1.2.2.4 +++ lams_central/web/includes/javascript/orgGrouping.js 3 Nov 2016 16:04:03 -0000 1.2.2.5 @@ -41,133 +41,115 @@ * 1) it was taken from Authoring dialog for groups-to-branches mapping * 2) two types of groups: course and branching could easily get mixed */ - if (!gtbDialog) { - // create the dialog - gtbDialog = $('#groupMappingDialog') - .dialog({ - 'autoOpen' : false, - 'modal' : true, - 'show' : 'fold', - 'hide' : 'fold', - 'width' : 650, - 'height' : 400, - 'title' : LABELS.COURSE_GROUPS_TO_BRANCHES_MATCH_DIALOG_TITLE, - 'buttons' : [ - { - 'text' : LABELS.OK_BUTTON, - 'click' : function() { - var dialog = $(this), - groupsToBranches = []; + + var groupMappingDialogContents = $('#groupMappingDialogContents').clone().attr('id', null); + $('#branchMappingOKButton', groupMappingDialogContents).click(function(){ + var dialog = $(this).closest('.modal'), + groupsToBranches = []; + + // fill JSON with group pairs + $('.branchMappingBoundItemCell div, .branchMappingFreeItemCell div', dialog).each(function(){ + var groupID = $(this).attr('id'), + boundItem = $(this).data('boundItem'), + branchID = boundItem ? boundItem.attr('id') : null; - // fill JSON with group pairs - $('.branchMappingBoundItemCell div, .branchMappingFreeItemCell div', dialog) - .each(function(){ - var groupID = $(this).attr('id'), - boundItem = $(this).data('boundItem'), - branchID = boundItem ? boundItem.attr('id') : null; - - // add the mapping - if (branchID) { - groupsToBranches.push({ - 'groupID' : groupID, - 'branchID' : branchID - }); - } - }); - - // save the mapping - $.ajax({ - url : LAMS_URL + 'OrganisationGroup.do', - data : { - 'method' : 'saveGroupMappings', - 'mapping' : JSON.stringify(groupsToBranches) - }, - success : function(response) { - // LAMS can reply 200 even if there is an error, so we need OK response - if (response == 'OK') { - // go straight to branching groups for final check - viewGroups(groupingId, true); - } - } - }); - } - } - ], - 'open' : function(){ - var dialog = $(this), - groupsCell = $('.branchMappingFreeItemCell', dialog), - branchesCell = $('.branchMappingFreeBranchCell', dialog), - groupCell = $('.branchMappingBoundItemCell', dialog), - branchCell = $('.branchMappingBoundBranchCell', dialog); - - // clear out previous entries - $('.branchMappingListCell', dialog).empty(); - - // fetch course and branching groups - $.ajax({ - url : LAMS_URL + 'OrganisationGroup.do', - data : { - 'method' : 'getGroupsForMapping', - 'groupingId' : groupingId, - 'activityID' : groupingActivityId - }, - dataType : 'json', - success : function(response) { - // fill table with course and branching groups - $.each(response.groups, function(){ - var group = this, - groupElem = $('
').click(selectGroupMappingListItem) - .text(group.name).attr('id', group.id); - - $.each(response.branches, function() { - // check if a branching group alread exists with the same name as a course group - if (this.name == group.name) { - var branchElem = $('
').click(selectGroupMappingListItem) - .appendTo(branchCell) - .text(this.name) - .attr('id', this.id) - .data('boundItem', groupElem); - groupElem.appendTo(groupCell).data('boundItem', branchElem); - groupElem = null; - return false; - } - }); - - if (groupElem) { - // no existing mapping was found, make the group available for mapping - groupElem.appendTo(groupsCell); - } - }); - // fill in branch groups - $.each(response.branches, function(){ - $('
').click(selectGroupMappingListItem).appendTo(branchesCell) - .text(this.name).attr('id', this.id); - }); - } - }); - } + // add the mapping + if (branchID) { + groupsToBranches.push({ + 'groupID' : groupID, + 'branchID' : branchID + }); + } }); - - // initialise buttons and labels - $('.branchMappingAddButton', gtbDialog).button({ - 'icons' : { - 'primary' : 'ui-icon-seek-next' + + // save the mapping + $.ajax({ + url : LAMS_URL + 'OrganisationGroup.do', + data : { + 'method' : 'saveGroupMappings', + 'mapping' : JSON.stringify(groupsToBranches) }, - 'text' : false - }).click(function(){ - addGroupMapping(); + success : function(response) { + // LAMS can reply 200 even if there is an error, so we need OK response + if (response == 'OK') { + // go straight to branching groups for final check + viewGroups(groupingId, true); + } + } }); - $('.branchMappingRemoveButton', gtbDialog).button({ - 'icons' : { - 'primary' : 'ui-icon-seek-prev' - }, - 'text' : false - }).click(function(){ - removeGroupMapping(); - }); - } + }); - gtbDialog.dialog('open'); + // initialise the dialog buttons + $('.branchMappingAddButton', groupMappingDialogContents).click(function(){ + addGroupMapping(); + }); + $('.branchMappingRemoveButton', groupMappingDialogContents).click(function(){ + removeGroupMapping(); + }); + + // initialise dialog for matching groups to branches in branching activities + gtbDialog = showDialog('gtbDialog',{ + 'autoOpen' : false, + 'modal' : true, + 'width' : 800, + 'title' : LABELS.COURSE_GROUPS_TO_BRANCHES_MATCH_DIALOG_TITLE, + 'open' : function(){ + var dialog = $(this), + groupsCell = $('.branchMappingFreeItemCell', dialog), + branchesCell = $('.branchMappingFreeBranchCell', dialog), + groupCell = $('.branchMappingBoundItemCell', dialog), + branchCell = $('.branchMappingBoundBranchCell', dialog); + + // clear out previous entries + $('.branchMappingListCell', dialog).empty(); + + // fetch course and branching groups + $.ajax({ + url : LAMS_URL + 'OrganisationGroup.do', + data : { + 'method' : 'getGroupsForMapping', + 'groupingId' : groupingId, + 'activityID' : groupingActivityId + }, + dataType : 'json', + success : function(response) { + // fill table with course and branching groups + $.each(response.groups, function(){ + var group = this, + groupElem = $('
').click(selectGroupMappingListItem) + .text(group.name).attr('id', group.id); + + $.each(response.branches, function() { + // check if a branching group alread exists with the same name as a course group + if (this.name == group.name) { + var branchElem = $('
').click(selectGroupMappingListItem) + .appendTo(branchCell) + .text(this.name) + .attr('id', this.id) + .data('boundItem', groupElem); + groupElem.appendTo(groupCell).data('boundItem', branchElem); + groupElem = null; + return false; + } + }); + + if (groupElem) { + // no existing mapping was found, make the group available for mapping + groupElem.appendTo(groupsCell); + } + }); + // fill in branch groups + $.each(response.branches, function(){ + $('
').click(selectGroupMappingListItem).appendTo(branchesCell) + .text(this.name).attr('id', this.id); + }); + } + }); + } + }, false); + + $('.modal-body', gtbDialog).empty().append(groupMappingDialogContents.show()); + gtbDialog.modal('show'); }; /**