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