Proyectos de Subversion Moodle

Rev

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