diff --git a/classes/condition.php b/classes/condition.php index ee55834..d538036 100644 --- a/classes/condition.php +++ b/classes/condition.php @@ -3,13 +3,18 @@ namespace availability_examus; defined('MOODLE_INTERNAL') || die(); +use core_availability\info_module; use stdClass; class condition extends \core_availability\condition { + protected $duration = 60; public function __construct($structure) { + if (!empty($structure->duration)) { + $this->duration = $structure->duration; + } } private static function delete_empty_entry($userid, $courseid, $cmid) @@ -25,8 +30,25 @@ private static function examus_enabled_for($cm) return strpos($cm->availability, '"c":[{"type":"examus"}]') !== false; } + public static function has_examus_condition(cm_info $cm) { + $econds = self::get_examus_conditions($cm); + return (bool)$econds; + } + + public static function get_examus_duration(cm_info $cm) { + $econds = self::get_examus_conditions($cm); + return $econds[0]->duration; + } + + private static function get_examus_conditions(cm_info $cm) { + $info = new info_module($cm); + $tree = $info->get_availability_tree(); + return $tree->get_all_children('\\availability_examus\\condition'); + } + public function save() { + return (object) ['duration' => $this->duration]; } public function is_available($not, @@ -64,9 +86,13 @@ public static function course_module_deleted(\core\event\course_module_deleted $ private static function create_entry_if_not_exist($userid, $courseid, $cmid) { global $DB; - $entry = $DB->get_record('availability_examus', array( - 'userid' => $userid, 'courseid' => $courseid, 'cmid' => $cmid)); - if (!$entry) { + $entries = $DB->get_records( + 'availability_examus', + array('userid' => $userid, 'courseid' => $courseid, 'cmid' => $cmid), + $sort='id'); + + + if (count($entries) !== 0) { $timenow = time(); $entry = new stdClass(); $entry->userid = $userid; diff --git a/classes/frontend.php b/classes/frontend.php index c1f9d8e..6b352a4 100644 --- a/classes/frontend.php +++ b/classes/frontend.php @@ -7,7 +7,7 @@ class frontend extends \core_availability\frontend { protected function get_javascript_strings() { - return array(); + return ['title', 'error_setduration', 'duration']; } protected function get_javascript_init_params($course, \cm_info $cm = null, diff --git a/db/install.xml b/db/install.xml index 0a1f5e8..9b0609b 100644 --- a/db/install.xml +++ b/db/install.xml @@ -15,6 +15,7 @@ + diff --git a/externallib.php b/externallib.php index 4e314c7..2cb68ee 100644 --- a/externallib.php +++ b/externallib.php @@ -39,7 +39,7 @@ public static function user_proctored_modules($useremail) $user = $DB->get_record('user', array('email' => $useremail)); - $entries = $DB->get_records('availability_examus', array('userid' => $user->id)); + $entries = $DB->get_records('availability_examus', array('userid' => $user->id, 'status' => 'Not inited')); $answer = array(); foreach ($entries as $entry) { diff --git a/lang/en/availability_examus.php b/lang/en/availability_examus.php index 1a1c355..407931b 100644 --- a/lang/en/availability_examus.php +++ b/lang/en/availability_examus.php @@ -11,6 +11,7 @@ $string['review'] = 'Review'; $string['module'] = 'Module'; $string['new_entry'] = 'New entry'; - +$string['error_setduration'] = 'Duration in minutes'; +$string['duration'] = 'Duration in minutes'; $string[''] = ''; \ No newline at end of file diff --git a/version.php b/version.php index 990f428..48c6dc7 100644 --- a/version.php +++ b/version.php @@ -3,7 +3,7 @@ defined('MOODLE_INTERNAL') || die(); $plugin->component = 'availability_examus'; -$plugin->version = 2016103105; +$plugin->version = 2016103107; $plugin->release = 'v3.1-r1'; $plugin->requires = 2016052300; $plugin->maturity = MATURITY_STABLE; diff --git a/yui/build/moodle-availability_examus-form/moodle-availability_examus-form-coverage.js b/yui/build/moodle-availability_examus-form/moodle-availability_examus-form-coverage.js index 2810548..2fc53b7 100644 --- a/yui/build/moodle-availability_examus-form/moodle-availability_examus-form-coverage.js +++ b/yui/build/moodle-availability_examus-form/moodle-availability_examus-form-coverage.js @@ -1,6 +1,6 @@ if (typeof __coverage__ === 'undefined') { __coverage__ = {}; } if (!__coverage__['build/moodle-availability_examus-form/moodle-availability_examus-form.js']) { - __coverage__['build/moodle-availability_examus-form/moodle-availability_examus-form.js'] = {"path":"build/moodle-availability_examus-form/moodle-availability_examus-form.js","s":{"1":0,"2":0,"3":0,"4":0,"5":0,"6":0,"7":0,"8":0,"9":0,"10":0},"b":{"1":[0,0]},"f":{"1":0,"2":0,"3":0,"4":0},"fnMap":{"1":{"name":"(anonymous_1)","line":1,"loc":{"start":{"line":1,"column":43},"end":{"line":1,"column":62}}},"2":{"name":"(anonymous_2)","line":21,"loc":{"start":{"line":21,"column":37},"end":{"line":21,"column":52}}},"3":{"name":"(anonymous_3)","line":29,"loc":{"start":{"line":29,"column":39},"end":{"line":29,"column":61}}},"4":{"name":"(anonymous_4)","line":32,"loc":{"start":{"line":32,"column":40},"end":{"line":32,"column":63}}}},"statementMap":{"1":{"start":{"line":1,"column":0},"end":{"line":35,"column":90}},"2":{"start":{"line":9,"column":0},"end":{"line":9,"column":52}},"3":{"start":{"line":11,"column":0},"end":{"line":11,"column":66}},"4":{"start":{"line":21,"column":0},"end":{"line":27,"column":2}},"5":{"start":{"line":22,"column":4},"end":{"line":22,"column":44}},"6":{"start":{"line":23,"column":4},"end":{"line":23,"column":56}},"7":{"start":{"line":24,"column":4},"end":{"line":24,"column":60}},"8":{"start":{"line":26,"column":4},"end":{"line":26,"column":16}},"9":{"start":{"line":29,"column":0},"end":{"line":30,"column":2}},"10":{"start":{"line":32,"column":0},"end":{"line":33,"column":2}}},"branchMap":{"1":{"line":9,"type":"binary-expr","locations":[{"start":{"line":9,"column":24},"end":{"line":9,"column":45}},{"start":{"line":9,"column":49},"end":{"line":9,"column":51}}]}},"code":["(function () { YUI.add('moodle-availability_examus-form', function (Y, NAME) {","","/*global M*/","/**"," * JavaScript for form editing profile conditions."," *"," * @module moodle-availability_examus-form"," */","M.availability_examus = M.availability_examus || {};","","M.availability_examus.form = Y.Object(M.core_availability.plugin);","","// M.availability_examus.form.initInner = function(param) {","// // The 'param' variable is the parameter passed through from PHP (you","// // can have more than one if required).","//","// // Using the PHP code above it'll show 'The param was: frog'.","// console.log('The param was: ' + param);","// };","","M.availability_examus.form.getNode = function(json) {"," var strings = M.str.availability_examus;"," var html = '';"," var node = Y.Node.create(' ' + html + ' ');",""," return node;","};","","M.availability_examus.form.fillValue = function(value, node) {","};","","M.availability_examus.form.fillErrors = function(errors, node) {","};","","}, '@VERSION@', {\"requires\": [\"base\", \"node\", \"event\", \"moodle-core_availability-form\"]});","","}());"]}; + __coverage__['build/moodle-availability_examus-form/moodle-availability_examus-form.js'] = {"path":"build/moodle-availability_examus-form/moodle-availability_examus-form.js","s":{"1":0,"2":0,"3":0,"4":0,"5":0,"6":0,"7":0,"8":0,"9":0,"10":0,"11":0,"12":0,"13":0,"14":0,"15":0,"16":0,"17":0,"18":0,"19":0,"20":0,"21":0,"22":0,"23":0,"24":0,"25":0,"26":0,"27":0,"28":0,"29":0},"b":{"1":[0,0],"2":[0,0],"3":[0,0],"4":[0,0],"5":[0,0]},"f":{"1":0,"2":0,"3":0,"4":0,"5":0,"6":0},"fnMap":{"1":{"name":"(anonymous_1)","line":1,"loc":{"start":{"line":1,"column":43},"end":{"line":1,"column":62}}},"2":{"name":"(anonymous_2)","line":13,"loc":{"start":{"line":13,"column":39},"end":{"line":13,"column":50}}},"3":{"name":"(anonymous_3)","line":19,"loc":{"start":{"line":19,"column":37},"end":{"line":19,"column":52}}},"4":{"name":"(anonymous_4)","line":37,"loc":{"start":{"line":37,"column":37},"end":{"line":37,"column":49}}},"5":{"name":"(anonymous_5)","line":46,"loc":{"start":{"line":46,"column":39},"end":{"line":46,"column":61}}},"6":{"name":"(anonymous_6)","line":50,"loc":{"start":{"line":50,"column":40},"end":{"line":50,"column":63}}}},"statementMap":{"1":{"start":{"line":1,"column":0},"end":{"line":59,"column":90}},"2":{"start":{"line":9,"column":0},"end":{"line":9,"column":52}},"3":{"start":{"line":11,"column":0},"end":{"line":11,"column":66}},"4":{"start":{"line":13,"column":0},"end":{"line":15,"column":2}},"5":{"start":{"line":17,"column":0},"end":{"line":17,"column":38}},"6":{"start":{"line":19,"column":0},"end":{"line":44,"column":2}},"7":{"start":{"line":20,"column":4},"end":{"line":20,"column":38}},"8":{"start":{"line":21,"column":4},"end":{"line":21,"column":40}},"9":{"start":{"line":23,"column":4},"end":{"line":23,"column":54}},"10":{"start":{"line":24,"column":4},"end":{"line":24,"column":43}},"11":{"start":{"line":26,"column":4},"end":{"line":26,"column":56}},"12":{"start":{"line":27,"column":4},"end":{"line":27,"column":70}},"13":{"start":{"line":28,"column":4},"end":{"line":28,"column":66}},"14":{"start":{"line":29,"column":4},"end":{"line":29,"column":56}},"15":{"start":{"line":30,"column":4},"end":{"line":32,"column":5}},"16":{"start":{"line":31,"column":8},"end":{"line":31,"column":69}},"17":{"start":{"line":34,"column":4},"end":{"line":41,"column":5}},"18":{"start":{"line":35,"column":8},"end":{"line":35,"column":54}},"19":{"start":{"line":36,"column":8},"end":{"line":36,"column":61}},"20":{"start":{"line":37,"column":8},"end":{"line":40,"column":56}},"21":{"start":{"line":39,"column":12},"end":{"line":39,"column":46}},"22":{"start":{"line":43,"column":4},"end":{"line":43,"column":16}},"23":{"start":{"line":46,"column":0},"end":{"line":48,"column":2}},"24":{"start":{"line":47,"column":4},"end":{"line":47,"column":73}},"25":{"start":{"line":50,"column":0},"end":{"line":57,"column":2}},"26":{"start":{"line":51,"column":4},"end":{"line":51,"column":19}},"27":{"start":{"line":52,"column":4},"end":{"line":52,"column":32}},"28":{"start":{"line":54,"column":4},"end":{"line":56,"column":5}},"29":{"start":{"line":55,"column":8},"end":{"line":55,"column":61}}},"branchMap":{"1":{"line":9,"type":"binary-expr","locations":[{"start":{"line":9,"column":24},"end":{"line":9,"column":45}},{"start":{"line":9,"column":49},"end":{"line":9,"column":51}}]},"2":{"line":30,"type":"if","locations":[{"start":{"line":30,"column":4},"end":{"line":30,"column":4}},{"start":{"line":30,"column":4},"end":{"line":30,"column":4}}]},"3":{"line":34,"type":"if","locations":[{"start":{"line":34,"column":4},"end":{"line":34,"column":4}},{"start":{"line":34,"column":4},"end":{"line":34,"column":4}}]},"4":{"line":54,"type":"if","locations":[{"start":{"line":54,"column":4},"end":{"line":54,"column":4}},{"start":{"line":54,"column":4},"end":{"line":54,"column":4}}]},"5":{"line":54,"type":"binary-expr","locations":[{"start":{"line":54,"column":8},"end":{"line":54,"column":36}},{"start":{"line":54,"column":40},"end":{"line":54,"column":69}}]}},"code":["(function () { YUI.add('moodle-availability_examus-form', function (Y, NAME) {","","/*global M*/","/**"," * JavaScript for form editing profile conditions."," *"," * @module moodle-availability_examus-form"," */","M.availability_examus = M.availability_examus || {};","","M.availability_examus.form = Y.Object(M.core_availability.plugin);","","M.availability_examus.form.initInner = function() {"," // Nothing","};","","M.availability_examus.form.instId = 1;","","M.availability_examus.form.getNode = function(json) {"," var html, node, root, id, strings;"," strings = M.str.availability_examus;",""," id = 'examus' + M.availability_examus.form.instId;"," M.availability_examus.form.instId += 1;",""," html = '
';"," html += '';"," html += '';"," node = Y.Node.create(' ' + html + ' ');"," if (json.duration !== undefined) {"," node.one('input[name=duration]').set('value', json.duration);"," }",""," if (!M.availability_examus.form.addedEvents) {"," M.availability_examus.form.addedEvents = true;"," root = Y.one('#fitem_id_availabilityconditionsjson');"," root.delegate('valuechange', function () {"," // Trigger the updating of the hidden availability data whenever the password field changes."," M.core_availability.form.update();"," }, '.availability_examus input[name=duration]');"," }",""," return node;","};","","M.availability_examus.form.fillValue = function(value, node) {"," value.duration = node.one('input[name=duration').get('value').trim();","};","","M.availability_examus.form.fillErrors = function(errors, node) {"," var value = {};"," this.fillValue(value, node);",""," if (value.duration === undefined || !/^\\d+$/.test(value.duration)) {"," errors.push('availability_examus:error_setduration');"," }","};","","}, '@VERSION@', {\"requires\": [\"base\", \"node\", \"event\", \"moodle-core_availability-form\"]});","","}());"]}; } var __cov_VkxrC3bnPgMAADDnSvyZqQ = __coverage__['build/moodle-availability_examus-form/moodle-availability_examus-form.js']; -__cov_VkxrC3bnPgMAADDnSvyZqQ.s['1']++;YUI.add('moodle-availability_examus-form',function(Y,NAME){__cov_VkxrC3bnPgMAADDnSvyZqQ.f['1']++;__cov_VkxrC3bnPgMAADDnSvyZqQ.s['2']++;M.availability_examus=(__cov_VkxrC3bnPgMAADDnSvyZqQ.b['1'][0]++,M.availability_examus)||(__cov_VkxrC3bnPgMAADDnSvyZqQ.b['1'][1]++,{});__cov_VkxrC3bnPgMAADDnSvyZqQ.s['3']++;M.availability_examus.form=Y.Object(M.core_availability.plugin);__cov_VkxrC3bnPgMAADDnSvyZqQ.s['4']++;M.availability_examus.form.getNode=function(json){__cov_VkxrC3bnPgMAADDnSvyZqQ.f['2']++;__cov_VkxrC3bnPgMAADDnSvyZqQ.s['5']++;var strings=M.str.availability_examus;__cov_VkxrC3bnPgMAADDnSvyZqQ.s['6']++;var html='';__cov_VkxrC3bnPgMAADDnSvyZqQ.s['7']++;var node=Y.Node.create(' '+html+' ');__cov_VkxrC3bnPgMAADDnSvyZqQ.s['8']++;return node;};__cov_VkxrC3bnPgMAADDnSvyZqQ.s['9']++;M.availability_examus.form.fillValue=function(value,node){__cov_VkxrC3bnPgMAADDnSvyZqQ.f['3']++;};__cov_VkxrC3bnPgMAADDnSvyZqQ.s['10']++;M.availability_examus.form.fillErrors=function(errors,node){__cov_VkxrC3bnPgMAADDnSvyZqQ.f['4']++;};},'@VERSION@',{'requires':['base','node','event','moodle-core_availability-form']}); +__cov_VkxrC3bnPgMAADDnSvyZqQ.s['1']++;YUI.add('moodle-availability_examus-form',function(Y,NAME){__cov_VkxrC3bnPgMAADDnSvyZqQ.f['1']++;__cov_VkxrC3bnPgMAADDnSvyZqQ.s['2']++;M.availability_examus=(__cov_VkxrC3bnPgMAADDnSvyZqQ.b['1'][0]++,M.availability_examus)||(__cov_VkxrC3bnPgMAADDnSvyZqQ.b['1'][1]++,{});__cov_VkxrC3bnPgMAADDnSvyZqQ.s['3']++;M.availability_examus.form=Y.Object(M.core_availability.plugin);__cov_VkxrC3bnPgMAADDnSvyZqQ.s['4']++;M.availability_examus.form.initInner=function(){__cov_VkxrC3bnPgMAADDnSvyZqQ.f['2']++;};__cov_VkxrC3bnPgMAADDnSvyZqQ.s['5']++;M.availability_examus.form.instId=1;__cov_VkxrC3bnPgMAADDnSvyZqQ.s['6']++;M.availability_examus.form.getNode=function(json){__cov_VkxrC3bnPgMAADDnSvyZqQ.f['3']++;__cov_VkxrC3bnPgMAADDnSvyZqQ.s['7']++;var html,node,root,id,strings;__cov_VkxrC3bnPgMAADDnSvyZqQ.s['8']++;strings=M.str.availability_examus;__cov_VkxrC3bnPgMAADDnSvyZqQ.s['9']++;id='examus'+M.availability_examus.form.instId;__cov_VkxrC3bnPgMAADDnSvyZqQ.s['10']++;M.availability_examus.form.instId+=1;__cov_VkxrC3bnPgMAADDnSvyZqQ.s['11']++;html='
';__cov_VkxrC3bnPgMAADDnSvyZqQ.s['12']++;html+='';__cov_VkxrC3bnPgMAADDnSvyZqQ.s['13']++;html+='';__cov_VkxrC3bnPgMAADDnSvyZqQ.s['14']++;node=Y.Node.create(' '+html+' ');__cov_VkxrC3bnPgMAADDnSvyZqQ.s['15']++;if(json.duration!==undefined){__cov_VkxrC3bnPgMAADDnSvyZqQ.b['2'][0]++;__cov_VkxrC3bnPgMAADDnSvyZqQ.s['16']++;node.one('input[name=duration]').set('value',json.duration);}else{__cov_VkxrC3bnPgMAADDnSvyZqQ.b['2'][1]++;}__cov_VkxrC3bnPgMAADDnSvyZqQ.s['17']++;if(!M.availability_examus.form.addedEvents){__cov_VkxrC3bnPgMAADDnSvyZqQ.b['3'][0]++;__cov_VkxrC3bnPgMAADDnSvyZqQ.s['18']++;M.availability_examus.form.addedEvents=true;__cov_VkxrC3bnPgMAADDnSvyZqQ.s['19']++;root=Y.one('#fitem_id_availabilityconditionsjson');__cov_VkxrC3bnPgMAADDnSvyZqQ.s['20']++;root.delegate('valuechange',function(){__cov_VkxrC3bnPgMAADDnSvyZqQ.f['4']++;__cov_VkxrC3bnPgMAADDnSvyZqQ.s['21']++;M.core_availability.form.update();},'.availability_examus input[name=duration]');}else{__cov_VkxrC3bnPgMAADDnSvyZqQ.b['3'][1]++;}__cov_VkxrC3bnPgMAADDnSvyZqQ.s['22']++;return node;};__cov_VkxrC3bnPgMAADDnSvyZqQ.s['23']++;M.availability_examus.form.fillValue=function(value,node){__cov_VkxrC3bnPgMAADDnSvyZqQ.f['5']++;__cov_VkxrC3bnPgMAADDnSvyZqQ.s['24']++;value.duration=node.one('input[name=duration').get('value').trim();};__cov_VkxrC3bnPgMAADDnSvyZqQ.s['25']++;M.availability_examus.form.fillErrors=function(errors,node){__cov_VkxrC3bnPgMAADDnSvyZqQ.f['6']++;__cov_VkxrC3bnPgMAADDnSvyZqQ.s['26']++;var value={};__cov_VkxrC3bnPgMAADDnSvyZqQ.s['27']++;this.fillValue(value,node);__cov_VkxrC3bnPgMAADDnSvyZqQ.s['28']++;if((__cov_VkxrC3bnPgMAADDnSvyZqQ.b['5'][0]++,value.duration===undefined)||(__cov_VkxrC3bnPgMAADDnSvyZqQ.b['5'][1]++,!/^\d+$/.test(value.duration))){__cov_VkxrC3bnPgMAADDnSvyZqQ.b['4'][0]++;__cov_VkxrC3bnPgMAADDnSvyZqQ.s['29']++;errors.push('availability_examus:error_setduration');}else{__cov_VkxrC3bnPgMAADDnSvyZqQ.b['4'][1]++;}};},'@VERSION@',{'requires':['base','node','event','moodle-core_availability-form']}); diff --git a/yui/build/moodle-availability_examus-form/moodle-availability_examus-form-debug.js b/yui/build/moodle-availability_examus-form/moodle-availability_examus-form-debug.js index 1ed0ca0..88288f1 100644 --- a/yui/build/moodle-availability_examus-form/moodle-availability_examus-form-debug.js +++ b/yui/build/moodle-availability_examus-form/moodle-availability_examus-form-debug.js @@ -10,26 +10,50 @@ M.availability_examus = M.availability_examus || {}; M.availability_examus.form = Y.Object(M.core_availability.plugin); -// M.availability_examus.form.initInner = function(param) { -// // The 'param' variable is the parameter passed through from PHP (you -// // can have more than one if required). -// -// // Using the PHP code above it'll show 'The param was: frog'. -// console.log('The param was: ' + param); -// }; +M.availability_examus.form.initInner = function() { + // Nothing +}; + +M.availability_examus.form.instId = 1; M.availability_examus.form.getNode = function(json) { - var strings = M.str.availability_examus; - var html = ''; - var node = Y.Node.create(' ' + html + ' '); + var html, node, root, id, strings; + strings = M.str.availability_examus; + + id = 'examus' + M.availability_examus.form.instId; + M.availability_examus.form.instId += 1; + + html = '
'; + html += ''; + html += ''; + node = Y.Node.create(' ' + html + ' '); + if (json.duration !== undefined) { + node.one('input[name=duration]').set('value', json.duration); + } + + if (!M.availability_examus.form.addedEvents) { + M.availability_examus.form.addedEvents = true; + root = Y.one('#fitem_id_availabilityconditionsjson'); + root.delegate('valuechange', function () { + // Trigger the updating of the hidden availability data whenever the password field changes. + M.core_availability.form.update(); + }, '.availability_examus input[name=duration]'); + } return node; }; M.availability_examus.form.fillValue = function(value, node) { + value.duration = node.one('input[name=duration').get('value').trim(); }; M.availability_examus.form.fillErrors = function(errors, node) { + var value = {}; + this.fillValue(value, node); + + if (value.duration === undefined || !/^\d+$/.test(value.duration)) { + errors.push('availability_examus:error_setduration'); + } }; }, '@VERSION@', {"requires": ["base", "node", "event", "moodle-core_availability-form"]}); diff --git a/yui/build/moodle-availability_examus-form/moodle-availability_examus-form-min.js b/yui/build/moodle-availability_examus-form/moodle-availability_examus-form-min.js index 8938282..0713fad 100644 --- a/yui/build/moodle-availability_examus-form/moodle-availability_examus-form-min.js +++ b/yui/build/moodle-availability_examus-form/moodle-availability_examus-form-min.js @@ -1 +1 @@ -YUI.add("moodle-availability_examus-form",function(e,t){M.availability_examus=M.availability_examus||{},M.availability_examus.form=e.Object(M.core_availability.plugin),M.availability_examus.form.getNode=function(t){var n=M.str.availability_examus,r="",i=e.Node.create(" "+r+" ");return i},M.availability_examus.form.fillValue=function(e,t){},M.availability_examus.form.fillErrors=function(e,t){}},"@VERSION@",{requires:["base","node","event","moodle-core_availability-form"]}); +YUI.add("moodle-availability_examus-form",function(e,t){M.availability_examus=M.availability_examus||{},M.availability_examus.form=e.Object(M.core_availability.plugin),M.availability_examus.form.initInner=function(){},M.availability_examus.form.instId=1,M.availability_examus.form.getNode=function(t){var n,r,i,s,o;return o=M.str.availability_examus,s="examus"+M.availability_examus.form.instId,M.availability_examus.form.instId+=1,n="
",n+='",n+='',r=e.Node.create(" "+n+" "),t.duration!==undefined&&r.one("input[name=duration]").set("value",t.duration),M.availability_examus.form.addedEvents||(M.availability_examus.form.addedEvents=!0,i=e.one("#fitem_id_availabilityconditionsjson"),i.delegate("valuechange",function(){M.core_availability.form.update()},".availability_examus input[name=duration]")),r},M.availability_examus.form.fillValue=function(e,t){e.duration=t.one("input[name=duration").get("value").trim()},M.availability_examus.form.fillErrors=function(e,t){var n={};this.fillValue(n,t),(n.duration===undefined||!/^\d+$/.test(n.duration))&&e.push("availability_examus:error_setduration")}},"@VERSION@",{requires:["base","node","event","moodle-core_availability-form"]}); diff --git a/yui/build/moodle-availability_examus-form/moodle-availability_examus-form.js b/yui/build/moodle-availability_examus-form/moodle-availability_examus-form.js index 1ed0ca0..88288f1 100644 --- a/yui/build/moodle-availability_examus-form/moodle-availability_examus-form.js +++ b/yui/build/moodle-availability_examus-form/moodle-availability_examus-form.js @@ -10,26 +10,50 @@ M.availability_examus = M.availability_examus || {}; M.availability_examus.form = Y.Object(M.core_availability.plugin); -// M.availability_examus.form.initInner = function(param) { -// // The 'param' variable is the parameter passed through from PHP (you -// // can have more than one if required). -// -// // Using the PHP code above it'll show 'The param was: frog'. -// console.log('The param was: ' + param); -// }; +M.availability_examus.form.initInner = function() { + // Nothing +}; + +M.availability_examus.form.instId = 1; M.availability_examus.form.getNode = function(json) { - var strings = M.str.availability_examus; - var html = ''; - var node = Y.Node.create(' ' + html + ' '); + var html, node, root, id, strings; + strings = M.str.availability_examus; + + id = 'examus' + M.availability_examus.form.instId; + M.availability_examus.form.instId += 1; + + html = '
'; + html += ''; + html += ''; + node = Y.Node.create(' ' + html + ' '); + if (json.duration !== undefined) { + node.one('input[name=duration]').set('value', json.duration); + } + + if (!M.availability_examus.form.addedEvents) { + M.availability_examus.form.addedEvents = true; + root = Y.one('#fitem_id_availabilityconditionsjson'); + root.delegate('valuechange', function () { + // Trigger the updating of the hidden availability data whenever the password field changes. + M.core_availability.form.update(); + }, '.availability_examus input[name=duration]'); + } return node; }; M.availability_examus.form.fillValue = function(value, node) { + value.duration = node.one('input[name=duration').get('value').trim(); }; M.availability_examus.form.fillErrors = function(errors, node) { + var value = {}; + this.fillValue(value, node); + + if (value.duration === undefined || !/^\d+$/.test(value.duration)) { + errors.push('availability_examus:error_setduration'); + } }; }, '@VERSION@', {"requires": ["base", "node", "event", "moodle-core_availability-form"]}); diff --git a/yui/src/form/js/form.js b/yui/src/form/js/form.js index 8b6b340..630a4cd 100644 --- a/yui/src/form/js/form.js +++ b/yui/src/form/js/form.js @@ -8,24 +8,48 @@ M.availability_examus = M.availability_examus || {}; M.availability_examus.form = Y.Object(M.core_availability.plugin); -// M.availability_examus.form.initInner = function(param) { -// // The 'param' variable is the parameter passed through from PHP (you -// // can have more than one if required). -// -// // Using the PHP code above it'll show 'The param was: frog'. -// console.log('The param was: ' + param); -// }; +M.availability_examus.form.initInner = function() { + // Nothing +}; + +M.availability_examus.form.instId = 1; M.availability_examus.form.getNode = function(json) { - var strings = M.str.availability_examus; - var html = ''; - var node = Y.Node.create(' ' + html + ' '); + var html, node, root, id, strings; + strings = M.str.availability_examus; + + id = 'examus' + M.availability_examus.form.instId; + M.availability_examus.form.instId += 1; + + html = '
'; + html += ''; + html += ''; + node = Y.Node.create(' ' + html + ' '); + if (json.duration !== undefined) { + node.one('input[name=duration]').set('value', json.duration); + } + + if (!M.availability_examus.form.addedEvents) { + M.availability_examus.form.addedEvents = true; + root = Y.one('#fitem_id_availabilityconditionsjson'); + root.delegate('valuechange', function () { + // Trigger the updating of the hidden availability data whenever the password field changes. + M.core_availability.form.update(); + }, '.availability_examus input[name=duration]'); + } return node; }; M.availability_examus.form.fillValue = function(value, node) { + value.duration = node.one('input[name=duration').get('value').trim(); }; M.availability_examus.form.fillErrors = function(errors, node) { + var value = {}; + this.fillValue(value, node); + + if (value.duration === undefined || !/^\d+$/.test(value.duration)) { + errors.push('availability_examus:error_setduration'); + } }; \ No newline at end of file