Proyectos de Subversion Moodle

Rev

Rev 1 | Rev 739 | Ir a la última revisión | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
365 ariadna 1
define([
2
  "jquery",
3
  "core/yui",
4
  "core/str",
5
  "core/config",
6
  "core/notification",
7
  "core/modal_factory",
8
], function ($, Y, str, config, notification, ModalFactory) {
9
  var CONFIG;
10
  var NODES = {
11
    DELETE_ICON: '<span class="delete">&#x274C;</span>',
12
  };
13
  var SELECTORS = {
14
    cesa_notes_BASE: "#cesa_notes_base",
15
    cesa_notes_OPENER: ".cesa_notes-opener",
16
    cesa_notes_LISTS: ".cesa_notes_list",
17
  };
18
  var CSS = {
19
    cesa_notes_BASE: "cesa_notes_base",
20
    cesa_notes_OPENER: "cesa_notes-opener",
21
    cesa_notes_LISTS: "cesa_notes_list",
22
  };
23
  var panel = null;
24
  var initnotes = null;
25
  var strdeletenote = M.util.get_string("deletecesa_notes", "block_cesa_notes");
26
 
27
  var getcesa_notesValidatedUrl = function (baseurl) {
28
    var a = document.createElement("a");
29
    a.href = baseurl;
30
    return a.search.length > 0 ? baseurl : baseurl + "?";
31
  };
32
 
33
  var cesa_notes = {
34
    /** @alias module:blocks/cesa_notes */
35
 
36
    getcesa_notesValidatedUrl: function (baseurl) {
37
      var a = document.createElement("a");
38
      a.href = baseurl;
39
      return a.search.length > 0 ? baseurl : baseurl + "?";
40
    },
41
    /*
42
     * Validation for textarea input text
43
     */
44
    getWarnings: function (status) {
45
      if (status == false) {
46
        $("#addmynote-label-" + CONFIG.instanceid + "  span.warning").html(
47
          CONFIG.maxallowedcharacters_warning
48
        );
49
      } else {
50
        var ta = $("#id_mynotecontent-" + CONFIG.instanceid);
51
        if (ta.val() == "") {
52
          $("#addmynote-label-" + CONFIG.instanceid + "  span.warning").html(
53
            ""
54
          );
55
        } else {
56
          var cl = CONFIG.maxallowedcharacters - ta.val().length;
57
          $("#addmynote-label-" + CONFIG.instanceid + "  span.warning").html(
58
            M.util.get_string("charactersleft", "block_cesa_notes") + cl
59
          );
60
        }
61
      }
62
    },
63
    checkInputText: function () {
64
      var ta = $("#id_mynotecontent-" + CONFIG.instanceid);
65
      if (ta.val().length <= CONFIG.maxallowedcharacters) {
66
        $("#addmynote_submit").removeAttr("disabled", "");
67
        return true;
68
      } else {
69
        $("#addmynote_submit").attr("disabled", "disabled");
70
        return false;
71
      }
72
      return true;
73
    },
74
    toggle_textarea: function (e) {
75
      var ta = $("#id_mynotecontent-" + CONFIG.instanceid);
76
 
77
      if (!ta) {
78
        return false;
79
      }
80
      var focus = e.type == "focusin";
81
      if (focus) {
82
        if (
83
          ta.val() ==
84
          M.util.get_string("placeholdercontent", "block_cesa_notes")
85
        ) {
86
          ta.val("");
87
          $(".textarea").css("border-color", "black");
88
        }
89
      } else {
90
        if (ta.val() == "") {
91
          ta.val(M.util.get_string("placeholdercontent", "block_cesa_notes"));
92
          $(".textarea").css("border-color", "gray");
93
          $("#addmynote-label-" + CONFIG.instanceid + "  span.warning").html(
94
            ""
95
          );
96
        }
97
      }
98
    },
99
    request: function (args) {
100
      var params = {};
101
      var scope = this;
102
      if (args["scope"]) {
103
        scope = args["scope"];
104
      }
105
      params["contextarea"] = scope.currenttab.replace(CONFIG.prefix, "");
106
      params["contextarea"] = params["contextarea"].replace("#", "");
107
      if (args.params) {
108
        for (i in args.params) {
109
          params[i] = args.params[i];
110
        }
111
      }
112
      params["sesskey"] = M.cfg.sesskey;
113
 
114
      var cfg = {
115
        method: "POST",
116
        on: {
117
          start: function () {
118
            //'<div class="mdl-align"><img src="'+M.util.image_url('i/loading', 'core')+'" /></div>';
119
          },
120
          complete: function (id, o, p) {
121
            if (!o) {
122
              alert("IO FATAL");
123
              return false;
1 efrain 124
            }
365 ariadna 125
            var data = Y.JSON.parse(o.responseText);
126
            if (data.error) {
127
              if (data.error == "require_login") {
128
                args.callback(id, data, p);
1 efrain 129
                return true;
365 ariadna 130
              }
131
              alert(data.error);
132
              return false;
1 efrain 133
            } else {
365 ariadna 134
              args.callback(id, data, p);
135
              return true;
1 efrain 136
            }
365 ariadna 137
          },
1 efrain 138
        },
365 ariadna 139
        arguments: {
140
          scope: scope,
1 efrain 141
        },
365 ariadna 142
        headers: {
143
          "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
1 efrain 144
        },
365 ariadna 145
        data: build_querystring(params),
146
      };
147
      if (args.form) {
148
        cfg.form = args.form;
149
      }
150
      Y.io(this.api, cfg);
151
    },
1 efrain 152
 
365 ariadna 153
    printcesa_notes: function (e) {
154
      e.preventDefault();
155
      let note_content_input = $("#id_mynotecontent-" + CONFIG.instanceid);
156
      let arg = {
157
        action: "print",
158
      };
1 efrain 159
 
365 ariadna 160
      note_content_input.attr("disabled", true);
161
      note_content_input.css({
162
        backgroundImage:
163
          "url(" + M.util.image_url("i/loading_small", "core") + ")",
164
        backgroundRepeat: "no-repeat",
165
        backgroundPosition: "center center",
166
      });
1 efrain 167
 
365 ariadna 168
      this.request({
169
        params: arg,
170
        callback: function (id, ret, args) {
171
          $("#id_mynotecontent-" + CONFIG.instanceid).removeAttr("disabled");
172
          $("#id_mynotecontent-" + CONFIG.instanceid).css({
173
            backgroundImage: "",
174
          });
1 efrain 175
        },
365 ariadna 176
      });
177
    },
1 efrain 178
 
365 ariadna 179
    savecesa_notes: function (e) {
180
      e.preventDefault();
181
      var scope = this;
1 efrain 182
 
365 ariadna 183
      if (scope.checkInputText() == false) {
184
        return false;
185
      }
186
      var ta = $("#id_mynotecontent-" + CONFIG.instanceid);
187
      if (
188
        ta.val() == "" ||
189
        ta.val() == M.util.get_string("placeholdercontent", "block_cesa_notes")
190
      ) {
191
        return false;
192
      }
193
      let editingNoteId = ta.attr("data-editnoteid")
194
        ? ta
195
            .attr("data-editnoteid")
196
            .replace("mynote-" + CONFIG.instanceid + "-", "")
197
        : false;
1 efrain 198
 
365 ariadna 199
      var arg = {
200
        contextid: CONFIG.contextid,
201
        content: ta.val(),
202
        action: editingNoteId ? "edit" : "add",
203
        contextarea: scope.currenttabindex,
204
        noteurl: window.location.href,
205
        noteToEditIt: editingNoteId,
206
      };
1 efrain 207
 
365 ariadna 208
      ta.attr("disabled", true);
209
      ta.css({
210
        backgroundImage:
211
          "url(" + M.util.image_url("i/loading_small", "core") + ")",
212
        backgroundRepeat: "no-repeat",
213
        backgroundPosition: "center center",
214
      });
215
      this.request({
216
        params: arg,
217
        callback: function (id, ret, args) {
218
          if (!ret.notes) {
219
            return false;
220
          }
221
 
222
          $("#addmynote-label-" + CONFIG.instanceid + "  span.warning").html(
223
            ""
224
          );
225
          $("#id_mynotecontent-" + CONFIG.instanceid).val(
226
            M.util.get_string("placeholdercontent", "block_cesa_notes")
227
          );
228
          $("#id_mynotecontent-" + CONFIG.instanceid).removeAttr("disabled");
229
          $("#id_mynotecontent-" + CONFIG.instanceid).css({
230
            backgroundImage: "",
231
          });
232
          if (scope.currenttab != scope.defaulttab) {
233
            scope.currenttab = scope.defaulttab;
234
            var tab = scope.currenttab.replace("#", "#tab-");
235
            $(SELECTORS.cesa_notes_BASE + " ul.tabs-menu li").removeClass(
236
              "current"
1 efrain 237
            );
365 ariadna 238
            $(SELECTORS.cesa_notes_BASE + " " + tab).addClass("current");
239
            $(SELECTORS.cesa_notes_BASE + " .tab-content")
240
              .has(scope.currenttab)
241
              .addClass("current");
242
            $(SELECTORS.cesa_notes_BASE + " .tab-content")
243
              .not(scope.currenttab)
244
              .css("display", "none");
245
            $(
246
              SELECTORS.cesa_notes_BASE +
247
                " " +
248
                scope.currenttab +
249
                ".tab-content"
250
            ).css("display", "block");
251
          }
252
          scope.addToList(ret, "add");
253
          scope.displaycesa_notes();
254
          $(SELECTORS.cesa_notes_BASE)
255
            .find(".responsetext")
256
            .html(M.util.get_string("savedsuccess", "block_cesa_notes"));
257
          $("#id_mynotecontent-" + CONFIG.instanceid).removeAttr(
258
            "data-editnoteid"
259
          );
260
 
261
          $(".j-delete-cesa-note").removeClass("show_delete_note_btn");
1 efrain 262
        },
365 ariadna 263
      });
264
    },
265
    addToList: function (notesobj, action = "") {
266
      var scope = this;
267
      var el = $(SELECTORS.cesa_notes_BASE).find(scope.currenttab + "-list");
268
      console.log(el);
269
      if (action == "add") {
270
        console.log(notesobj.notes);
271
        el.prepend(scope.rendercesa_notes(notesobj.notes));
272
      } else {
273
        el.append(scope.rendercesa_notes(notesobj.notes));
274
        $(el)
275
          .find("li")
276
          .sort(sort_li) // sort elements
277
          .appendTo(el); // append again to the list
278
        // sort function callback
279
        function sort_li(a, b) {
280
          return $(b).data("itemid") > $(a).data("itemid") ? 1 : -1;
281
        }
282
      }
283
      $(SELECTORS.cesa_notes_BASE)
284
        .find(scope.currenttab)
285
        .attr("notes-count", notesobj.count);
286
    },
287
    getcesa_notes: function (page = 0) {
288
      var scope = this;
289
      page = parseInt(page);
290
      var el = $(SELECTORS.cesa_notes_BASE).find(scope.currenttab + "-list");
291
      var notescount = el.find("li").length;
292
      var lastpage = Math.ceil(notescount / CONFIG.perpage);
293
      if (notescount > 0 && lastpage > page) {
294
        scope.displaycesa_notes();
295
        return false;
296
      }
297
      var arg = {
298
        contextid: CONFIG.contextid,
299
        action: "get",
300
        page: page,
301
      };
302
      this.request({
303
        params: arg,
304
        callback: function (id, ret, args) {
305
          scope.addToList(ret);
306
          scope.displaycesa_notes();
1 efrain 307
        },
365 ariadna 308
      });
309
    },
310
    updatecesa_notesInfo: function (cesa_notescount, page) {
311
      page = parseInt(page);
312
      cesa_notescount = parseInt(cesa_notescount);
313
      var scope = this;
314
      var paging = "";
315
      if (cesa_notescount > CONFIG.perpage) {
316
        var pagenum = page - 1;
317
        var prevlink = "";
318
        var nextlink = "";
1 efrain 319
 
365 ariadna 320
        if (page > 0) {
321
          prevlink = scope.createLink(
322
            pagenum,
323
            M.util.get_string("previouspage", "block_cesa_notes"),
324
            "previous"
325
          );
326
        }
327
        if (CONFIG.perpage > 0) {
328
          var lastpage = Math.ceil(cesa_notescount / CONFIG.perpage);
329
        } else {
330
          var lastpage = 1;
331
        }
332
        // Uncomment this line if you want to display page number
333
        //paging += '<span class="current-page">' + (page + 1) + '</span>';
334
        pagenum = page + 1;
335
        if (pagenum != lastpage) {
336
          nextlink = scope.createLink(
337
            pagenum,
338
            M.util.get_string("nextpage", "block_cesa_notes"),
339
            "next"
340
          );
341
        }
342
        paging = prevlink;
343
        if (prevlink != "" && nextlink != "") {
344
          paging += '<span class="separator"></span>';
345
        }
346
        paging += nextlink;
1 efrain 347
 
365 ariadna 348
        paging = '<span class="paging">' + paging + "</span>";
349
      }
350
      var noteinfo = $(SELECTORS.cesa_notes_BASE).find(scope.currenttab);
351
      if (cesa_notescount > 0) {
352
        noteinfo
353
          .find(".count")
354
          .html(
355
            M.util.get_string("cesa_notescount", "block_cesa_notes") +
356
              "" +
357
              cesa_notescount
358
          );
359
      } else {
360
        noteinfo
361
          .find(".count")
362
          .html(M.util.get_string("nothingtodisplay", "block_cesa_notes"));
363
      }
364
      noteinfo.find(".cesa_notes-paging").html(paging);
365
    },
366
    /*
367
     * Render notes as html ul li element
368
     */
369
    rendercesa_notes: function (notes) {
370
      if (notes.length < 1) {
371
        return false;
372
      }
373
      var lists = "";
374
      var x = "";
375
      for (x in notes) {
376
        $("#mynote-" + CONFIG.instanceid + "-" + notes[x].id).remove();
377
        var deletelink =
378
          '<a href="#" id="mynote-delete-' +
379
          CONFIG.instanceid +
380
          "-" +
381
          notes[x].id +
382
          '" class="mynote-delete" title="' +
383
          strdeletenote +
384
          '">' +
385
          NODES.DELETE_ICON +
386
          "</a>";
387
        var notedetail = "";
388
        var userdate = '<span class="time">' + notes[x].timecreated + "</span>";
389
        if (notes[x].coursename != "") {
390
          notedetail =
391
            '<div class="note-detail">' +
392
            notes[x].coursename +
393
            " - " +
394
            userdate +
395
            "</div>";
396
        } else {
397
          notedetail = '<div class="note-detail">' + userdate + "</div>";
398
        }
1 efrain 399
 
365 ariadna 400
        var note_html =
401
          '<div class="content" data-noteid="mynote-' +
402
          CONFIG.instanceid +
403
          "-" +
404
          notes[x].id +
405
          '">' +
406
          notes[x].content +
407
          "</div>";
408
        var note_edit_btn =
409
          '<button class="j-cesa-note-content-edit">Editar</button>';
410
        lists +=
411
          '<li id="mynote-' +
412
          CONFIG.instanceid +
413
          "-" +
414
          notes[x].id +
415
          '" data-itemid="' +
416
          notes[x].id +
417
          '">' +
418
          note_edit_btn +
419
          note_html +
420
          notedetail +
421
          "</li>";
422
      }
423
      return lists;
424
    },
425
    createLink: function (page, text, classname) {
426
      var classattribute =
427
        typeof classname != "undefined" ? ' class="' + classname + '"' : "";
428
      return (
429
        '<a href="' +
430
        this.api +
431
        "&page=" +
432
        page +
433
        '"' +
434
        classattribute +
435
        ">" +
436
        text +
437
        "</a>"
438
      );
439
    },
440
    displaycesa_notes: function () {
441
      var scope = this;
442
      var page = parseInt(
443
        $(SELECTORS.cesa_notes_BASE).find(scope.currenttab).attr("onpage")
444
      );
445
      var cesa_notescount = parseInt(
446
        $(SELECTORS.cesa_notes_BASE).find(scope.currenttab).attr("notes-count")
447
      );
448
      var el = $(SELECTORS.cesa_notes_BASE).find(
449
        " " + scope.currenttab + "-list"
450
      );
451
      var notescount = el.find("li").length;
452
      var lastpage = Math.ceil(notescount / CONFIG.perpage);
453
 
454
      if (notescount > 0 && lastpage <= page) {
455
        page = lastpage - 1;
456
      }
457
      var upperlimit = page * CONFIG.perpage + CONFIG.perpage;
458
      var lowerlimit = page * CONFIG.perpage;
459
      el.find("li").css("display", "none");
460
      el.find("li").each(function (i, el) {
461
        if (i >= lowerlimit && i < upperlimit) {
462
          $(el).css("display", "block");
463
        }
464
      });
465
      scope.updatecesa_notesInfo(cesa_notescount, page);
466
      //panel.centerDialogue();
467
    },
468
    registerActions: function () {
469
      var scope = this;
470
 
471
      $("body").delegate("#addmynote_cancel", "click", function () {
472
        panel.hide();
473
      });
474
 
475
      $("body").delegate(".j-cesa-note-content-edit", "click", function () {
476
        let noteText = $(this).parent().find(".text_to_html").text();
477
        let textArea = $(".cesa_notes_base .textarea textarea");
478
        let deleteButton = $(".j-delete-cesa-note");
479
 
480
        deleteButton.addClass("show_delete_note_btn");
481
        textArea.attr(
482
          "data-editnoteid",
483
          $(this).parent().find(".content").attr("data-noteid")
484
        );
485
        textArea.val(noteText);
486
      });
487
      $("body").delegate(
488
        ".modal_cesa_notes_root .modal-header button.close",
489
        "click",
490
        function (e) {
491
          $("#id_mynotecontent-" + CONFIG.instanceid).removeAttr(
492
            "data-editnoteid"
493
          );
494
          $("#id_mynotecontent-" + CONFIG.instanceid).val("");
495
          $(".j-delete-cesa-note").removeClass("show_delete_note_btn");
496
          $("#cesa_notes_delete_modal").removeClass("show_delete_modal");
497
        }
498
      );
499
      $("body").delegate(
500
        "#cesa_notes_modal_cancel_delete",
501
        "click",
502
        function (e) {
503
          $("#cesa_notes_delete_modal").removeClass("show_delete_modal");
504
        }
505
      );
506
      $("body").delegate(
507
        "#cesa_notes_modal_accept_delete",
508
        "click",
509
        function (e) {
510
          var nid = $("#id_mynotecontent-" + CONFIG.instanceid).attr(
511
            "data-editnoteid"
512
          );
513
          if (nid != "" || nid != "undefined") {
514
            var notescount = $(SELECTORS.cesa_notes_BASE).find(
515
              SELECTORS.cesa_notes_LISTS + "-" + scope.currenttab + " > li"
516
            ).length;
517
            var id = nid.replace("mynote-" + CONFIG.instanceid + "-", "");
518
            var arg = {
519
              contextid: CONFIG.contextid,
520
              action: "delete",
521
              noteid: id,
522
              lastnotecounts: notescount,
523
            };
524
            scope.request({
525
              params: arg,
526
              callback: function (id, ret, args) {
527
                args.scope.addToList(ret);
528
                $("#mynote-" + CONFIG.instanceid + "-" + ret.noteid).remove();
529
                $(".j-delete-cesa-note").removeClass("show_delete_note_btn");
530
                $("#id_mynotecontent-" + CONFIG.instanceid).removeAttr(
531
                  "data-editnoteid"
532
                );
533
                $("#id_mynotecontent-" + CONFIG.instanceid).val("");
534
                $("#cesa_notes_delete_modal").removeClass("show_delete_modal");
535
                args.scope.displaycesa_notes();
536
              },
1 efrain 537
            });
365 ariadna 538
          }
539
        }
540
      );
541
      $("body").delegate("#addmynote_submit", "click", function (e) {
542
        scope.savecesa_notes(e);
543
      });
544
      //$('body').delegate('#cesa_notes_print', 'click', function(e) {scope.printcesa_notes(e)});
545
      $("body").delegate(
546
        SELECTORS.cesa_notes_BASE + " ul.tabs-menu li",
547
        "click",
548
        function (e) {
549
          $(this).addClass("current");
550
          $(this).siblings().removeClass("current");
551
          var tab = $(this).attr("id").replace("tab-", "");
552
          $(SELECTORS.cesa_notes_BASE + " .tab-content")
553
            .not("#" + tab)
554
            .css("display", "none");
555
          $(SELECTORS.cesa_notes_BASE + " #" + tab + ".tab-content").css(
556
            "display",
557
            "block"
558
          );
559
          scope.currenttab = "#" + tab;
1 efrain 560
 
365 ariadna 561
          var isloaded = $(scope.currenttab).attr("data-loaded");
562
          if (typeof isloaded == "undefined" || isloaded == false) {
563
            $(SELECTORS.cesa_notes_BASE)
564
              .find(scope.currenttab)
565
              .attr("data-loaded", "true");
566
            scope.getcesa_notes(0);
567
          }
568
        }
569
      );
570
 
571
      $("body").delegate(
572
        "#id_mynotecontent-" + CONFIG.instanceid,
573
        "focus blur",
574
        function (e) {
575
          scope.toggle_textarea(e);
576
        }
577
      );
578
      $("body").delegate(
579
        "#id_mynotecontent-" + CONFIG.instanceid,
580
        "change keypress keyup",
581
        function (e) {
582
          scope.getWarnings(scope.checkInputText());
583
        }
584
      );
585
 
586
      $("body").delegate(
587
        SELECTORS.cesa_notes_BASE + " .cesa_notes-paging .paging a",
588
        "click",
589
        function (e) {
590
          e.preventDefault();
591
          var regex = new RegExp(/[\?&]page=(\d+)/);
592
          var results = regex.exec($(this).attr("href"));
593
          var page = 0;
594
          if (results[1]) {
595
            page = results[1];
596
          }
597
          $(SELECTORS.cesa_notes_BASE)
598
            .find(scope.currenttab)
599
            .attr("onpage", parseInt(page));
600
          scope.getcesa_notes(page);
601
        }
602
      );
603
 
604
      $("body").delegate(
605
        SELECTORS.cesa_notes_BASE + " .j-delete-cesa-note",
606
        "click",
607
        function (e) {
608
          e.preventDefault();
609
          var nid = $("#id_mynotecontent-" + CONFIG.instanceid).attr(
610
            "data-editnoteid"
611
          );
612
          if (nid != "" || nid != "undefined") {
613
            let deleteModal = $("#cesa_notes_delete_modal");
614
            deleteModal.addClass("show_delete_modal");
615
          }
616
        }
617
      );
618
      $("body").delegate(
619
        SELECTORS.cesa_notes_BASE + " a.mynote-delete",
620
        "click",
621
        function (e) {
622
          e.preventDefault();
623
          $("#id_mynotecontent-" + CONFIG.instanceid).removeAttr(
624
            "data-editnoteid"
625
          );
626
          var nid = $(this).attr("id");
627
          if (nid != "" || nid != "undefined") {
628
            var notescount = $(SELECTORS.cesa_notes_BASE).find(
629
              SELECTORS.cesa_notes_LISTS + "-" + scope.currenttab + " > li"
630
            ).length;
631
            var id = nid.replace(
632
              "mynote-delete-" + CONFIG.instanceid + "-",
633
              ""
634
            );
635
            var arg = {
636
              contextid: CONFIG.contextid,
637
              action: "delete",
638
              noteid: id,
639
              lastnotecounts: notescount,
640
            };
641
            scope.request({
642
              params: arg,
643
              callback: function (id, ret, args) {
644
                args.scope.addToList(ret);
645
                $("#mynote-" + CONFIG.instanceid + "-" + ret.noteid).remove();
646
                args.scope.displaycesa_notes();
647
              },
1 efrain 648
            });
365 ariadna 649
          }
650
        }
651
      );
652
    },
653
    displayDialogue: function (e) {
654
      var scope = cesa_notes;
655
      if (panel === null) {
656
        str
657
          .get_strings([
658
            { key: "cesa_notes", component: "block_cesa_notes" },
659
            { key: "characterlimit", component: "block_cesa_notes" },
660
            { key: "save", component: "block_cesa_notes" },
661
            { key: "cancel" },
662
            {
663
              key: "cesa_notessavedundertab",
664
              component: "block_cesa_notes",
665
              param: CONFIG.contextareas[scope.currenttabindex],
666
            },
667
            { key: "placeholdercontent", component: "block_cesa_notes" },
668
          ])
669
          .done(function (s) {
670
            // Create basic tab structure
1 efrain 671
 
365 ariadna 672
            let deleteModal = `<div id="cesa_notes_delete_modal">
1 efrain 673
                                        <div class="cesa_notes_delete_modal_content">
674
                                            <p>¿Estás seguro de que quieres eliminar este apunte?</p>
675
                                            <button id="cesa_notes_modal_cancel_delete">Cancelar</button>
676
                                            <button id="cesa_notes_modal_accept_delete">Eliminar</button>
677
                                        </div>
678
                                        </div>`;
365 ariadna 679
            var el = $("<div></div>").append(
680
              $(
681
                '<div id="' +
682
                  CSS.cesa_notes_BASE +
683
                  '" class="' +
684
                  CSS.cesa_notes_BASE +
685
                  '">' +
686
                  deleteModal +
687
                  "</div>"
688
              )
689
                .append(
690
                  '<div class="inputarea"><div class="responsetext"></div><div class="cesa-notes-limit" id="addmynote-label-' +
691
                    CONFIG.instanceid +
692
                    '">' +
693
                    s[1] +
694
                    " " +
695
                    CONFIG.maxallowedcharacters +
696
                    '<span class="warning"></span></div>' +
697
                    '<div class="textarea"><textarea id="id_mynotecontent-' +
698
                    CONFIG.instanceid +
699
                    '" name="mynotecontent" rows="2">' +
700
                    s[5] +
701
                    "</textarea></div>" +
702
                    '<p class="notesavedhint">' +
703
                    s[4] +
704
                    "</p>" +
705
                    '<p class="cesa_notes_buttons_container"><button class="j-delete-cesa-note">Eliminar</button><input type="submit" id="addmynote_submit"/> </p>' +
706
                    '<p class="cesa_note_bottom_container"><a class="cesa_notes_print" target="_blank" href="' +
707
                    CONFIG.printapi +
708
                    '">Imprimir notas</a> </p>' +
709
                    "</div>"
710
                )
711
                .append($('<ul class="tabs-menu"></ul>'))
712
                .append($('<div class="tab"></div>'))
713
            );
714
            el.find("#addmynote_submit").attr("value", s[2]);
715
            el.find("#addmynote_cancel").attr("value", s[3]);
716
            var tabsmenu = "";
717
            var tabcontents = "";
718
            var i = "";
719
            for (i in CONFIG.contextareas) {
720
              if (scope.currenttabindex == i) {
721
                tabsmenu +=
722
                  '<li class="current" id="tab-' +
723
                  CONFIG.prefix +
724
                  i +
725
                  '"><div class="menu-item">' +
726
                  CONFIG.contextareas[i] +
727
                  "</div></li>";
728
              } else {
729
                tabsmenu +=
730
                  '<li class="" id="tab-' +
731
                  CONFIG.prefix +
732
                  i +
733
                  '"><div class="menu-item">' +
734
                  CONFIG.contextareas[i] +
735
                  "</div></li>";
736
              }
737
              tabcontents +=
738
                '<div class="tab-content" id="' +
739
                CONFIG.prefix +
740
                i +
741
                '" onpage="0" notes-count="0">' +
742
                '<div class="notes-info"><div class="cesa_notes-paging"></div><div class="count"></div></div>' +
743
                '<ul id="' +
744
                CONFIG.prefix +
745
                i +
746
                '-list" class="cesa_notes_lists"></ul>' +
747
                "</div>";
748
            }
749
            el.find(".tabs-menu").append(tabsmenu);
750
            el.find(".tab").append($(tabcontents));
751
            ModalFactory.create({
752
              title: s[0],
753
              body: el.html(),
754
            }).then(function (modal) {
755
              if (initnotes === null) {
756
                initnotes = true;
757
                // Get initial notes
758
                scope.getcesa_notes(0);
759
                $(SELECTORS.cesa_notes_BASE)
760
                  .find(scope.currenttab)
761
                  .attr("data-loaded", "true");
762
                $(SELECTORS.cesa_notes_BASE)
763
                  .find(scope.currenttab)
764
                  .css("display", "block");
765
              }
1 efrain 766
 
365 ariadna 767
              let root = modal.getRoot();
1 efrain 768
 
365 ariadna 769
              root.addClass("modal_cesa_notes_root");
1 efrain 770
 
365 ariadna 771
              panel = modal;
772
              panel.show();
773
              scope.registerActions();
774
            });
1 efrain 775
 
365 ariadna 776
            /*if (initnotes === null) {
1 efrain 777
                        initnotes = true;
778
                        // Get initial notes
779
                        scope.getcesa_notes(0);
780
                        $(SELECTORS.cesa_notes_BASE).find(scope.currenttab).attr('data-loaded', "true");
781
                        $(SELECTORS.cesa_notes_BASE).find(scope.currenttab).css('display', 'block');
782
                    }
783
 
784
                    panel.show();*/
365 ariadna 785
            /*Y.use('moodle-core-notification-dialogue', function() {
1 efrain 786
 
787
                         // TODO: CESA_NOTES Cambiar esto para que no use yui sino https://docs.moodle.org/dev/AMD_Modal
788
 
789
                        panel = new M.core.dialogue({
790
                            draggable: true,
791
                            modal: true,
792
                            closeButton: true,
793
                            headerContent: M.util.get_string('cesa_notes', 'block_cesa_notes'),
794
                            responsive: true,
795
                            classname: 'testing'
796
                        });
797
 
798
                        panel.set('bodyContent', el.html());
799
                        if (initnotes === null) {
800
                            initnotes = true;
801
                            // Get initial notes
802
                            scope.getcesa_notes(0);
803
                            $(SELECTORS.cesa_notes_BASE).find(scope.currenttab).attr('data-loaded', "true");
804
                            $(SELECTORS.cesa_notes_BASE).find(scope.currenttab).css('display', 'block');
805
                        }
806
                        panel.show();
807
                    });*/
365 ariadna 808
            //scope.registerActions();
809
          });
810
      } else {
811
        panel.show();
812
      }
813
    },
814
    /**
815
     * Initialize cesa_notes
816
     * @access public
817
     * @param {int} instanceid
818
     * @param {int} contextid
819
     * @param {int} maxallowedcharacters
820
     * @param {int} perpage
821
     * @param {string} editingicon_pos
822
     * @param {bool} editing
823
     * @param {string} adminurl
824
     * @param {array} contextareas
825
     * @param {string} currenttabindex
826
     */
827
    init: function (args) {
828
      CONFIG = args;
829
      CONFIG.prefix = "cesa_notes_";
830
      CONFIG.printapi = this.getcesa_notesValidatedUrl(
831
        M.cfg.wwwroot + "/blocks/cesa_notes/cesa_notes_print.php"
832
      );
833
      this.perpage = parseInt(CONFIG.perpage);
834
      this.currenttab = "#cesa_notes_" + args.currenttabindex;
835
      this.defaulttab = "#cesa_notes_" + args.currenttabindex;
836
      this.currenttabindex = args.currenttabindex;
837
      this.api = this.getcesa_notesValidatedUrl(
838
        M.cfg.wwwroot + "/blocks/cesa_notes/cesa_notes_ajax.php"
839
      );
840
      var strtitle = M.util.get_string("showcesa_notes", "block_cesa_notes");
841
      if (!CONFIG.editing) {
842
        var handler = $(
843
          '<div class="' +
844
            CSS.cesa_notes_OPENER +
845
            '" title="' +
846
            strtitle +
847
            '" alt="' +
848
            strtitle +
849
            '">' +
850
            M.util.get_string("cesa_notes", "block_cesa_notes") +
851
            "</div>"
852
        );
853
        handler.addClass(CONFIG.editingicon_pos);
854
        $("body").append(handler);
855
        handler.html('<span class="pencil">&#x270D;</span>');
856
      } else {
857
        var handler = $(
858
          '<div class="' +
859
            CSS.cesa_notes_OPENER +
860
            '" title="' +
861
            strtitle +
862
            '" alt="' +
863
            strtitle +
864
            '">' +
865
            M.util.get_string("cesa_notes", "block_cesa_notes") +
866
            "</div>"
867
        );
868
        handler.addClass(CONFIG.editingicon_pos);
869
        handler.html('<span class="pencil">&#x270D;</span>');
870
        $(".inline-" + CSS.cesa_notes_OPENER).html(handler);
871
        $(".inline-" + CSS.cesa_notes_OPENER).append(
872
          '<div class="cesa_notes-pos-inline-text ' +
873
            CSS.cesa_notes_OPENER +
874
            '">' +
875
            strtitle +
876
            "</div>"
877
        );
878
      }
879
      var body = $("body");
880
      body.delegate(SELECTORS.cesa_notes_OPENER, "click", this.displayDialogue);
881
    },
882
  };
883
  return cesa_notes;
884
});