Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

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