Index: lams_central/web/includes/javascript/groupDisplay.js =================================================================== RCS file: /usr/local/cvsroot/lams_central/web/includes/javascript/groupDisplay.js,v diff -u -r1.37.2.29 -r1.37.2.30 --- lams_central/web/includes/javascript/groupDisplay.js 27 Oct 2016 11:43:35 -0000 1.37.2.29 +++ lams_central/web/includes/javascript/groupDisplay.js 27 Oct 2016 16:02:36 -0000 1.37.2.30 @@ -1,685 +1,16 @@ -function initMainPage() { - initButtons(); - - //in case active course is not yet chosen by user, select the fist one from the list - - - if (activeOrgId > 0) { - //$('#orgTabs').tabs({ - // 'activate' : function(event, ui){ - // loadOrganisation(); - // } - //}).addClass('ui-tabs-vertical ui-helper-clearfix') - // .find('li').removeClass('ui-corner-top').addClass('ui-corner-left'); - - loadOrganisation(); +/** +* Called from within Course Groups dialog, it saves groups and loads grouping +* page. +*/ +function saveOrgGroups() { + var groupsSaved = $('#dialogOrgGroup iframe')[0].contentWindow.saveGroups(); + if (groupsSaved) { + showOrgGroupDialogContents(null, 460, 460, + LAMS_URL + 'OrganisationGroup.do?method=viewGroupings&organisationID=' + + $('#dialogOrgGroup').dialog('option', 'orgID')); } - - refreshPrivateNotificationCount(); - } - -function selectOrganisation(newOrgId) { - //remove active CSS class from the old org - if (activeOrgId > 0) { - $("#org-row-" + activeOrgId).removeClass("active"); - $("#org-row-" + activeOrgId + " a>i").remove(); - } - - //add active CSS class - $("#org-row-" + newOrgId).addClass("active"); - $("#org-row-" + newOrgId + " a").append( "" ) - - activeOrgId = newOrgId; - loadOrganisation(); - - //store last visited - // TODO - } - -function loadOrganisation() { - $("#org-container").load( - "displayGroup.do", - { - stateId : stateId, - orgId : activeOrgId - }, - function() { - initButtons("org-container"); - } - ); } - -function initButtons(containerId) { - var container = containerId ? $('#' + containerId) : document; - - $(".ui-button", container).button(); - $(".split-ui-button", container).each(function(){ - var buttonContainer = $(this), - buttons = buttonContainer.children(); - - buttons.first().button() - .next().button({ - text : false, - icons : { - primary : "ui-icon-triangle-1-s" - } - }); - - buttonContainer.buttonset().next().hide().menu(); - - buttons.each(function(){ - var button = $(this); - if (!button.attr('onclick')) { - button.click(function() { - var menu = $(this).parent().next().show().position({ - my : "right top", - at : "right bottom", - of : $(this).parent() - }); - $(document).one("click", function() { - menu.hide(); - }); - return false; - }); - } - }); - }); -} - - -function makeOrgSortable(orgId) { - var org = jQuery("div.orgTab[id$='-org-" + orgId + "']"); - $(".lesson-table", org).each(function() { - makeSortable(this); - }); - - $("a.sorting", org).attr({ - "onClick" : null, - "title" : LABELS.SORTING_DISABLE - }).off('click').click(function(){ - makeOrgUnsortable(orgId); - }).find("img") - .attr("src", "images/sorting_enabled.gif"); - -} - -function makeOrgUnsortable(orgId) { - var org = jQuery("div.orgTab[id$='-org-" + orgId + "']"); - $(".lesson-table", org).each(function() { - $(this).sortable('destroy'); - }); - - $("a.sorting", org).attr({ - "onClick" : null, - "title" : LABELS.SORTING_ENABLE - }).off('click').click(function(){ - makeOrgSortable(orgId); - }).find("img") - .attr("src", "images/sorting_disabled.gif"); -} - -function makeSortable(element) { - $(element).sortable({ - axis : "y", - delay : 100, - tolerance : 'pointer', - cursor : 'n-resize', - helper : function(e, tr) { - var $originals = tr.children(); - var $helper = tr.clone(); - $helper.children().each(function(index) { - // Set helper cell sizes to match the original - // sizes - $(this).width($originals.eq(index).width()) - }); - return $helper; - }, - forceHelperSize : true, - forcePlaceholderSize : true, - containment : 'parent', - stop : function() { - var ids = $(this).sortable('toArray'); - - var jLessonsId = $(this).attr("id"); - var dashIndex = jLessonsId.indexOf("-"); - var orgId = (dashIndex > 0 ? jLessonsId.substring(0, - dashIndex) : jLessonsId); - - $.ajax({ - url : "servlet/saveLessonOrder", - data : { - orgId : orgId, - ids : ids.join(",") - }, - error : function() { - loadOrganisation(); - } - }); - } - }).disableSelection(); -} - - - -function showMonitorLessonDialog(lessonID) { - var id = "dialogMonitorLesson" + lessonID, - dialog = showDialog(id, { - 'data' : { - 'lessonID' : lessonID - }, - 'autoOpen' : false, - 'height' : 600, - 'width' : 1024, - 'title' : LABELS.MONITORING_TITLE, - 'open' : function() { - // load contents after opening the dialog - $('iframe', this).attr('src', LAMS_URL - + 'home.do?method=monitorLesson&lessonID=' - + $(this).data('lessonID')); - }, - - }, true); - - // if it was just created - if (dialog) { - // tell the dialog contents that it was resized - $('.modal-content', dialog).on('resizestop', resizeSequenceCanvas); - // initial resize - $('iframe', dialog).load(resizeSequenceCanvas); - - dialog.modal('show'); - } -} - -function resizeSequenceCanvas(){ - var body = $('.modal-body'), - frame = $('iframe', body); - if (frame.length > 0) { - var win = frame[0].contentWindow || frame[0].contentDocument; - if (win.resizeSequenceCanvas) { - win.resizeSequenceCanvas(body.width(), body.height()); - } - } -} - - -function showAddLessonDialog(orgID) { - showDialog("dialogAddLesson", { - 'data' : { - 'orgID' : orgID - }, - 'modal' : true, - 'height' : 740, - 'width' : 'auto', - 'title' : LABELS.ADD_LESSON_TITLE, - 'open' : function() { - var dialog = $(this); - // load contents after opening the dialog - $('iframe', dialog) - .attr('src', LAMS_URL - + 'home.do?method=addLesson&organisationID=' - + dialog.data('orgID')); - $(this).css("maxWidth", "850px").css("margin", "auto"); - - // in case of mobile devices allow iframe scrolling - if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) { - setTimeout(function() { - dialog.css({ - 'overflow-y' : 'scroll', - '-webkit-overflow-scrolling' : 'touch' - }); - },500); - } - } - }); -} - - -function showMyProfileDialog() { - showDialog("dialogMyProfile", { - 'title' : LABELS.MY_PROFILE, - 'modal' : true, - 'width' : 'auto', - 'height' : 430, - 'open' : function() { - var dialog = $(this); - // load contents after opening the dialog - $('iframe', dialog).attr('src', LAMS_URL + 'index.do?method=profile'); - $(this).css("maxWidth", "770px").css("margin", "auto"); - - // in case of mobile devices allow iframe scrolling - if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) { - setTimeout(function() { - dialog.css({ - 'overflow-y' : 'scroll', - '-webkit-overflow-scrolling' : 'touch' - }); - },500); - } - } - }); -} - - -function updateMyProfileDialogSettings(title, height) { - var id = 'dialogMyProfile'; - var dialog = $("#" + id, window.parent.document); - - // update height - $('.modal-content', dialog).height(height); - if (height.match("%$")) { - $('.modal-dialog', dialog).height(height); - } else { - $('.modal-dialog', dialog).height(''); - } - - // update title - $('.modal-title', dialog).attr('id', id + 'Label').text(title); -} - - -function showOrgGroupDialog(orgID) { - showDialog("dialogOrgGroup", { - 'data' : { - 'orgID' : orgID - }, - 'modal' : true, - 'height' : 460, - 'width' : 'auto', - 'title' : LABELS.COURSE_GROUPS_TITLE, - 'open' : function() { - // load contents after opening the dialog - $('iframe', this) - .attr('src', LAMS_URL - + 'OrganisationGroup.do?method=viewGroupings&organisationID=' - + $(this).data('orgID')); - $(this).css("maxWidth", "460px").css("margin", "auto"); - - } - }, true); -} - -function showAddSingleActivityLessonDialog(orgID, toolID, learningLibraryID) { - showDialog("dialogAddSingleActivityLesson", { - 'data' : { - 'orgID' : orgID, - 'toolID' : toolID, - 'learningLibraryID' : learningLibraryID - }, - 'modal' : true, - 'height' : 600, - 'width' : 'auto', - 'title' : LABELS.SINGLE_ACTIVITY_LESSON_TITLE, - 'open' : function() { - var dialog = $(this), - toolID = dialog.data('toolID'); - $(this).css("maxWidth", "850px").css("margin", "auto"); - $.ajax({ - async : false, - cache : false, - url : LAMS_URL + "authoring/author.do", - dataType : 'json', - data : { - 'method' : 'createToolContent', - 'toolID' : toolID - }, - success : function(response) { - dialog.data({ - 'toolContentID' : response.toolContentID, - 'contentFolderID' : response.contentFolderID - }); - - $('iframe', dialog).load(function(){ - if ($(this).contents().find('span.editForm').length > 0){ - closeAddSingleActivityLessonDialog('save'); - } - }) - .attr('src', response.authorURL + '¬ifyCloseURL=' - + encodeURIComponent(LAMS_URL - + 'dialogCloser.jsp?function=closeAddSingleActivityLessonDialog&noopener=true')); - } - }); - } - }, true); -} - - -function showNotificationsDialog(orgID, lessonID) { - var id = "dialogNotifications" + (lessonID ? "Lesson" + lessonID : "Org" + orgID); - showDialog(id, { - 'data' : { - 'orgID' : orgID, - 'lessonID' : lessonID - }, - 'height' : 650, - 'width' : 'auto', - 'title' : LABELS.EMAIL_NOTIFICATIONS_TITLE, - 'open' : function() { - var dialog = $(this), - lessonID = dialog.data('lessonID'); - // if lesson ID is given, use lesson view; otherwise use course view - if (lessonID) { - // load contents after opening the dialog - $('iframe', dialog).attr('src', LAMS_URL - + 'monitoring/emailNotifications.do?method=getLessonView&lessonID=' - + lessonID); - } else { - $('iframe', dialog).attr('src', LAMS_URL - + 'monitoring/emailNotifications.do?method=getCourseView&organisationID=' - + orgID); - } - $(this).css("maxWidth", "800px").css("margin", "auto"); - } - }, true); -} - - -function showPrivateNotificationsDialog(){ - showDialog("dialogPrivateNotifications", { - 'height' : 470, - 'width' : 600, - 'title' : LABELS.PRIVATE_NOTIFICATIONS_TITLE, - 'close' : function(){ - refreshPrivateNotificationCount(); - // completely delete the dialog - $(this).remove(); - }, - 'open' : function() { - // build the table from the scratch - var dialog = $(this), - table = $('