Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
 
2
// This file is part of Moodle - http://moodle.org/
3
//
4
// Moodle is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8
//
9
// Moodle is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13
//
14
// You should have received a copy of the GNU General Public License
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
16
 
17
/**
18
 * JavaScript for the drag'n'drop functionnality.
19
 *
20
 * @package   mod_stickynotes
21
 * @copyright 2021 Sébastien Mehr <sebmehr.fr>
22
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
24
 
25
import Sortable from 'sortablejs';
26
import * as Ajax from 'core/ajax';
27
 
28
export const init = () => {
29
    window.console.log('we have been started');
30
 
31
    var columnnotes = document.getElementsByClassName('columnnote');
32
 
33
    Array.from(columnnotes).forEach((column) => {
34
        // Do stuff here
35
        var sortable = Sortable.create(column, {
36
            group: "columnnote",
37
            draggable: ".stickynotemod",
38
            pull: "true",
39
 
40
            onEnd: function (/**Event*/evt) {
41
 
42
                if ((evt.from === evt.to) && (evt.oldDraggableIndex === evt.newDraggableIndex)) {
43
                    return;
44
                 } else {
45
                    var noteid = parseInt(evt.item.id.replace('element', '').replace('container', ''));
46
                    var oldcolumnid = parseInt(evt.from.id.replace('column', ''));
47
                    var newcolumnid = parseInt(evt.to.id.replace('column', ''));
48
                    var oldindex = evt.oldDraggableIndex + 1;
49
                    var newindex = evt.newDraggableIndex + 1;
50
                    var promise = Ajax.call([{
51
                        methodname: 'mod_stickynotes_changing_note_position',
52
                        args: { noteid: noteid,
53
                                oldcolumnid: oldcolumnid,
54
                                newcolumnid: newcolumnid,
55
                                oldindex: oldindex,
56
                                newindex: newindex
57
                            },
58
                    }]);
59
                    promise[0].done(function(response) {
60
                        window.console.log('mod_stickynotes/dragndrop success' + JSON.stringify(response));
61
                    }).fail(function(ex) {
62
                        window.console.log('mod_stickynotes/dragndrop erreur' + JSON.stringify(ex));
63
                    });
64
                }
65
            },
66
        });
67
    });
68
 };