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