mirrored from git://git.moodle.org/moodle.git
/
toolboxes.js
800 lines (711 loc) · 28.7 KB
/
toolboxes.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
YUI.add('moodle-course-toolboxes', function(Y) {
WAITICON = {'pix':"i/loading_small",'component':'moodle'};
// The CSS selectors we use
var CSS = {
ACTIVITYLI : 'li.activity',
COMMANDSPAN : 'li.activity span.commands',
SPINNERCOMMANDSPAN : 'span.commands',
CONTENTAFTERLINK : 'div.contentafterlink',
DELETE : 'a.editing_delete',
DIMCLASS : 'dimmed',
DIMMEDTEXT : 'dimmed_text',
EDITTITLE : 'a.editing_title',
EDITTITLECLASS : 'edittitle',
GENERICICONCLASS : 'iconsmall',
GROUPSNONE : 'a.editing_groupsnone',
GROUPSSEPARATE : 'a.editing_groupsseparate',
GROUPSVISIBLE : 'a.editing_groupsvisible',
HASLABEL : 'label',
HIDE : 'a.editing_hide',
HIGHLIGHT : 'a.editing_highlight',
INSTANCENAME : 'span.instancename',
LIGHTBOX : 'lightbox',
MODINDENTCOUNT : 'mod-indent-',
MODINDENTDIV : 'div.mod-indent',
MODINDENTHUGE : 'mod-indent-huge',
MODULEIDPREFIX : 'module-',
MOVELEFT : 'a.editing_moveleft',
MOVELEFTCLASS : 'editing_moveleft',
MOVERIGHT : 'a.editing_moveright',
PAGECONTENT : 'div#page-content',
RIGHTDIV : 'div.right',
SECTIONHIDDENCLASS : 'hidden',
SECTIONIDPREFIX : 'section-',
SECTIONLI : 'li.section',
SHOW : 'a.editing_show',
SHOWHIDE : 'a.editing_showhide'
};
/**
* The toolbox classes
*
* TOOLBOX is a generic class which should never be directly instantiated
* RESOURCETOOLBOX is a class extending TOOLBOX containing code specific to resources
* SECTIONTOOLBOX is a class extending TOOLBOX containing code specific to sections
*/
var TOOLBOX = function() {
TOOLBOX.superclass.constructor.apply(this, arguments);
}
Y.extend(TOOLBOX, Y.Base, {
/**
* Replace the button click at the selector with the specified
* callback
*
* @param toolboxtarget The selector of the working area
* @param selector The 'button' to replace
* @param callback The callback to apply
* @param cursor An optional cursor style to apply
*/
replace_button : function(toolboxtarget, selector, callback, cursor) {
if (!cursor) {
// Set the default cursor type to pointer to match the
// anchor
cursor = 'pointer';
}
var button = Y.one(toolboxtarget).all(selector)
.setStyle('cursor', cursor);
// on isn't chainable and will return an event
button.on('click', callback, this);
return button;
},
/**
* Toggle the visibility and availability for the specified
* resource show/hide button
*/
toggle_hide_resource_ui : function(button) {
var element = button.ancestor(CSS.ACTIVITYLI);
var hideicon = button.one('img');
var dimarea;
var toggle_class;
if (this.is_label(element)) {
toggle_class = CSS.DIMMEDTEXT;
dimarea = element.one(CSS.MODINDENTDIV + ' div');
} else {
toggle_class = CSS.DIMCLASS;
dimarea = element.one('a');
}
var status = '';
var value;
if (dimarea.hasClass(toggle_class)) {
status = 'hide';
value = 1;
} else {
status = 'show';
value = 0;
}
// Change the UI
dimarea.toggleClass(toggle_class);
// We need to toggle dimming on the description too
element.all(CSS.CONTENTAFTERLINK).toggleClass(CSS.DIMMEDTEXT);
var newstring = M.util.get_string(status, 'moodle');
hideicon.setAttrs({
'alt' : newstring,
'title' : newstring,
'src' : M.util.image_url('t/' + status)
});
button.set('title', newstring);
button.set('className', 'editing_'+status);
return value;
},
/**
* Send a request using the REST API
*
* @param data The data to submit
* @param statusspinner (optional) A statusspinner which may contain a section loader
* @param optionalconfig (optional) Any additional configuration to submit
* @return response responseText field from responce
*/
send_request : function(data, statusspinner, optionalconfig) {
// Default data structure
if (!data) {
data = {};
}
// Handle any variables which we must pass back through to
var pageparams = this.get('config').pageparams;
for (varname in pageparams) {
data[varname] = pageparams[varname];
}
data.sesskey = M.cfg.sesskey;
data.courseId = this.get('courseid');
var uri = M.cfg.wwwroot + this.get('ajaxurl');
// Define the configuration to send with the request
var responsetext = [];
var config = {
method: 'POST',
data: data,
on: {
success: function(tid, response) {
try {
responsetext = Y.JSON.parse(response.responseText);
if (responsetext.error) {
new M.core.ajaxException(responsetext);
}
} catch (e) {}
if (statusspinner) {
window.setTimeout(function(e) {
statusspinner.hide();
}, 400);
}
},
failure : function(tid, response) {
if (statusspinner) {
statusspinner.hide();
}
new M.core.ajaxException(response);
}
},
context: this,
sync: true
}
// Apply optional config
if (optionalconfig) {
for (varname in optionalconfig) {
config[varname] = optionalconfig[varname];
}
}
if (statusspinner) {
statusspinner.show();
}
// Send the request
Y.io(uri, config);
return responsetext;
},
is_label : function(target) {
return target.hasClass(CSS.HASLABEL);
},
/**
* Return the module ID for the specified element
*
* @param element The <li> element to determine a module-id number for
* @return string The module ID
*/
get_element_id : function(element) {
return element.get('id').replace(CSS.MODULEIDPREFIX, '');
},
/**
* Return the module ID for the specified element
*
* @param element The <li> element to determine a module-id number for
* @return string The module ID
*/
get_section_id : function(section) {
return section.get('id').replace(CSS.SECTIONIDPREFIX, '');
}
},
{
NAME : 'course-toolbox',
ATTRS : {
// The ID of the current course
courseid : {
'value' : 0
},
ajaxurl : {
'value' : 0
},
config : {
'value' : 0
}
}
}
);
var RESOURCETOOLBOX = function() {
RESOURCETOOLBOX.superclass.constructor.apply(this, arguments);
}
Y.extend(RESOURCETOOLBOX, TOOLBOX, {
// Variables
GROUPS_NONE : 0,
GROUPS_SEPARATE : 1,
GROUPS_VISIBLE : 2,
/**
* Initialize the resource toolbox
*
* Updates all span.commands with relevant handlers and other required changes
*/
initializer : function(config) {
this.setup_for_resource();
M.course.coursebase.register_module(this);
},
/**
* Update any span.commands within the scope of the specified
* selector with AJAX equivelants
*
* @param baseselector The selector to limit scope to
* @return void
*/
setup_for_resource : function(baseselector) {
if (!baseselector) {
var baseselector = CSS.PAGECONTENT;
}
Y.all(baseselector).each(this._setup_for_resource, this);
},
_setup_for_resource : function(toolboxtarget) {
// Edit Title
this.replace_button(toolboxtarget, CSS.COMMANDSPAN + ' ' + CSS.EDITTITLE, this.edit_resource_title);
// Move left and right
this.replace_button(toolboxtarget, CSS.COMMANDSPAN + ' ' + CSS.MOVELEFT, this.move_left);
this.replace_button(toolboxtarget, CSS.COMMANDSPAN + ' ' + CSS.MOVERIGHT, this.move_right);
// Delete
this.replace_button(toolboxtarget, CSS.COMMANDSPAN + ' ' + CSS.DELETE, this.delete_resource);
// Show/Hide
var showhide = this.replace_button(toolboxtarget, CSS.COMMANDSPAN + ' ' + CSS.HIDE, this.toggle_hide_resource);
var shown = this.replace_button(toolboxtarget, CSS.COMMANDSPAN + ' ' + CSS.SHOW, this.toggle_hide_resource);
showhide = showhide.concat(shown);
showhide.each(function(node) {
var section = node.ancestor(CSS.SECTIONLI);
if (section && section.hasClass(CSS.SECTIONHIDDENCLASS)) {
node.setStyle('cursor', 'auto');
}
});
// Change Group Mode
var groups;
groups = this.replace_button(toolboxtarget, CSS.COMMANDSPAN + ' ' + CSS.GROUPSNONE, this.toggle_groupmode);
groups.setAttribute('groupmode', this.GROUPS_NONE);
groups = this.replace_button(toolboxtarget, CSS.COMMANDSPAN + ' ' + CSS.GROUPSSEPARATE, this.toggle_groupmode);
groups.setAttribute('groupmode', this.GROUPS_SEPARATE);
groups = this.replace_button(toolboxtarget, CSS.COMMANDSPAN + ' ' + CSS.GROUPSVISIBLE, this.toggle_groupmode);
groups.setAttribute('groupmode', this.GROUPS_VISIBLE);
},
move_left : function(e) {
this.move_leftright(e, -1);
},
move_right : function(e) {
this.move_leftright(e, 1);
},
move_leftright : function(e, direction) {
// Prevent the default button action
e.preventDefault();
// Get the element we're working on
var element = e.target.ancestor(CSS.ACTIVITYLI);
// And we need to determine the current and new indent level
var indentdiv = element.one(CSS.MODINDENTDIV);
var indent = indentdiv.getAttribute('class').match(/mod-indent-(\d{1,})/);
if (indent) {
var oldindent = parseInt(indent[1]);
var newindent = Math.max(0, (oldindent + parseInt(direction)));
indentdiv.removeClass(indent[0]);
} else {
var oldindent = 0;
var newindent = 1;
}
// Perform the move
indentdiv.addClass(CSS.MODINDENTCOUNT + newindent);
var data = {
'class' : 'resource',
'field' : 'indent',
'value' : newindent,
'id' : this.get_element_id(element)
};
var spinner = M.util.add_spinner(Y, element.one(CSS.SPINNERCOMMANDSPAN));
this.send_request(data, spinner);
// Handle removal/addition of the moveleft button
if (newindent == 0) {
element.one(CSS.MOVELEFT).remove();
} else if (newindent == 1 && oldindent == 0) {
this.add_moveleft(element);
}
// Handle massive indentation to match non-ajax display
var hashugeclass = indentdiv.hasClass(CSS.MODINDENTHUGE);
if (newindent > 15 && !hashugeclass) {
indentdiv.addClass(CSS.MODINDENTHUGE);
} else if (newindent <= 15 && hashugeclass) {
indentdiv.removeClass(CSS.MODINDENTHUGE);
}
},
delete_resource : function(e) {
// Prevent the default button action
e.preventDefault();
// Get the element we're working on
var element = e.target.ancestor(CSS.ACTIVITYLI);
var confirmstring = '';
if (this.is_label(element)) {
// Labels are slightly different to other activities
var plugindata = {
type : M.util.get_string('pluginname', 'label')
}
confirmstring = M.util.get_string('deletechecktype', 'moodle', plugindata)
} else {
var plugindata = {
type : M.util.get_string('pluginname', element.getAttribute('class').match(/modtype_([^\s]*)/)[1]),
name : element.one(CSS.INSTANCENAME).get('firstChild').get('data')
}
confirmstring = M.util.get_string('deletechecktypename', 'moodle', plugindata);
}
// Confirm element removal
if (!confirm(confirmstring)) {
return false;
}
// Actually remove the element
element.remove();
var data = {
'class' : 'resource',
'action' : 'DELETE',
'id' : this.get_element_id(element)
};
this.send_request(data);
},
toggle_hide_resource : function(e) {
// Prevent the default button action
e.preventDefault();
// Return early if the current section is hidden
var section = e.target.ancestor(CSS.SECTIONLI);
if (section && section.hasClass(CSS.SECTIONHIDDENCLASS)) {
return;
}
// Get the element we're working on
var element = e.target.ancestor(CSS.ACTIVITYLI);
var button = e.target.ancestor('a', true);
var value = this.toggle_hide_resource_ui(button);
// Send the request
var data = {
'class' : 'resource',
'field' : 'visible',
'value' : value,
'id' : this.get_element_id(element)
};
var spinner = M.util.add_spinner(Y, element.one(CSS.SPINNERCOMMANDSPAN));
this.send_request(data, spinner);
},
toggle_groupmode : function(e) {
// Prevent the default button action
e.preventDefault();
// Get the element we're working on
var element = e.target.ancestor(CSS.ACTIVITYLI);
var button = e.target.ancestor('a', true);
var icon = button.one('img');
// Current Mode
var groupmode = button.getAttribute('groupmode');
groupmode++;
if (groupmode > 2) {
groupmode = 0;
}
button.setAttribute('groupmode', groupmode);
var newtitle = '';
var iconsrc = '';
switch (groupmode) {
case this.GROUPS_NONE:
newtitle = 'groupsnone';
iconsrc = M.util.image_url('t/groupn');
break;
case this.GROUPS_SEPARATE:
newtitle = 'groupsseparate';
iconsrc = M.util.image_url('t/groups');
break;
case this.GROUPS_VISIBLE:
newtitle = 'groupsvisible';
iconsrc = M.util.image_url('t/groupv');
break;
}
newtitle = M.util.get_string('clicktochangeinbrackets', 'moodle',
M.util.get_string(newtitle, 'moodle'));
// Change the UI
icon.setAttrs({
'alt' : newtitle,
'title' : newtitle,
'src' : iconsrc
});
button.setAttribute('title', newtitle);
// And send the request
var data = {
'class' : 'resource',
'field' : 'groupmode',
'value' : groupmode,
'id' : this.get_element_id(element)
};
var spinner = M.util.add_spinner(Y, element.one(CSS.SPINNERCOMMANDSPAN));
this.send_request(data, spinner);
},
/**
* Add the moveleft button
* This is required after moving left from an initial position of 0
*
* @param target The encapsulating <li> element
*/
add_moveleft : function(target) {
var left_string = M.util.get_string('moveleft', 'moodle');
var newicon = Y.Node.create('<img />')
.addClass(CSS.GENERICICONCLASS)
.setAttrs({
'src' : M.util.image_url('t/left', 'moodle'),
'title' : left_string,
'alt' : left_string
});
var moveright = target.one(CSS.MOVERIGHT);
var newlink = moveright.getAttribute('href').replace('indent=1', 'indent=-1');
var anchor = new Y.Node.create('<a />')
.setStyle('cursor', 'pointer')
.addClass(CSS.MOVELEFTCLASS)
.setAttribute('href', newlink)
.setAttribute('title', left_string);
anchor.appendChild(newicon);
anchor.on('click', this.move_left, this);
moveright.insert(anchor, 'before');
},
/**
* Edit the title for the resource
*/
edit_resource_title : function(e) {
// Get the element we're working on
var element = e.target.ancestor(CSS.ACTIVITYLI);
var instancename = element.one(CSS.INSTANCENAME);
var currenttitle = instancename.get('firstChild');
var oldtitle = currenttitle.get('data');
var titletext = oldtitle;
var editbutton = element.one('a.' + CSS.EDITTITLECLASS + ' img');
// Handle events for edit_resource_title
var listenevents = [];
var thisevent;
// Grab the anchor so that we can swap it with the edit form
var anchor = instancename.ancestor('a');
var data = {
'class' : 'resource',
'field' : 'gettitle',
'id' : this.get_element_id(element)
};
// Try to retrieve the existing string from the server
var response = this.send_request(data, editbutton);
if (response.instancename) {
titletext = response.instancename;
}
// Create the editor and submit button
var editor = Y.Node.create('<input />')
.setAttrs({
'name' : 'title',
'value' : titletext,
'autocomplete' : 'off'
})
.addClass('titleeditor');
var editform = Y.Node.create('<form />')
.setStyle('padding', '0')
.setStyle('display', 'inline')
.setAttribute('action', '#');
var editinstructions = Y.Node.create('<span />')
.addClass('editinstructions')
.set('innerHTML', M.util.get_string('edittitleinstructions', 'moodle'));
// Clear the existing content and put the editor in
currenttitle.set('data', '');
editform.appendChild(editor);
anchor.replace(editform);
element.appendChild(editinstructions);
e.preventDefault();
// Focus and select the editor text
editor.focus().select();
// Handle removal of the editor
var clear_edittitle = function() {
// Detach all listen events to prevent duplicate triggers
var thisevent;
while (thisevent = listenevents.shift()) {
thisevent.detach();
}
if (editinstructions) {
// Convert back to anchor and remove instructions
editform.replace(anchor);
editinstructions.remove();
editinstructions = null;
}
}
// Handle cancellation of the editor
var cancel_edittitle = function(e) {
clear_edittitle();
// Set the title and anchor back to their previous settings
currenttitle.set('data', oldtitle);
};
// Cancel the edit if we lose focus or the escape key is pressed
thisevent = editor.on('blur', cancel_edittitle);
listenevents.push(thisevent);
thisevent = Y.one('document').on('keyup', function(e) {
if (e.keyCode == 27) {
cancel_edittitle(e);
}
});
listenevents.push(thisevent);
// Handle form submission
thisevent = editform.on('submit', function(e) {
// We don't actually want to submit anything
e.preventDefault();
// Clear the edit title boxes
clear_edittitle();
// We only accept strings which have valid content
var newtitle = Y.Lang.trim(editor.get('value'));
if (newtitle != null && newtitle != "" && newtitle != titletext) {
var data = {
'class' : 'resource',
'field' : 'updatetitle',
'title' : newtitle,
'id' : this.get_element_id(element)
};
var response = this.send_request(data, editbutton);
if (response.instancename) {
currenttitle.set('data', response.instancename);
}
} else {
// Invalid content. Set the title back to it's original contents
currenttitle.set('data', oldtitle);
}
}, this);
listenevents.push(thisevent);
}
}, {
NAME : 'course-resource-toolbox',
ATTRS : {
courseid : {
'value' : 0
},
format : {
'value' : 'topics'
}
}
});
var SECTIONTOOLBOX = function() {
SECTIONTOOLBOX.superclass.constructor.apply(this, arguments);
}
Y.extend(SECTIONTOOLBOX, TOOLBOX, {
/**
* Initialize the toolboxes module
*
* Updates all span.commands with relevant handlers and other required changes
*/
initializer : function(config) {
this.setup_for_section();
M.course.coursebase.register_module(this);
},
/**
* Update any section areas within the scope of the specified
* selector with AJAX equivelants
*
* @param baseselector The selector to limit scope to
* @return void
*/
setup_for_section : function(baseselector) {
if (!baseselector) {
var baseselector = CSS.PAGECONTENT;
}
Y.all(baseselector).each(this._setup_for_section, this);
},
_setup_for_section : function(toolboxtarget) {
// Section Highlighting
this.replace_button(toolboxtarget, CSS.RIGHTDIV + ' ' + CSS.HIGHLIGHT, this.toggle_highlight);
// Section Visibility
this.replace_button(toolboxtarget, CSS.RIGHTDIV + ' ' + CSS.SHOWHIDE, this.toggle_hide_section);
},
toggle_hide_section : function(e) {
// Prevent the default button action
e.preventDefault();
// Get the section we're working on
var section = e.target.ancestor(CSS.SECTIONLI);
var button = e.target.ancestor('a', true);
var hideicon = button.one('img');
// The value to submit
var value;
// The status text for strings and images
var status;
if (!section.hasClass(CSS.SECTIONHIDDENCLASS)) {
section.addClass(CSS.SECTIONHIDDENCLASS);
value = 0;
status = 'show';
} else {
section.removeClass(CSS.SECTIONHIDDENCLASS);
value = 1;
status = 'hide';
}
var newstring = M.util.get_string(status + 'fromothers', 'format_' + this.get('format'));
hideicon.setAttrs({
'alt' : newstring,
'title' : newstring,
'src' : M.util.image_url('i/' + status)
});
button.set('title', newstring);
// Change the highlight status
var data = {
'class' : 'section',
'field' : 'visible',
'id' : this.get_section_id(section),
'value' : value
};
var lightbox = M.util.add_lightbox(Y, section);
lightbox.show();
var response = this.send_request(data, lightbox);
var activities = section.all(CSS.ACTIVITYLI);
activities.each(function(node) {
if (node.one(CSS.SHOW)) {
var button = node.one(CSS.SHOW);
} else {
var button = node.one(CSS.HIDE);
}
var activityid = this.get_element_id(node);
if (Y.Array.indexOf(response.resourcestotoggle, activityid) != -1) {
this.toggle_hide_resource_ui(button);
}
if (value == 0) {
button.setStyle('cursor', 'auto');
} else {
button.setStyle('cursor', 'pointer');
}
}, this);
},
toggle_highlight : function(e) {
// Prevent the default button action
e.preventDefault();
// Get the section we're working on
var section = e.target.ancestor(CSS.SECTIONLI);
var button = e.target.ancestor('a', true);
var buttonicon = button.one('img');
// Determine whether the marker is currently set
var togglestatus = section.hasClass('current');
var value = 0;
// Set the current highlighted item text
var old_string = M.util.get_string('markthistopic', 'moodle');
Y.one(CSS.PAGECONTENT)
.all(CSS.SECTIONLI + '.current ' + CSS.HIGHLIGHT)
.set('title', old_string);
Y.one(CSS.PAGECONTENT)
.all(CSS.SECTIONLI + '.current ' + CSS.HIGHLIGHT + ' img')
.set('title', old_string)
.set('alt', old_string)
.set('src', M.util.image_url('i/marker'));
// Remove the highlighting from all sections
var allsections = Y.one(CSS.PAGECONTENT).all(CSS.SECTIONLI)
.removeClass('current');
// Then add it if required to the selected section
if (!togglestatus) {
section.addClass('current');
value = this.get_section_id(section);
var new_string = M.util.get_string('markedthistopic', 'moodle');
button
.set('title', new_string);
buttonicon
.set('title', new_string)
.set('alt', new_string)
.set('src', M.util.image_url('i/marked'));
}
// Change the highlight status
var data = {
'class' : 'course',
'field' : 'marker',
'value' : value
};
var lightbox = M.util.add_lightbox(Y, section);
lightbox.show();
this.send_request(data, lightbox);
}
}, {
NAME : 'course-section-toolbox',
ATTRS : {
courseid : {
'value' : 0
},
format : {
'value' : 'topics'
}
}
});
M.course = M.course || {};
M.course.init_resource_toolbox = function(config) {
return new RESOURCETOOLBOX(config);
};
M.course.init_section_toolbox = function(config) {
return new SECTIONTOOLBOX(config);
};
},
'@VERSION@', {
requires : ['base', 'node', 'io', 'moodle-course-coursebase']
}
);