Index: lams_central/web/includes/javascript/authoring/authoringProperty.js =================================================================== diff -u -rcfe6f86b357387dc4d4ee125e6df9ee03676e7aa -r86805f61b68b1c56cc95458060a8693e43b7276e --- lams_central/web/includes/javascript/authoring/authoringProperty.js (.../authoringProperty.js) (revision cfe6f86b357387dc4d4ee125e6df9ee03676e7aa) +++ lams_central/web/includes/javascript/authoring/authoringProperty.js (.../authoringProperty.js) (revision 86805f61b68b1c56cc95458060a8693e43b7276e) @@ -1,1930 +1,1911 @@ -/** - * This file contains methods for Activity properties dialogs. - */ - -/** - * Stores different Activity properties structures. - */ -var PropertyDefs = { - - /** - * Properties dialog content for Branching activities. - */ - branchingProperties : function() { - var activity = this, - content = activity.propertiesContent, - fillWidgetsFunction = function(){ - // fill widgets based on data stored in Activity object - $('.propertiesContentFieldTitle', content).val(activity.branchingActivity.title); - $('.propertiesContentFieldBranchingType', content).val(activity.branchingActivity.branchingType); - // see what grouping and input Tools are available - PropertyLib.fillGroupingDropdown(activity, activity.branchingActivity.grouping); - PropertyLib.fillToolInputDropdown(activity, activity.branchingActivity.input); - - $('.propertiesContentFieldOptionalSequenceMin', content).attr('value', - activity.branchingActivity.minOptions) - .attr('max', - activity.branchingActivity.branches.length); - $('.propertiesContentFieldOptionalSequenceMax', content).attr('value', - activity.branchingActivity.maxOptions) - .attr({ - 'min' : activity.branchingActivity.minOptions, - 'max' : activity.branchingActivity.branches.length - }); - if (activity.branchingActivity.branches.length == 0) { - // no branches = no buttons to define and match groups/conditions to branches - $('.propertiesContentRowConditions', content) - .add($('.propertiesContentFieldMatchGroups', content).closest('tr')) - .hide(); - } - }; - - if (!content) { - // first run, create the content - content = activity.propertiesContent = $('#propertiesContentBranching').clone().attr('id', null) - .show().data('parentObject', activity); - // extra buttons for group/input based branching - $('.propertiesContentFieldMatchGroups', content).button().click(function(){ - PropertyLib.openGroupsToBranchesMappingDialog(activity.branchingActivity); - }); - $('.propertiesContentFieldCreateConditions', content).button().click(function(){ - PropertyLib.openOutputConditionsDialog(activity.branchingActivity); - }); - $('.propertiesContentFieldMatchConditions', content).button().click(function(){ - PropertyLib.openConditionsToBranchesMappingDialog(activity.branchingActivity); - }); - - // if the user changed something in the dialog, save the state - // make onChange function a local variable, because it's used several times - var changeFunction = function(){ - // extract changed properties and redraw the activity - var content = $(this).closest('.dialogContents'), - activity = content.data('parentObject'), - branchingActivity = activity.branchingActivity, - redrawNeeded = false, - newTitle = $('.propertiesContentFieldTitle', content).val(); - if (newTitle == '') { - newTitle = undefined; - } - // validate and save the title - if (newTitle != branchingActivity.title) { - if (GeneralLib.validateName(newTitle)) { - branchingActivity.title = newTitle; - redrawNeeded = true; - } else { - layout.infoDialog.data('show')(LABELS.TITLE_VALIDATION_ERROR); - $('.propertiesContentFieldTitle', content).val(branchingActivity.title); - } - } - branchingActivity.branchingType = $('.propertiesContentFieldBranchingType', content).val(); - - // show/hide group match button - var groupingRow = $('.propertiesContentFieldGrouping', content).closest('tr'); - if (branchingActivity.branchingType == 'group') { - branchingActivity.grouping = groupingRow.show() - .find('option:selected').data('grouping'); - } else { - branchingActivity.grouping = null; - groupingRow.hide(); - } - $('.propertiesContentFieldMatchGroups', content).closest('tr') - .css('display', branchingActivity.branchingType == 'group' && branchingActivity.grouping - && branchingActivity.branches.length > 0 ? '' : 'none'); - - // show/hide conditions define/match buttons - var inputRow = $('.propertiesContentFieldInput', content).closest('tr'), - inputDefinitionRows = $('.propertiesContentRowConditions', content); - if (branchingActivity.branchingType == 'tool') { - branchingActivity.input = inputRow.show() - .find('option:selected').data('input'); - // no branches = no buttons - if (branchingActivity.input && branchingActivity.branches.length > 0) { - inputDefinitionRows.show(); - } else { - inputDefinitionRows.hide(); - } - } else { - inputRow.hide(); - inputDefinitionRows.hide(); - } - - var optionalSequenceRows = $('.spinner', content).closest('tr'); - if (branchingActivity.branchingType == 'optional') { - optionalSequenceRows.show(); - } else { - optionalSequenceRows.hide(); - } - - // if title changed, redraw branching and converge points - if (redrawNeeded) { - ActivityLib.removeSelectEffect(layout.selectedObject); - branchingActivity.start.draw(); - branchingActivity.end.draw(); - ActivityLib.addSelectEffect(layout.selectedObject, true); - } - - GeneralLib.setModified(true); - } - - // min can not be higher than max; neither of them can be higher than number of branches - $('.propertiesContentFieldOptionalSequenceMin', content).attr('min', 0) - .on('input', function(){ - var value = +$(this).val(); - activity.branchingActivity.minOptions = Math.min(value, activity.branchingActivity.branches.length); - if (value != activity.branchingActivity.minOptions) { - $(this, content).attr('value', activity.branchingActivity.minOptions); - } - if (activity.branchingActivity.minOptions > activity.branchingActivity.maxOptions) { - $('.propertiesContentFieldOptionalSequenceMax', content).attr('value', value); - } - $('.propertiesContentFieldOptionalSequenceMax', content).attr('min', value); - }); - - - $('.propertiesContentFieldOptionalSequenceMax', content).attr('min', 0) - .on('input', function(){ - var value = +$(this).val(); - activity.branchingActivity.maxOptions = Math.min(value, activity.branchingActivity.branches.length); - if (value != activity.branchingActivity.maxOptions) { - $(this, content).attr('value', activity.branchingActivity.maxOptions); - } - }); - - // set up the handler and run functions for the first time - $('input, select', content).change(changeFunction); - fillWidgetsFunction(); - changeFunction.call(content); - } - - - fillWidgetsFunction(); - }, - - - /** - * Properties dialog content for Gates. - */ - gateProperties : function() { - var activity = this, - content = activity.propertiesContent; - if (!content) { - // first run, create the content - content = activity.propertiesContent = $('#propertiesContentGate').clone().attr('id', null) - .show().data('parentObject', activity); - $('.propertiesContentFieldTitle', content).val(activity.title); - if (activity.gateType == 'system') { - // remove everything except for the title - $('.propertiesContentFieldTitle', content).closest('tr').siblings().remove(); - return; - } - - $('.propertiesContentFieldDescription', content).val(activity.description ? activity.description : ''); - $('.propertiesContentFieldGateType', content).val(activity.gateType); - - $('.propertiesContentFieldCreateConditions', content).button().click(function(){ - PropertyLib.openOutputConditionsDialog(activity); - }); - $('.propertiesContentFieldMatchConditions', content).button().click(function(){ - PropertyLib.openConditionsToBranchesMappingDialog(activity); - }); - - // make onChange function a local variable, because it's used several times - var changeFunction = function(){ - // extract changed properties and redraw the activity - var content = $(this).closest('.dialogContents'), - activity = content.data('parentObject'), - redrawNeeded = false, - newTitle = $('.propertiesContentFieldTitle', content).val(); - if (newTitle == '') { - newTitle = undefined; - } - // validate and save the title - if (newTitle != activity.title) { - if (GeneralLib.validateName(newTitle)) { - activity.title = newTitle; - redrawNeeded = true; - } else { - layout.infoDialog.data('show')(LABELS.TITLE_VALIDATION_ERROR); - $('.propertiesContentFieldTitle', content).val(activity.title); - } - } - - // only Gate activity has description - activity.description = $('.propertiesContentFieldDescription', content).val(); - - activity.gateType = $('.propertiesContentFieldGateType', content).val(); - if (activity.gateType == 'schedule') { - // show inputs for setting delay before the gate is closed - $(".propertiesContentRowGateSchedule").show(); - activity.offsetDay = +$('.propertiesContentFieldOffsetDay', content).val(); - activity.offsetHour = +$('.propertiesContentFieldOffsetHour', content).val(); - activity.offsetMinute = +$('.propertiesContentFieldOffsetMinute', content).val(); - activity.gateActivityCompletionBased = $('.propertiesContentFieldActivityCompletionBased').is(':checked'); - } else { - $(".propertiesContentRowGateSchedule").hide(); - } - - // Gate can be input-based - var inputRow = $('.propertiesContentFieldInput', content).closest('tr'), - inputDefinitionRows = $('.propertiesContentRowConditions', content); - if (activity.gateType == 'condition') { - activity.input = inputRow.show().find('option:selected').data('input'); - if (activity.input) { - inputDefinitionRows.show(); - } else { - inputDefinitionRows.hide(); - } - } else { - inputRow.hide(); - inputDefinitionRows.hide(); - } - - if (redrawNeeded) { - ActivityLib.removeSelectEffect(activity); - activity.draw(); - ActivityLib.addSelectEffect(activity, true); - } - - GeneralLib.setModified(true); - }; - - // create groups/learners spinners - $('.propertiesContentFieldOffsetDay', content).attr({ - 'min' : 0, - 'max' : 364 - }).attr('value', activity.offsetDay || 0) - .on('input', changeFunction); - - $('.propertiesContentFieldOffsetHour', content).attr({ - 'min' : 0, - 'max' : 23 - }).attr('value', activity.offsetHour || 0) - .on('input', changeFunction); - - $('.propertiesContentFieldOffsetMinute', content).attr({ - 'min' : 0, - 'max' : 59 - }).attr('value', activity.offsetMinute || 0) - .on('input', changeFunction); - - $('.propertiesContentFieldActivityCompletionBased', content) - .attr('checked', activity.gateActivityCompletionBased? 'checked' : null); - - $('input, textarea, select', content).change(changeFunction); - PropertyLib.fillToolInputDropdown(activity, activity.input); - changeFunction.call(content); - } - - if (activity.transitions.to.length == 0){ - $('.propertiesContentFieldActivityCompletionBased', content) - .attr('checked', null) - .prop('checked', false) - .attr('disabled', 'disabled'); - - } else { - $('.propertiesContentFieldActivityCompletionBased', content) - .attr('disabled', null); - } - - PropertyLib.fillToolInputDropdown(activity, activity.input); - }, - - - /** - * Properties dialog content for Grouping activities. - */ - groupingProperties : function() { - var activity = this, - content = activity.propertiesContent; - - if (!content) { - // make onChange function a local variable, because it's used several times - var changeFunction = function(){ - // extract changed properties and redraw the activity, if needed - var content = $(this).closest('.dialogContents'), - activity = content.data('parentObject'), - redrawNeeded = false, - newTitle = $('.propertiesContentFieldTitle', content).val(), - newGroupCount = +$('.propertiesContentFieldGroupCount', content).val(); - if (newTitle == '') { - newTitle = undefined; - } - // validate and save the title - if (newTitle != activity.title) { - if (GeneralLib.validateName(newTitle)) { - activity.title = newTitle; - redrawNeeded = true; - } else { - layout.infoDialog.data('show')(LABELS.TITLE_VALIDATION_ERROR); - $('.propertiesContentFieldTitle', content).val(activity.title); - } - } - - activity.groupingType = $('.propertiesContentFieldGroupingType', content).val(); - - $('input[name="propertiesContentFieldGroupDivide"]', content).each(function(){ - // enable/disable division types, depending on radio buttons next to them - $(this).next().find('.spinner').prop('disabled', !$(this).is(':checked')); - }) - // hide group/learner division with some grouping types - .add($('.propertiesContentFieldLearnerCount', content).closest('tr')) - .css('display', activity.groupingType == 'monitor' ? 'none' : ''); - - // show "equal group sizes" only for Learner's Choice type and Number of Groups selected - $('.propertiesContentFieldEqualSizes', content) - .closest('tr').css('display', activity.groupingType == 'learner' - && $('.propertiesContentFieldGroupCountEnable', content).is(':checked') ? '' : 'none'); - - // show "view learners before selection" only for Learner's Choice type - $('.propertiesContentFieldViewLearners', content) - .closest('tr').css('display', activity.groupingType == 'learner' ? '' : 'none'); - - - activity.groupDivide = activity.groupingType == 'monitor' - || $('.propertiesContentFieldGroupCountEnable', content).is(':checked') - ? 'groups' : 'learners'; - $('.propertiesContentFieldNameGroups', content).css('display', activity.groupDivide == 'groups' ? '' : 'none'); - - if (activity.groupCount != newGroupCount){ - activity.groupCount = newGroupCount; - activity.groups = PropertyLib.fillNameAndUIIDList(activity.groupCount, activity.groups, 'name', - LABELS.DEFAULT_GROUP_PREFIX); - } - activity.learnerCount = +$('.propertiesContentFieldLearnerCount', content).val(); - activity.equalSizes = $('.propertiesContentFieldEqualSizes', content).is(':checked'); - activity.viewLearners = $('.propertiesContentFieldViewLearners', content).is(':checked'); - - if (redrawNeeded) { - ActivityLib.removeSelectEffect(activity); - activity.draw(); - ActivityLib.addSelectEffect(activity, true); - } - - GeneralLib.setModified(true); - }; - - // first run, create the content - content = activity.propertiesContent = $('#propertiesContentGrouping').clone().attr('id', null) - .show().data('parentObject', activity); - - // init widgets - $('.propertiesContentFieldTitle', content).val(activity.title); - $('.propertiesContentFieldGroupingType', content).val(activity.groupingType); - if (activity.groupDivide == 'learners') { - $('.propertiesContentFieldLearnerCountEnable', content).attr('checked', 'checked'); - } else { - $('.propertiesContentFieldGroupCountEnable', content).attr('checked', 'checked'); - } - - // create groups/learners spinners - $('.propertiesContentFieldGroupCount', content).attr({ - 'min' : 2 - }).attr('value', activity.groupCount) - .on('input', changeFunction); - - $('.propertiesContentFieldLearnerCount', content).attr({ - 'min' : 1 - }).attr('value', activity.learnerCount) - .on('input', changeFunction); - - $('.propertiesContentFieldEqualSizes', content).attr('checked', activity.equalSizes ? 'checked' : null); - $('.propertiesContentFieldViewLearners', content).attr('checked', activity.viewLearners ? 'checked' : null); - $('.propertiesContentFieldNameGroups', content).click(function(){ - PropertyLib.openGroupNamingDialog(activity); - }); - - $('input, select', content).change(changeFunction); - changeFunction.call(content); - } - }, - - - /** - * Properties dialog content for labels (annotations). - */ - labelProperties : function() { - var label = this, - content = label.propertiesContent; - if (!content) { - // first run, create the content - content = label.propertiesContent = $('#propertiesContentLabel').clone().attr('id', null) - .show().data('parentObject', label); - $('.propertiesContentFieldTitle', content).val(label.title); - var color = label.items.shape.attr('fill'); - // init colour chooser - $('.propertiesContentFieldColor', content).val(color) - .simpleColor({ - 'colors' : layout.colors.annotationPalette, - 'chooserCSS' : { - 'left' : 2, - 'top' : '25px', - 'margin' : '0' - } - }); - - var changeFunction = function(){ - // extract changed properties and redraw the label, if needed - var content = $(this).closest('.dialogContents'), - label = content.data('parentObject'), - redrawNeeded = false, - newTitle = $('.propertiesContentFieldTitle', content).val(), - color = label.items.shape.attr('fill'), - newColor = $('.propertiesContentFieldColor', content).val(), - size = label.items.shape.attr('font-size'); - size = +size.substring(0, size.indexOf('px')); - - if (newTitle == '') { - newTitle = undefined; - } - // validate and save the title - if (newTitle != label.title) { - if (GeneralLib.validateName(newTitle)) { - label.title = newTitle; - redrawNeeded = true; - } else { - layout.infoDialog.data('show')(LABELS.TITLE_VALIDATION_ERROR); - $('.propertiesContentFieldTitle', content).val(label.title); - } - } - - redrawNeeded |= newColor != color; - redrawNeeded |= label.newSize && (label.newSize <= layout.conf.labelMaxSize - || label.newSize >= layout.conf.labelMinSize); - - if (redrawNeeded) { - ActivityLib.removeSelectEffect(label); - label.draw(null, null, newColor, label.newSize); - ActivityLib.addSelectEffect(label, true); - GeneralLib.setModified(true); - } - - label.newSize = null; - }; - - $('input', content).change(changeFunction); - - $('.labelPlusSize, .labelMinusSize', content).click(function(){ - label.newSize = label.items.shape.attr('font-size'); - label.newSize = +label.newSize.substring(0, label.newSize.indexOf('px')) - + ($(this).hasClass('labelPlusSize') ? 1 : -1); - changeFunction.call(content); - }); - } - }, - - - /** - * Properties dialog content for Optional Activity. - */ - optionalActivityProperties : function() { - var activity = this, - content = activity.propertiesContent; - - activity.minOptions = Math.min(activity.minOptions, activity.childActivities.length); - activity.maxOptions = Math.min(activity.maxOptions, activity.childActivities.length); - - if (!content) { - // first run, create the content - content = activity.propertiesContent = $('#propertiesContentOptionalActivity').clone().attr('id', null) - .show().data('parentObject', activity); - $('.propertiesContentFieldTitle', content).val(activity.title); - - $('input', content).change(function(){ - // extract changed properties and redraw the activity, if needed - var content = $(this).closest('.dialogContents'), - activity = content.data('parentObject'), - newTitle = $('.propertiesContentFieldTitle', content).val(); - if (newTitle == '') { - newTitle = undefined; - } - // validate and save the title - if (newTitle != activity.title) { - if (GeneralLib.validateName(newTitle)) { - activity.title = newTitle; - ActivityLib.removeSelectEffect(activity); - activity.draw(); - ActivityLib.addSelectEffect(activity, true); - GeneralLib.setModified(true); - } else { - layout.infoDialog.data('show')(LABELS.TITLE_VALIDATION_ERROR); - $('.propertiesContentFieldTitle', content).val(activity.title); - } - } - }); - - // min can not be higher than max; neither of them can be higher than children count - $('.propertiesContentFieldOptionalActivityMin', content).attr({'min' : 0}) - .on('input', function(){ - var value = +$(this).val(); - activity.minOptions = Math.min(value, activity.childActivities.length); - if (value != activity.minOptions) { - $(this, content).attr('value', activity.minOptions); - } - if (activity.minOptions > activity.maxOptions) { - $('.propertiesContentFieldOptionalActivityMax', content).attr('value', value); - } - $('.propertiesContentFieldOptionalActivityMax', content).attr('min', value); - }); - - - $('.propertiesContentFieldOptionalActivityMax', content).attr('min', 0) - .on('input', function(){ - var value = +$(this).val(); - activity.maxOptions = Math.min(value, activity.childActivities.length); - if (value != activity.maxOptions) { - $(this, content).attr('value', activity.maxOptions); - } - }); - } - - $('.propertiesContentFieldOptionalActivityMin', content).attr('value', activity.minOptions) - .attr('max', activity.childActivities.length); - $('.propertiesContentFieldOptionalActivityMax', content).attr('value', activity.maxOptions) - .attr({ - 'min' : activity.minOptions, - 'max' : activity.childActivities.length - }); - }, - - - /** - * Properties dialog content for Parallel activities. - */ - parallelProperties : function() { - var activity = this, - content = activity.propertiesContent; - - if (!content) { - // first run, create the content - content = activity.propertiesContent = $('#propertiesContentParallel').clone().attr('id', null) - .show().data('parentObject', activity); - $('.propertiesContentFieldTitle', content).val(activity.title); - - $('input, select', content).change(function(){ - // extract changed properties and redraw the activity - var content = $(this).closest('.dialogContents'), - activity = content.data('parentObject'), - redrawNeeded = false, - newTitle = $('.propertiesContentFieldTitle', content).val(); - if (newTitle == '') { - newTitle = undefined; - } - // validate and save the title - if (newTitle != activity.title) { - if (GeneralLib.validateName(newTitle)) { - activity.title = newTitle; - redrawNeeded = true; - } else { - layout.infoDialog.data('show')(LABELS.TITLE_VALIDATION_ERROR); - $('.propertiesContentFieldTitle', content).val(activity.title); - } - } - var newGroupingValue = $('.propertiesContentFieldGrouping option:selected', content) - .data('grouping'); - if (newGroupingValue != activity.grouping) { - activity.grouping = newGroupingValue; - $.each(activity.childActivities, function(){ - this.grouping = newGroupingValue; - }); - redrawNeeded = true; - } - - if (redrawNeeded) { - ActivityLib.removeSelectEffect(activity); - activity.draw(); - ActivityLib.addSelectEffect(activity, true); - GeneralLib.setModified(true); - } - }); - } - - PropertyLib.fillGroupingDropdown(activity, activity.grouping); - }, - - - /** - * Properties dialog content for regions (annotations). - */ - regionProperties : function() { - var region = this, - content = region.propertiesContent; - if (!content) { - // first run, create the content - content = region.propertiesContent = $('#propertiesContentRegion').clone().attr('id', null) - .show().data('parentObject', region); - - $('.propertiesContentFieldTitle', content).val(region.title); - var color = region.items.shape.attr('fill'); - // init colour chooser - $('.propertiesContentFieldColor', content).val(color) - .simpleColor({ - 'colors' : layout.colors.annotationPalette, - 'chooserCSS' : { - 'left' : 2, - 'top' : '25px', - 'margin' : '0' - } - }); - - $('input', content).change(function(){ - // extract changed properties and redraw the transition - var content = $(this).closest('.dialogContents'), - region = content.data('parentObject'), - redrawNeeded = false, - newTitle = $('.propertiesContentFieldTitle', content).val(), - color = region.items.shape.attr('fill'), - newColor = $('.propertiesContentFieldColor', content).val(); - if (newTitle == '') { - newTitle = undefined; - } - // validate and save the title - if (newTitle != region.title) { - if (GeneralLib.validateName(newTitle)) { - region.title = newTitle; - redrawNeeded = true; - } else { - layout.infoDialog.data('show')(LABELS.TITLE_VALIDATION_ERROR); - $('.propertiesContentFieldTitle', content).val(region.title); - } - } - redrawNeeded |= newColor != color; - - if (redrawNeeded) { - ActivityLib.removeSelectEffect(region); - region.draw(null, null, null, null, newColor); - ActivityLib.addSelectEffect(region, true); - GeneralLib.setModified(true); - } - }); - } - }, - - - /** - * Properties dialog content for Tool activities. - */ - toolProperties : function() { - var activity = this, - content = activity.propertiesContent; - - if (!content) { - // first run, create the content - content = activity.propertiesContent = $('#propertiesContentTool').clone().attr('id', null) - .show().data('parentObject', activity); - $('.propertiesContentFieldTitle', content).val(activity.title); - if (activity.parentActivity && (activity.parentActivity instanceof ActivityDefs.ParallelActivity)) { - // parts of Parallel Activity are grouped as the parent activity - $('.propertiesContentFieldGrouping', content).attr('disabled', 'disabled'); - } - - if (activity.outputDefinitions) { - PropertyLib.fillOutputDefinitionsDropdown(activity); - } - - $('input, select', content).change(function(){ - // extract changed properties and redraw the activity - var content = $(this).closest('.dialogContents'), - activity = content.data('parentObject'), - redrawNeeded = false, - newTitle = $('.propertiesContentFieldTitle', content).val(); - if (newTitle == '') { - newTitle = undefined; - } - // validate and save the title - if (newTitle != activity.title) { - if (GeneralLib.validateName(newTitle)) { - activity.title = newTitle; - redrawNeeded = true; - } else { - layout.infoDialog.data('show')(LABELS.TITLE_VALIDATION_ERROR); - $('.propertiesContentFieldTitle', content).val(activity.title); - } - } - - var selectedGrouping = $('.propertiesContentFieldGrouping option:selected', content); - if (selectedGrouping.length > 0){ - var newGroupingValue = selectedGrouping.data('grouping'); - if (newGroupingValue != activity.grouping) { - activity.grouping = newGroupingValue; - redrawNeeded = true; - if (activity.requireGrouping && newGroupingValue != null) { - // get rid of red border set by TBL check - activity.requireGrouping = false; - } - } - } - - var selectedGradebookToolOutputDefinition = $('.propertiesContentFieldGradebook option:selected', content); - if (selectedGradebookToolOutputDefinition.length > 0){ - activity.gradebookToolOutputDefinitionName = selectedGradebookToolOutputDefinition.val(); - if (activity.gradebookToolOutputDefinitionName) { - $.each(activity.outputDefinitions, function(){ - if (this.name == activity.gradebookToolOutputDefinitionName) { - activity.gradebookToolOutputDefinitionDescription = this.description; - activity.gradebookToolOutputDefinitionWeightable = this.weightable; - return false; - } - }); - } else { - activity.gradebookToolOutputDefinitionDescription = null; - activity.gradebookToolOutputDefinitionWeightable = false; - activity.gradebookToolOutputDefinitionWeight = null; - } - } - - if (redrawNeeded) { - ActivityLib.removeSelectEffect(activity); - activity.draw(); - ActivityLib.addSelectEffect(activity, true); - GeneralLib.setModified(true); - } - }); - } - - PropertyLib.fillGroupingDropdown(activity, activity.grouping); - }, - - - /** - * Properties dialog content for transitions. - */ - transitionProperties : function() { - var transition = this, - content = transition.propertiesContent; - if (!content) { - // first run, create the content - content = transition.propertiesContent = $('#propertiesContentTransition').clone().attr('id', null) - .show().data('parentObject', transition); - $('.propertiesContentFieldTitle', content).val(transition.title); - - var defaultBranch = $('.propertiesContentFieldDefault', content); - if (transition.branch) { - defaultBranch.show(); - } else { - defaultBranch.hide(); - } - - $('input', content).change(function(){ - // extract changed properties and redraw the transition - var content = $(this).closest('.dialogContents'), - transition = content.data('parentObject'), - redrawNeeded = false, - newTitle = $('.propertiesContentFieldTitle', content).val(); - - // validate and save the title - if (newTitle != transition.title) { - if (GeneralLib.validateName(newTitle)) { - transition.title = newTitle; - if (transition.branch) { - transition.branch.title = newTitle; - } - redrawNeeded = true; - } else { - layout.infoDialog.data('show')(LABELS.TITLE_VALIDATION_ERROR); - $('.propertiesContentFieldTitle', content).val(transition.title); - } - } - - if (transition.branch) { - transition.branch.defaultBranch = $('.propertiesContentFieldDefault', content).is(':checked'); - if (transition.branch.defaultBranch) { - // reset default branch marker in other branches, there can be only one - $.each(transition.branch.branchingActivity.branches, function(){ - if (this != transition.branch) { - this.defaultBranch = false; - } - }); - } - } - - if (redrawNeeded) { - ActivityLib.removeSelectEffect(activity); - transition.draw(); - ActivityLib.addSelectEffect(activity, true); - GeneralLib.setModified(true); - } - }); - } - - $('.propertiesContentFieldDefault', content).attr('checked', - transition.branch && transition.branch.defaultBranch ? 'checked' : null); - } -}, - - - -/** - * Contains Properties dialog manipulation methods. - */ -PropertyLib = { - - init : function(){ - // initialise the properties dialog singleton - var propertiesDialog = layout.propertiesDialog = showDialog('propertiesDialog',{ - 'autoOpen' : false, - 'title' : LABELS.PROPERTIES_DIALOG_TITLE, - 'width' : 370, - 'close' : null, - 'data' : { - 'position' : false - } - }, false); - $('.modal-body', propertiesDialog).empty(); - // for proximity detection throttling (see handlers) - propertiesDialog.data('lastRun', 0); - // remove close button, add dimming - propertiesDialog.addClass('propertiesDialogContainer smallHeader') - .css('opacity', layout.conf.propertiesDialogDimOpacity) - .mousemove(HandlerPropertyLib.approachPropertiesDialogHandler) - .find('.modal-header button').remove(); - layout.dialogs.push(propertiesDialog); - - var groupNamingContent = $('#propertiesContentGroupNaming'); - $('#groupNamingOKButton', groupNamingContent).click(function() { - var dialog = layout.groupNamingDialog, - activity = groupNamingContent.data('parentObject'), - names = [], - error = null; - - // extract group names from text fields and validate them - $('input', groupNamingContent).each(function(){ - var groupName = $(this).val().trim(); - if (GeneralLib.validateName(groupName)) { - names.push(groupName); - } else { - error = LABELS.GROUP_TITLE_VALIDATION_ERORR; - return false; - } - }); - - if (error) { - layout.infoDialog.data('show')(error); - return; - } - - $('input', groupNamingContent).each(function(index){ - activity.groups[index].name = names[index]; - }); - - dialog.modal('hide'); - }); - $('#groupNamingCancelButton', groupNamingContent).click(function() { - layout.groupNamingDialog.modal('hide'); - }); - // initialise dialog from group naming - layout.groupNamingDialog = showDialog('groupNamingDialog',{ - 'autoOpen' : false, - 'modal' : true, - 'draggable' : true, - 'width' : 400, - 'title' : LABELS.GROUP_NAMING_DIALOG_TITLE, - 'close' : null - }, false) - .addClass('smallHeader'); - - - $('.modal-body', layout.groupNamingDialog).empty().append(groupNamingContent.show()); - $('.modal-header button', layout.groupNamingDialog).remove(); - // add to dialogs array so they can be easily closed at once - layout.dialogs.push(layout.groupNamingDialog); - - - var branchMappingDialogContents = $('#branchMappingDialogContents').clone().attr('id', null); - $('.branchMappingOKButton', branchMappingDialogContents).click(function(){ - var dialog = layout.groupsToBranchesMappingDialog, - branchingActivity = dialog.data('branchingActivity'), - groupsToBranches = [], - assignedToDefault = false, - defaultBranch = null, - close = true; - - // find references to groups and branches - $('.branchMappingBoundItemCell div, .branchMappingFreeItemCell div', dialog).each(function(){ - var groupUIID = +$(this).attr('uiid'), - boundItem = $(this).data('boundItem'), - branchUIID = boundItem ? +boundItem.attr('uiid') : null, - group = null, - branch = null; - - // look for branch - if (branchUIID) { - $.each(branchingActivity.branches, function(){ - if (branchUIID == this.uiid) { - branch = this; - return false; - } - }); - } else { - // assign to default branch - if (!defaultBranch) { - $.each(branchingActivity.branches, function(){ - if (this.defaultBranch) { - defaultBranch = this; - return false; - } - }); - // fall back to first branch - if (!defaultBranch) { - defaultBranch = branchingActivity.branches[0]; - defaultBranch.defaultBranch = true; - } - } - branch = defaultBranch; - assignedToDefault = true; - } - - // look for group - $.each(branchingActivity.grouping.groups, function(){ - if (groupUIID == this.uiid) { - group = this; - return false; - } - }); - - // add the mapping - groupsToBranches.push({ - 'uiid' : ++layout.ld.maxUIID, - 'group' : group, - 'branch' : branch - }); - }); - - if (assignedToDefault){ - // ask the user if it's OK to assign groups to default branch - close = confirm(LABELS.GROUPS_TO_DEFAULT_BRANCH_CONFIRM); - } - - if (close) { - branchingActivity.groupsToBranches = groupsToBranches; - dialog.modal('hide'); - GeneralLib.setModified(true); - } - }); - - // initialise the dialog buttons - $('.branchMappingAddButton', branchMappingDialogContents).click(function(){ - PropertyLib.addBranchMapping(layout.groupsToBranchesMappingDialog); - }); - $('.branchMappingRemoveButton', branchMappingDialogContents).click(function(){ - PropertyLib.removeBranchMapping(layout.groupsToBranchesMappingDialog); - }); - $('.branchMappingFreeItemHeaderCell', branchMappingDialogContents).text(LABELS.BRANCH_MAPPING_CONDITIONS_HEADER); - $('.branchMappingBoundItemHeaderCell', branchMappingDialogContents).text(LABELS.BRANCH_MAPPING_CONDITION_HEADER); - - // initialise dialog for matching groups to branches in branching activities - layout.groupsToBranchesMappingDialog = showDialog('gtbDialog',{ - 'autoOpen' : false, - 'modal' : true, - 'width' : 800, - 'title' : LABELS.GROUPS_TO_BRANCHES_MATCH_DIALOG_TITLE, - 'close' : null - }, false) - .addClass('smallHeader'); - - $('.modal-body', layout.groupsToBranchesMappingDialog).empty().append(branchMappingDialogContents.show()); - layout.dialogs.push(layout.groupsToBranchesMappingDialog); - - var outputConditionsDialogContents = $('#outputConditionsDialogContents'); - $('#outputConditionsClearAllButton', outputConditionsDialogContents).click(function(){ - // remove all range conditions - var rows = $('#rangeConditions td', layout.outputConditionsDialog).closest('tr'); - rows.each(function(){ - // check for conditions already linked to branches/gate states - if ($(this).data('mappingEntry').branch) { - if (!confirm(LABELS.CLEAR_ALL_CONFIRM)) { - rows = null; - } - return false; - } - }); - - if (rows) { - rows.remove(); - } - }); - - $('#outputConditionsRemoveButton', outputConditionsDialogContents).click(function(){ - // remove the selected range condition - var selected = $('#rangeConditions tr.selected', layout.outputConditionsDialog); - if (!selected.data('mappingEntry').branch - || confirm(LABELS.REMOVE_CONDITION_CONFIRM)) { - selected.remove(); - } - }); - - $('#outputConditionsCancelButton', outputConditionsDialogContents).click(function(){ - layout.outputConditionsDialog.modal('hide'); - }); - - $('#outputConditionsOKButton', outputConditionsDialogContents).click(function(){ - var dialog = layout.outputConditionsDialog, - activity = dialog.data('parentObject'); - - // extract created mappings from UI - activity.conditionsToBranches = []; - $('#rangeConditions tr, #complexConditions li', dialog).each(function(){ - // if it's hidden, then another output was selected, so skip it - var mappingEntry = $(this).is(':visible') ? $(this).data('mappingEntry') : null; - if (!mappingEntry) { - return true; - } - - // new UIID for new conditions - if (!mappingEntry.uiid) { - mappingEntry.uiid = ++layout.ld.maxUIID; - } - if (!mappingEntry.condition.conditionUIID) { - mappingEntry.condition.conditionUIID = ++layout.ld.maxUIID; - } - - // range conditions can have their names changed - var input = $('input', this); - if (input.length > 0) { - mappingEntry.condition.displayName = input.val(); - } - activity.conditionsToBranches.push(mappingEntry); - }); - - dialog.modal('hide'); - // go straight to mapping dialog - PropertyLib.openConditionsToBranchesMappingDialog(activity); - }); - - // initialise dialog for defining input conditions - layout.outputConditionsDialog = showDialog('outputConditionsDialog',{ - 'autoOpen' : false, - 'modal' : true, - 'width' : 400, - 'height' : 400, - 'title' : LABELS.CONDITIONS_DIALOG_TITLE, - 'open' : function(){ - $(this).data('buildContent')(); - }, - 'close' : null, - 'data' : { - /** - * Link output data to UI widgets - */ - 'buildContent' : function() { - var dialog = layout.outputConditionsDialog, - activity = dialog.data('parentObject'), - outputSelect = $('#outputSelect', dialog), - emptyOption = $('option[value="none"]', outputSelect).attr('selected', 'selected'), - // conditions can have names like "output.name#6", but real output names do not have a suffix - outputName = activity.conditionsToBranches && activity.conditionsToBranches.length > 0 - ? activity.conditionsToBranches[0].condition.name.split('#')[0] : null; - // remove all previously defined outputs - $('option[value!="none"]', outputSelect).remove(); - - if (activity.input.outputDefinitions) { - // build output dropdown and bind data to each option - $.each(activity.input.outputDefinitions,function(){ - var suffix = ''; - switch(this.type) { - case 'OUTPUT_COMPLEX' : - suffix = LABELS.COMPLEX_OUTPUT_SUFFIX; - break; - - case 'OUTPUT_LONG' : - suffix = LABELS.RANGE_OUTPUT_SUFFIX; - break; - - case 'OUTPUT_BOOLEAN' : - suffix = LABELS.BOOLEAN_OUTPUT_SUFFIX; - break; - }; - - this.toolActivityUIID = activity.input.uiid; - var option = $('