diff --git a/ajax.php b/ajax.php index e89b563..352fc90 100644 --- a/ajax.php +++ b/ajax.php @@ -67,22 +67,6 @@ $enrol = enrol_get_plugin('ilios'); switch ($action) { - case 'getassignable': - $otheruserroles = optional_param('otherusers', false, PARAM_BOOL); - $outcome->response = array_reverse($manager->get_assignable_roles($otheruserroles), true); - break; - case 'getdefaultiliosrole': //TODO: use in ajax UI MDL-24280 - $iliosenrol = enrol_get_plugin('ilios'); - $outcome->response = $iliosenrol->get_config('roleid'); - break; - case 'getcohorts': - require_capability('moodle/course:enrolconfig', $context); - $offset = optional_param('offset', 0, PARAM_INT); - $search = optional_param('search', '', PARAM_RAW); - $outcome->response = enrol_ilios_search_cohorts($manager, $offset, 25, $search); - // Some browsers reorder collections by key. - $outcome->response['cohorts'] = array_values($outcome->response['cohorts']); - break; case 'getselectschooloptions': require_capability('moodle/course:enrolconfig', $context); $http = $enrol->get_http_client(); @@ -93,6 +77,7 @@ } $outcome->response = $schoolarray; break; + case 'getselectprogramoptions': require_capability('moodle/course:enrolconfig', $context); $sid = required_param('filterid', PARAM_INT); // school id @@ -105,6 +90,7 @@ } $outcome->response = $programarray; break; + case 'getselectcohortoptions': require_capability('moodle/course:enrolconfig', $context); $pid = required_param('filterid', PARAM_INT); @@ -203,44 +189,6 @@ $outcome->response = $instructorgroupoptions; break; - case 'enrolilios': - require_capability('moodle/course:enrolconfig', $context); - require_capability('enrol/ilios:config', $context); - $roleid = required_param('roleid', PARAM_INT); - $cohortid = required_param('cohortid', PARAM_INT); - - $roles = $manager->get_assignable_roles(); - if (!enrol_ilios_can_view_cohort($cohortid) || !array_key_exists($roleid, $roles)) { - throw new enrol_ajax_exception('errorenrolilios'); - } - $enrol = enrol_get_plugin('ilios'); - $enrol->add_instance($manager->get_course(), array('customint1' => $cohortid, 'roleid' => $roleid)); - $trace = new null_progress_trace(); - enrol_ilios_sync($trace, $manager->get_course()->id); - $trace->finished(); - break; - case 'enroliliosusers': - //TODO: this should be moved to enrol_manual, see MDL-35618. - require_capability('enrol/manual:enrol', $context); - $roleid = required_param('roleid', PARAM_INT); - $cohortid = required_param('cohortid', PARAM_INT); - - $roles = $manager->get_assignable_roles(); - if (!enrol_ilios_can_view_cohort($cohortid) || !array_key_exists($roleid, $roles)) { - throw new enrol_ajax_exception('errorenrolilios'); - } - - $result = enrol_ilios_enrol_all_users($manager, $cohortid, $roleid); - if ($result === false) { - throw new enrol_ajax_exception('errorenroliliosusers'); - } - - $outcome->success = true; - $outcome->response->users = $result; - $outcome->response->title = get_string('success'); - $outcome->response->message = get_string('enrollednewusers', 'enrol', $result); - $outcome->response->yesLabel = get_string('ok'); - break; default: throw new enrol_ajax_exception('unknowajaxaction'); } diff --git a/edit_form.php b/edit_form.php index 5aedcff..6559c4b 100644 --- a/edit_form.php +++ b/edit_form.php @@ -53,8 +53,7 @@ function definition() { $mform->addElement('select', 'status', get_string('status', 'enrol_ilios'), $options); - // TODO: Move this into 'if ($instance->id)'. - $usertypes = array('Learner', 'Instructor'); + $usertypes = array(get_string('learner', 'enrol_ilios'), get_string('instructor', 'enrol_ilios')); $schooloptions = array('' => get_string('choosedots')); $programoptions = array('' => get_string('choosedots')); $cohortoptions = array('' => get_string('choosedots')); diff --git a/lang/en/enrol_ilios.php b/lang/en/enrol_ilios.php index 0e0f637..27ec374 100644 --- a/lang/en/enrol_ilios.php +++ b/lang/en/enrol_ilios.php @@ -34,10 +34,6 @@ $string['defaultlearnerrole'] = 'Default learner role'; $string['defaultinstructorrole'] = 'Default instructor role'; $string['enrol'] = 'Enrol Ilios users'; -$string['enrolilios'] = 'Enrol Ilios cohort/learner group/users'; -$string['enrolilioscohort'] = 'Enrol cohort'; -$string['enroliliosgroup'] = 'Enrol group'; -$string['enroliliosusers'] = 'Enrol users'; $string['enrolusers'] = 'Enrol users'; $string['host_url'] = 'Host URL'; $string['host_url_desc'] = 'Type Ilios server IP address or host URL.'; @@ -48,6 +44,8 @@ $string['ilios:config'] = 'Configure ilios instances'; $string['ilios:unenrol'] = 'Unenrol suspended users'; $string['instanceexists'] = 'Ilios sync is already synchronised with selected role'; +$string['instructor'] = 'Instructor'; +$string['learner'] = 'Learner'; $string['learnergroup'] = 'Learner group (sub-groups) (learners)'; $string['learnergroup_help'] = 'This corresponds to the Learner groups in Ilios'; $string['learnergroupoptionsupdate'] = 'Update learner group options'; diff --git a/lang/en_us/enrol_ilios.php b/lang/en_us/enrol_ilios.php index 55e5f48..014bdd8 100644 --- a/lang/en_us/enrol_ilios.php +++ b/lang/en_us/enrol_ilios.php @@ -34,10 +34,6 @@ $string['defaultlearnerrole'] = 'Default learner role'; $string['defaultinstructorrole'] = 'Default instructor role'; $string['enrol'] = 'Enroll Ilios users'; -$string['enrolilios'] = 'Enroll Ilios cohort/learner group/users'; -$string['enrolilioscohort'] = 'Enroll cohort'; -$string['enroliliosgroup'] = 'Enroll group'; -$string['enroliliosusers'] = 'Enroll users'; $string['enrolusers'] = 'Enroll users'; $string['host_url'] = 'Host URL'; $string['host_url_desc'] = 'Type Ilios server IP address or host URL.'; @@ -48,6 +44,8 @@ $string['ilios:config'] = 'Configure ilios instances'; $string['ilios:unenrol'] = 'Unenroll suspended users'; $string['instanceexists'] = 'Ilios sync is already synchronized with selected role'; +$string['instructor'] = 'Instructor'; +$string['learner'] = 'Learner'; $string['learnergroup'] = 'Learner group (sub-groups) (learners)'; $string['learnergroup_help'] = 'This corresponds to the Learner groups in Ilios'; $string['learnergroupoptionsupdate'] = 'Update learner group options'; diff --git a/lib.php b/lib.php index 589a92a..8aee322 100644 --- a/lib.php +++ b/lib.php @@ -289,9 +289,6 @@ public function get_user_enrolment_actions(course_enrolment_manager $manager, $u /** * Returns a button to enrol a ilios or its users through the manual enrolment plugin. * - * This function also adds a quickenrolment JS ui to the page so that users can be enrolled - * via AJAX. - * * @param course_enrolment_manager $manager * @return enrol_user_button */ @@ -303,39 +300,6 @@ public function get_manual_enrol_button(course_enrolment_manager $manager) { $iliosurl = new moodle_url('/enrol/ilios/edit.php', array('courseid' => $course->id)); $button = new enrol_user_button($iliosurl, get_string('enrol', 'enrol_ilios'), 'get'); - $button->class .= ' enrol_ilios_plugin'; - - $button->strings_for_js(array( - 'enrol', - 'synced', - ), 'enrol'); - $button->strings_for_js(array( - 'ajaxmore', - 'enrolilios', - 'enrolilioscohort', - 'enroliliosgroup', - 'enroliliosusers', - 'iliosgroups', - 'iliosgroupsearch', - 'school', - 'program', - 'cohort' - ), 'enrol_ilios'); - $button->strings_for_js('assignroles', 'role'); - $button->strings_for_js('ilios', 'enrol_ilios'); - $button->strings_for_js('users', 'moodle'); - - // No point showing this at all if the user cant manually enrol users. - $hasmanualinstance = has_capability('enrol/manual:enrol', $manager->get_context()) && $manager->has_instance('manual'); - - $modules = array('moodle-enrol_ilios-quickenrolment', 'moodle-enrol_ilios-quickenrolment-skin'); - $function = 'M.enrol_ilios.quickenrolment.init'; - $arguments = array( - 'courseid' => $course->id, - 'ajaxurl' => '/enrol/ilios/ajax.php', - 'url' => $manager->get_moodlepage()->url->out(false), - 'manualEnrolment' => $hasmanualinstance); - $button->require_yui_module($modules, $function, array($arguments)); return $button; } diff --git a/locallib.php b/locallib.php index 23a1ba4..da6a640 100644 --- a/locallib.php +++ b/locallib.php @@ -232,150 +232,3 @@ function enrol_ilios_sync(progress_trace $trace, $courseid = NULL) { return 0; } - -/** - * Enrols all of the users in a cohort through a manual plugin instance. - * - * In order for this to succeed the course must contain a valid manual - * enrolment plugin instance that the user has permission to enrol users through. - * - * @global moodle_database $DB - * @param course_enrolment_manager $manager - * @param int $cohortid - * @param int $roleid - * @return int - */ - -// DISABLED: This is being called by ajax.php. // TODO: Update this to take learner group id -function enrol_ilios_enrol_all_users(course_enrolment_manager $manager, $cohortid, $roleid) { - global $DB; - $context = $manager->get_context(); - require_capability('moodle/course:enrolconfig', $context); - - $instance = false; - $instances = $manager->get_enrolment_instances(); - foreach ($instances as $i) { - if ($i->enrol == 'manual') { - $instance = $i; - break; - } - } - $plugin = enrol_get_plugin('manual'); - if (!$instance || !$plugin || !$plugin->allow_enrol($instance) || !has_capability('enrol/'.$plugin->get_name().':enrol', $context)) { - return false; - } - $sql = "SELECT com.userid - FROM {cohort_members} com - LEFT JOIN ( - SELECT * - FROM {user_enrolments} ue - WHERE ue.enrolid = :enrolid - ) ue ON ue.userid=com.userid - WHERE com.cohortid = :cohortid AND ue.id IS NULL"; - $params = array('cohortid' => $cohortid, 'enrolid' => $instance->id); - $rs = $DB->get_recordset_sql($sql, $params); - $count = 0; - foreach ($rs as $user) { - $count++; - $plugin->enrol_user($instance, $user->userid, $roleid); - } - $rs->close(); - return $count; -} - -/** - * Check if cohort exists and user is allowed to enrol it. - * - * @global moodle_database $DB - * @param int $cohortid Ilios enrolment ID - * @return boolean - */ -// TODO: Being called by ajax.php. Not really needed. -function enrol_ilios_can_view_cohort($cohortid) { - global $DB; - $ilios = $DB->get_record('ilios', array('id' => $cohortid), 'id, contextid'); - if ($ilios) { - $context = context::instance_by_id($ilios->contextid); - if (has_capability('moodle/cohort:view', $context)) { - return true; - } - } - return false; -} - -/** - * Gets cohorts the user is able to view. - * - * @global moodle_database $DB - * @param course_enrolment_manager $manager - * @param int $offset limit output from - * @param int $limit items to output per load - * @param string $search search string - * @return array Array(more => bool, offset => int, cohorts => array) - */ -// TODO: Update to search learner groups -function enrol_ilios_search_cohorts(course_enrolment_manager $manager, $offset = 0, $limit = 25, $search = '') { - global $DB; - $context = $manager->get_context(); - $cohorts = array(); - $instances = $manager->get_enrolment_instances(); - $enrolled = array(); - foreach ($instances as $instance) { - if ($instance->enrol == 'ilios') { - $enrolled[] = $instance->customint1; - } - } - - list($sqlparents, $params) = $DB->get_in_or_equal($context->get_parent_context_ids()); - - // Add some additional sensible conditions. - $tests = array('contextid ' . $sqlparents); - - // Modify the query to perform the search if required. - if (!empty($search)) { - $conditions = array( - 'name', - 'idnumber', - 'description' - ); - $searchparam = '%' . $DB->sql_like_escape($search) . '%'; - foreach ($conditions as $key=>$condition) { - $conditions[$key] = $DB->sql_like($condition, "?", false); - $params[] = $searchparam; - } - $tests[] = '(' . implode(' OR ', $conditions) . ')'; - } - $wherecondition = implode(' AND ', $tests); - - $sql = "SELECT id, name, idnumber, contextid, description - FROM {cohort} - WHERE $wherecondition - ORDER BY name ASC, idnumber ASC"; - $rs = $DB->get_recordset_sql($sql, $params, $offset); - - // Produce the output respecting parameters. - foreach ($rs as $c) { - // Track offset. - $offset++; - // Check capabilities. - $context = context::instance_by_id($c->contextid); - if (!has_capability('moodle/cohort:view', $context)) { - continue; - } - if ($limit === 0) { - // We have reached the required number of items and know that there are more, exit now. - $offset--; - break; - } - $cohorts[$c->id] = array( - 'cohortid' => $c->id, - 'name' => shorten_text(format_string($c->name, true, array('context'=>context::instance_by_id($c->contextid))), 35), - 'users' => $DB->count_records('cohort_members', array('cohortid'=>$c->id)), - 'enrolled' => in_array($c->id, $enrolled) - ); - // Count items. - $limit--; - } - $rs->close(); - return array('more' => !(bool)$limit, 'offset' => $offset, 'cohorts' => $cohorts); -} diff --git a/yui/quickenrolment/assets/skins/sam/quickenrolment.css b/yui/quickenrolment/assets/skins/sam/quickenrolment.css deleted file mode 100644 index faa5791..0000000 --- a/yui/quickenrolment/assets/skins/sam/quickenrolment.css +++ /dev/null @@ -1,46 +0,0 @@ -.qce-panel {background-color:#666;border:2px solid #666;border-width:0 2px 2px 0;min-width:420px;} -.qce-panel .yui3-widget-hd {background:url("sprite.png");background-repeat:repeat-x;background-color:#DDD;background-position: 0 -15px;border-bottom:1px solid #555;border-top:1px solid #fff;} -.qce-panel .yui3-widget-hd h2 {margin:3px 5px 2px;padding:0;font-size:110%;} -.qce-panel .yui3-widget-hd .close {width:25px;height:15px;position:absolute;top:3px;right:1em;cursor:pointer;background:url("sprite.png") no-repeat scroll 0 0 transparent;} -.dir-rtl .qce-panel .yui3-widget-hd .close {right:auto;left:1em;} -.qce-panel .yui3-overlay-content {background-color:#F6F6F6;border:1px solid #555;margin-top:-2px;margin-left:-2px;} -.qce-panel .qce-enrollable-ilios-groups {margin:5px;} -.qce-panel .qce-cohorts {border:1px solid #666;min-width:408px;background-color:#FFF;height:375px;overflow:auto;} -.qce-panel .qce-cohorts .qce-more-results {background-color:#eee;padding:5px;border-top:1px solid #BBB;text-align:center;} - -.qce-panel .qce-panel-content {min-height:405px;} -.qce-panel .qce-panel-content .qce-loading-lightbox {position:absolute;width:100%;height:100%;top:0;left:0;background-color:#FFF;min-height:264px;text-align:center;} -.qce-panel .qce-panel-content .qce-loading-lightbox.hidden {display:none;} -.qce-panel .qce-panel-content .qce-loading-lightbox .loading-icon {margin:auto;vertical-align:middle;margin-top:198px;} - -.qce-panel .qce-cohort {width:100%;position:relative;clear:both;height:24px;white-space:nowrap;} -.qce-panel .qce-cohort div {display:inline-block;overflow:hidden;} -.qce-panel .qce-cohort.odd {background-color:#f4f4f4;} -.qce-panel .qce-cohort .qce-cohort-button {text-align:center;display:inline-block;font-size:80%;height:22px;line-height:22px;overflow:hidden;padding:0 4px;} -.qce-panel .qce-cohort .qce-cohort-button.notenrolled {background-color:#ddd;border:1px outset #CCC;background:url("sprite.png");background-repeat:repeat-x;background-color:#DDD;background-position: 0 -25px;color:inherit;} -.qce-panel .qce-cohort .qce-cohort-button.notenrolled:hover {background-position:0 -15px;cursor:pointer;} -.qce-panel .qce-cohort .qce-cohort-button.notenrolled.enrolusers {margin-right: 4px;} -.qce-panel .qce-cohort .qce-cohort-button.alreadyenrolled {font-weight:bold;} -.qce-panel .qce-cohort .qce-cohort-name {line-height:24px;width:220px;} -.qce-panel .canenrolusers .qce-cohort .qce-cohort-button.alreadyenrolled {width:125px;} -.qce-panel .canenrolusers .qce-cohort .qce-cohort-name {line-height:24px;} -.qce-panel .qce-cohort .qce-cohort-users {width:30px;text-align:right;height:24px;line-height:24px;margin-right:4px} - -.qce-panel .qce-ilios-schools {margin:5px 6px 0 6px;} -.qce-panel .qce-ilios-schools label {padding-right:8px;} -.qce-panel .qce-ilios-programs {margin:5px 6px 0 6px;} -.qce-panel .qce-ilios-programs label {padding-right:8px;} -.qce-panel .qce-ilios-cohorts {margin:5px 6px 0 6px;} -.qce-panel .qce-ilios-cohorts label {padding-right:8px;} -.qce-panel .qce-assignable-roles {margin:5px 6px 0 6px;} -.qce-panel .qce-assignable-roles label {padding-right:8px;} - -.qce-panel .qce-footer {margin:0 6px 5px 6px;} -.qce-panel .qce-search label {padding-right:8px;} -.qce-panel .qce-search input {width:70%;} - -.qce-panel .qce-cohort.headings {font-weight:bold;border-width:0;} -.qe-panel .qce-cohort.headings .qce-cohort-button {display:none;} - -.ie7 .qce-panel .qce-cohort div, -.ie7 .qce-panel .canenrolusers .qce-cohort .qce-cohort-name {float:left;} diff --git a/yui/quickenrolment/assets/skins/sam/sprite.png b/yui/quickenrolment/assets/skins/sam/sprite.png deleted file mode 100644 index 067c225..0000000 Binary files a/yui/quickenrolment/assets/skins/sam/sprite.png and /dev/null differ diff --git a/yui/quickenrolment/quickenrolment.js b/yui/quickenrolment/quickenrolment.js deleted file mode 100644 index 4e03926..0000000 --- a/yui/quickenrolment/quickenrolment.js +++ /dev/null @@ -1,542 +0,0 @@ -YUI.add('moodle-enrol_ilios-quickenrolment-disbled', function(Y) { - - var CONTROLLERNAME = 'Quick ilios enrolment controller', - COHORTNAME = 'Cohort', - COHORTID = 'cohortid', - ENROLLED = 'enrolled', - NAME = 'name', - USERS = 'users', - COURSEID = 'courseid', - ASSIGNABLEROLES = 'assignableRoles', - DEFAULTILIOSROLE = 'defaultIliosRole', - ILIOSSCHOOLS = 'iliosschools', - ILIOSPROGRAMS = 'iliosprograms', - // Moodle COHORTS - remove - COHORTS = 'cohorts', - ILIOSCOHORTS = 'ilioscohorts', - ILIOSGROUPS = 'iliosgroups', - MORERESULTS = 'moreresults', - FIRSTPAGE = 'firstpage', - OFFSET = 'offset', - PANELID = 'qce-panel-', - REQUIREREFRESH = 'requiresRefresh', - SEARCH = 'search', - URL = 'url', - AJAXURL = 'ajaxurl', - MANUALENROLMENT = 'manualEnrolment', - CSS = { - CLOSEBTN : 'close-button', - COHORT : 'qce-cohort', - COHORTS : 'qce-cohorts', - COHORTBUTTON : 'qce-cohort-button', - COHORTENROLLED : 'qce-cohort-enrolled', - COHORTNAME : 'qce-cohort-name', - COHORTUSERS : 'qce-cohort-users', - ENROLUSERS : 'canenrolusers', - FOOTER : 'qce-footer', - HIDDEN : 'hidden', - LIGHTBOX : 'qce-loading-lightbox', - LOADINGICON : 'loading-icon', - MORERESULTS : 'qce-more-results', - PANEL : 'qce-panel', - PANELCONTENT : 'qce-panel-content', - PANELILIOSGROUPS : 'qce-enrollable-ilios-groups', - PANELCOHORTS : 'qce-ilios-cohorts', - PANELPROGRAMS : 'qce-ilios-programs', - PANELROLES : 'qce-assignable-roles', - PANELSCHOOLS : 'qce-ilios-schools', - PANELCONTROLS : 'qce-panel-controls', - SEARCH : 'qce-search' - }, - COUNT = 0; - - - var CONTROLLER = function(config) { - CONTROLLER.superclass.constructor.apply(this, arguments); - }; - CONTROLLER.prototype = { - initializer : function(config) { - COUNT ++; - this.publish('assignablerolesloaded', {fireOnce:true}); - this.publish('iliosgroupsloaded'); - this.publish('defaultiliosroleloaded', {fireOnce:true}); - - var finishbutton = Y.Node.create('
') - .append(Y.Node.create('')); - var base = Y.Node.create('
') - .append(Y.Node.create('
')) - .append(Y.Node.create('
')) - .append(Y.Node.create('
')) - .append(Y.Node.create('
')) - .append(Y.Node.create('
')) - .append(Y.Node.create('
') - .append(Y.Node.create('
') - .append(Y.Node.create('')) - ) - .append(finishbutton) - ) - .append(Y.Node.create('
') - .append(Y.Node.create('loading') - .setAttribute('src', M.util.image_url('i/loading', 'moodle'))) - .setStyle('opacity', 0.5) - ); - - var close = Y.Node.create('
'); - var panel = new Y.Overlay({ - headerContent : Y.Node.create('
').append(Y.Node.create('

'+M.str.enrol_ilios.enrolilios+'

')).append(close), - bodyContent : base, - constrain : true, - centered : true, - id : PANELID+COUNT, - visible : false - }); - - // display the wheel on ajax events - Y.on('io:start', function() { - base.one('.'+CSS.LIGHTBOX).removeClass(CSS.HIDDEN); - }, this); - Y.on('io:end', function() { - base.one('.'+CSS.LIGHTBOX).addClass(CSS.HIDDEN); - }, this); - - this.set(SEARCH, base.one('#enroliliosgroupsearch')); - Y.on('key', this.getIliosGroups, this.get(SEARCH), 'down:13', this, false); - - panel.get('boundingBox').addClass(CSS.PANEL); - panel.render(Y.one(document.body)); - this.on('show', function(){ - this.set('centered', true); - this.show(); - }, panel); - this.on('hide', panel.hide, panel); - this.on('iliosschoolsloaded', this.updateContent, this, panel); - this.on('iliosprogramsloaded', this.updateContent, this, panel); - this.on('ilioscohortsloaded', this.updateContent, this, panel); - this.on('assignablerolesloaded', this.updateContent, this, panel); - // this.on('cohortsloaded', this.updateContent, this, panel); - this.on('iliosgroupsloaded', this.updateContent, this, panel); - this.on('defaultiliosroleloaded', this.updateContent, this, panel); - Y.on('key', this.hide, document.body, 'down:27', this); - close.on('click', this.hide, this); - finishbutton.on('click', this.hide, this); - - Y.all('.enrol_ilios_plugin input').each(function(node){ - if (node.getAttribute('type', 'submit')) { - node.on('click', this.show, this); - } - }, this); - - base = panel.get('boundingBox'); - base.plug(Y.Plugin.Drag); - base.dd.addHandle('.yui3-widget-hd h2'); - base.one('.yui3-widget-hd h2').setStyle('cursor', 'move'); - }, - show : function(e) { - e.preventDefault(); - // prepare the data and display the window - //this.getCohorts(e, false); - this.getIliosSchools(); - this.getAssignableRoles(); - this.fire('show'); - - var rolesselect = Y.one('#id_enrol_ilios_assignable_roles'); - if (rolesselect) { - rolesselect.focus(); - } - }, - updateContent : function(e, panel) { - var content, i, roles, schools, programs, cohorts, count=0, supportmanual = this.get(MANUALENROLMENT), defaultrole; - switch (e.type.replace(/^[^:]+:/, '')) { - case 'iliosgroupsloaded' : - case 'cohortsloaded' : - if (this.get(FIRSTPAGE)) { - // we are on the page 0, create new element for cohorts list - content = Y.Node.create('
'); - if (supportmanual) { - content.addClass(CSS.ENROLUSERS); - } - } else { - // we are adding cohorts to existing list - content = Y.Node.one('.'+CSS.PANELILIOSGROUPS+' .'+CSS.COHORTS); - content.one('.'+CSS.MORERESULTS).remove(); - } - // add cohorts items to the content - cohorts = this.get(COHORTS); - for (i in cohorts) { - count++; - cohorts[i].on('enrolchort', this.enrolCohort, this, cohorts[i], panel.get('contentBox'), false); - cohorts[i].on('enrolusers', this.enrolCohort, this, cohorts[i], panel.get('contentBox'), true); - content.append(cohorts[i].toHTML(supportmanual).addClass((count%2)?'even':'odd')); - } - // add the next link if there are more items expected - if (this.get(MORERESULTS)) { - var fetchmore = Y.Node.create('
'+M.str.enrol_ilios.ajaxmore+'
'); - fetchmore.on('click', this.getCohorts, this, true); - content.append(fetchmore); - } - // finally assing the content to the block - if (this.get(FIRSTPAGE)) { - panel.get('contentBox').one('.'+CSS.PANELILIOSGROUPS).setContent(content); - } - break; - case 'assignablerolesloaded': - roles = this.get(ASSIGNABLEROLES); - content = Y.Node.create(''); - for (i in roles) { - content.append(Y.Node.create('')); - } - panel.get('contentBox').one('.'+CSS.PANELROLES).setContent(Y.Node.create('
').append(content)); - - this.getDefaultIliosRole(); - Y.one('#id_enrol_ilios_assignable_roles').focus(); - break; - case 'iliosschoolsloaded': - schools = this.get(ILIOSSCHOOLS); - content = Y.Node.create(''); - content.on('change', this.getIliosPrograms, this); - for (i in schools) { - content.append(Y.Node.create('')); - } - panel.get('contentBox').one('.'+CSS.PANELSCHOOLS).setContent(Y.Node.create('
').append(content)); - - // this.getDefaultCohortRole(); - // Y.one('#id_enrol_ilios_schools').focus(); - break; - case 'iliosprogramsloaded': - programs = this.get(ILIOSPROGRAMS); - content = Y.Node.create(''); - content.on('change', this.getIliosCohorts, this); - for (i in programs) { - content.append(Y.Node.create('')); - } - panel.get('contentBox').one('.'+CSS.PANELPROGRAMS).setContent(Y.Node.create('
').append(content)); - - // this.getDefaultIliosRole(); - // Y.one('#id_enrol_ilios_programs').focus(); - break; - case 'ilioscohortsloaded': - cohorts = this.get(ILIOSCOHORTS); - content = Y.Node.create(''); - for (i in cohorts) { - content.append(Y.Node.create('')); - } - panel.get('contentBox').one('.'+CSS.PANELCOHORTS).setContent(Y.Node.create('
').append(content)); - - // this.getDefaultIliosRole(); - // Y.one('#id_enrol_ilios_cohorts').focus(); - break; - case 'defaultiliosroleloaded': - defaultrole = this.get(DEFAULTILIOSROLE); - panel.get('contentBox').one('.'+CSS.PANELROLES+' select').set('value', defaultrole); - break; - } - }, - hide : function() { - if (this.get(REQUIREREFRESH)) { - window.location = this.get(URL); - } - this.fire('hide'); - }, - getCohorts : function(e, append) { - if (e) { - e.preventDefault(); - } - if (append) { - this.set(FIRSTPAGE, false); - } else { - this.set(FIRSTPAGE, true); - this.set(OFFSET, 0); - } - var params = []; - params['id'] = this.get(COURSEID); - params['offset'] = this.get(OFFSET); - params['search'] = this.get(SEARCH).get('value'); - params['action'] = 'getcohorts'; - params['sesskey'] = M.cfg.sesskey; - - Y.io(M.cfg.wwwroot+this.get(AJAXURL), { - method:'POST', - data:build_querystring(params), - on: { - complete: function(tid, outcome, args) { - try { - var cohorts = Y.JSON.parse(outcome.responseText); - if (cohorts.error) { - new M.core.ajaxException(cohorts); - } else { - this.setCohorts(cohorts.response); - } - } catch (e) { - return new M.core.exception(e); - } - this.fire('iliosgroupsloaded'); - } - }, - context:this - }); - }, - setCohorts : function(response) { - this.set(MORERESULTS, response.more); - this.set(OFFSET, response.offset); - var rawcohorts = response.cohorts; - var cohorts = [], i=0; - for (i in rawcohorts) { - cohorts[i] = new COHORT(rawcohorts[i]); - } - this.set(COHORTS, cohorts); - }, - getAssignableRoles : function() { - Y.io(M.cfg.wwwroot+this.get(AJAXURL), { - method:'POST', - data:'id='+this.get(COURSEID)+'&action=getassignable&sesskey='+M.cfg.sesskey, - on: { - complete: function(tid, outcome, args) { - try { - var roles = Y.JSON.parse(outcome.responseText); - this.set(ASSIGNABLEROLES, roles.response); - } catch (e) { - return new M.core.exception(e); - } - this.getAssignableRoles = function() { - this.fire('assignablerolesloaded'); - }; - this.getAssignableRoles(); - } - }, - context:this - }); - }, - getDefaultIliosRole : function() { - Y.io(M.cfg.wwwroot+this.get(AJAXURL), { - method:'POST', - data:'id='+this.get(COURSEID)+'&action=getdefaultiliosrole&sesskey='+M.cfg.sesskey, - on: { - complete: function(tid, outcome, args) { - try { - var roles = Y.JSON.parse(outcome.responseText); - this.set(DEFAULTILIOSROLE, roles.response); - } catch (e) { - return new M.core.exception(e); - } - this.fire('defaultiliosroleloaded'); - } - }, - context:this - }); - }, - getIliosSchools : function() { - Y.io(M.cfg.wwwroot+this.get(AJAXURL), { - method:'POST', - data:'id='+this.get(COURSEID)+'&action=getiliosschools&sesskey='+M.cfg.sesskey, - on: { - complete: function(tid, outcome, args) { - try { - var schools = Y.JSON.parse(outcome.responseText); - this.set(ILIOSSCHOOLS, schools.response); - } catch (e) { - return new M.core.exception(e); - } - this.fire('iliosschoolsloaded'); - } - }, - context:this - }); - }, - getIliosPrograms : function(e) { - var sid = e.currentTarget.get('options').item(e.currentTarget.get('selectedIndex')).get('value'); - Y.io(M.cfg.wwwroot+this.get(AJAXURL), { - method:'POST', - data:'id='+this.get(COURSEID)+'&action=getiliosprograms&schoolid='+sid+'&sesskey='+M.cfg.sesskey, - on: { - complete: function(tid, outcome, args) { - try { - var programs = Y.JSON.parse(outcome.responseText); - this.set(ILIOSPROGRAMS, programs.response); - } catch (e) { - return new M.core.exception(e); - } - this.fire('iliosprogramsloaded'); - } - }, - context:this - }); - }, - getIliosCohorts : function(e) { - var pid = e.currentTarget.get('options').item(e.currentTarget.get('selectedIndex')).get('value'); - Y.io(M.cfg.wwwroot+this.get(AJAXURL), { - method:'POST', - data:'id='+this.get(COURSEID)+'&action=getilioscohorts&programid='+pid+'&sesskey='+M.cfg.sesskey, - on: { - complete: function(tid, outcome, args) { - try { - var cohorts = Y.JSON.parse(outcome.responseText); - this.set(ILIOSCOHORTS, cohorts.response); - } catch (e) { - return new M.core.exception(e); - } - this.fire('ilioscohortsloaded'); - } - }, - context:this - }); - }, - getIliosGroups : function(e, append) { - if (e) { - e.preventDefault(); - } - if (append) { - this.set(FIRSTPAGE, false); - } else { - this.set(FIRSTPAGE, true); - this.set(OFFSET, 0); - } - var params = []; - params['id'] = this.get(COURSEID); - params['offset'] = this.get(OFFSET); - params['search'] = this.get(SEARCH).get('value'); - params['action'] = 'getcohorts'; - params['sesskey'] = M.cfg.sesskey; - - Y.io(M.cfg.wwwroot+this.get(AJAXURL), { - method:'POST', - data:build_querystring(params), - on: { - complete: function(tid, outcome, args) { - try { - var cohorts = Y.JSON.parse(outcome.responseText); - if (cohorts.error) { - new M.core.ajaxException(cohorts); - } else { - this.setCohorts(cohorts.response); - } - } catch (e) { - return new M.core.exception(e); - } - this.fire('iliosgroupsloaded'); - } - }, - context:this - }); - }, - enrolCohort : function(e, cohort, node, usersonly) { - var params = { - id : this.get(COURSEID), - roleid : node.one('.'+CSS.PANELROLES+' select').get('value'), - cohortid : cohort.get(COHORTID), - action : (usersonly)?'enroliliosusers':'enroliliosgroup', - sesskey : M.cfg.sesskey - }; - Y.io(M.cfg.wwwroot+this.get(AJAXURL), { - method:'POST', - data:build_querystring(params), - on: { - complete: function(tid, outcome, args) { - try { - var result = Y.JSON.parse(outcome.responseText); - if (result.error) { - new M.core.ajaxException(result); - } else { - if (result.response && result.response.message) { - var alertpanel = new M.core.alert(result.response); - Y.Node.one('#id_yuialertconfirm-' + alertpanel.get('COUNT')).focus(); - } - var enrolled = Y.Node.create('
'+M.str.enrol.synced+'
'); - node.one('.'+CSS.COHORT+' #cohortid_'+cohort.get(COHORTID)).replace(enrolled); - this.set(REQUIREREFRESH, true); - } - } catch (e) { - new M.core.exception(e); - } - } - }, - context:this - }); - return true; - } - }; - Y.extend(CONTROLLER, Y.Base, CONTROLLER.prototype, { - NAME : CONTROLLERNAME, - ATTRS : { - url : { - validator : Y.Lang.isString - }, - ajaxurl : { - validator : Y.Lang.isString - }, - courseid : { - value : null - }, - cohorts : { - validator : Y.Lang.isArray, - value : null - }, - assignableRoles : { - value : null - }, - manualEnrolment : { - value : false - }, - defaultIliosRole : { - value : null - }, - requiresRefresh : { - value : false, - validator : Y.Lang.isBool - } - } - }); - Y.augment(CONTROLLER, Y.EventTarget); - - var COHORT = function(config) { - COHORT.superclass.constructor.apply(this, arguments); - }; - Y.extend(COHORT, Y.Base, { - toHTML : function(supportmanualenrolment){ - var button, result, name, users, syncbutton, usersbutton; - result = Y.Node.create('
'); - if (this.get(ENROLLED)) { - button = Y.Node.create('
'+M.str.enrol.synced+'
'); - } else { - button = Y.Node.create('
'); - - syncbutton = Y.Node.create(''+M.str.enrol_ilios.enroliliosgroup+''); - syncbutton.on('click', function(){this.fire('enrolchort');}, this); - button.append(syncbutton); - - if (supportmanualenrolment) { - usersbutton = Y.Node.create(''+M.str.enrol_ilios.enroliliosusers+''); - usersbutton.on('click', function(){this.fire('enrolusers');}, this); - button.append(usersbutton); - } - } - name = Y.Node.create('
'+this.get(NAME)+'
'); - users = Y.Node.create('
'+this.get(USERS)+'
'); - return result.append(button).append(name).append(users); - } - }, { - NAME : COHORTNAME, - ATTRS : { - cohortid : { - - }, - name : { - validator : Y.Lang.isString - }, - enrolled : { - value : false - }, - users : { - value : 0 - } - } - }); - Y.augment(COHORT, Y.EventTarget); - - M.enrol_ilios = M.enrol || {}; - M.enrol_ilios.quickenrolment = { - init : function(cfg) { - new CONTROLLER(cfg); - } - } - -}, '@VERSION@', {requires:['base','node', 'overlay', 'io-base', 'test', 'json-parse', 'event-delegate', 'dd-plugin', 'event-key', 'moodle-core-notification']});