1 |
efrain |
1 |
define(['jquery', 'core/yui', 'core/str', 'core/config', 'core/notification', 'core/modal_factory'], function($, Y, str, config, notification, ModalFactory) {
|
|
|
2 |
var CONFIG;
|
|
|
3 |
var NODES = {
|
|
|
4 |
DELETE_ICON: '<span class="delete">❌</span>',
|
|
|
5 |
};
|
|
|
6 |
var SELECTORS = {
|
|
|
7 |
cesa_notes_BASE: '#cesa_notes_base',
|
|
|
8 |
cesa_notes_OPENER: '.cesa_notes-opener',
|
|
|
9 |
cesa_notes_LISTS: '.cesa_notes_list',
|
|
|
10 |
};
|
|
|
11 |
var CSS = {
|
|
|
12 |
cesa_notes_BASE: 'cesa_notes_base',
|
|
|
13 |
cesa_notes_OPENER: 'cesa_notes-opener',
|
|
|
14 |
cesa_notes_LISTS: 'cesa_notes_list',
|
|
|
15 |
};
|
|
|
16 |
var panel = null;
|
|
|
17 |
var initnotes = null;
|
|
|
18 |
var strdeletenote = M.util.get_string('deletecesa_notes', 'block_cesa_notes');
|
|
|
19 |
|
|
|
20 |
var getcesa_notesValidatedUrl = function(baseurl) {
|
|
|
21 |
var a = document.createElement('a');
|
|
|
22 |
a.href = baseurl;
|
|
|
23 |
return (a.search.length > 0) ? baseurl : baseurl + '?';
|
|
|
24 |
};
|
|
|
25 |
|
|
|
26 |
var cesa_notes = { /** @alias module:blocks/cesa_notes */
|
|
|
27 |
|
|
|
28 |
getcesa_notesValidatedUrl: function(baseurl) {
|
|
|
29 |
var a = document.createElement('a');
|
|
|
30 |
a.href = baseurl;
|
|
|
31 |
return (a.search.length > 0) ? baseurl : baseurl + '?';
|
|
|
32 |
},
|
|
|
33 |
/*
|
|
|
34 |
* Validation for textarea input text
|
|
|
35 |
*/
|
|
|
36 |
getWarnings: function(status) {
|
|
|
37 |
if (status == false) {
|
|
|
38 |
$('#addmynote-label-' + CONFIG.instanceid + ' span.warning').html(CONFIG.maxallowedcharacters_warning);
|
|
|
39 |
} else {
|
|
|
40 |
var ta = $('#id_mynotecontent-' + CONFIG.instanceid);
|
|
|
41 |
if (ta.val() == '') {
|
|
|
42 |
$('#addmynote-label-' + CONFIG.instanceid + ' span.warning').html('');
|
|
|
43 |
} else {
|
|
|
44 |
var cl = CONFIG.maxallowedcharacters - ta.val().length;
|
|
|
45 |
$('#addmynote-label-' + CONFIG.instanceid + ' span.warning').html(M.util.get_string('charactersleft', 'block_cesa_notes') + cl);
|
|
|
46 |
}
|
|
|
47 |
}
|
|
|
48 |
},
|
|
|
49 |
checkInputText: function() {
|
|
|
50 |
var ta = $('#id_mynotecontent-' + CONFIG.instanceid);
|
|
|
51 |
if (ta.val().length <= CONFIG.maxallowedcharacters) {
|
|
|
52 |
$('#addmynote_submit').removeAttr('disabled', '');
|
|
|
53 |
return true;
|
|
|
54 |
} else {
|
|
|
55 |
$('#addmynote_submit').attr('disabled', 'disabled');
|
|
|
56 |
return false;
|
|
|
57 |
}
|
|
|
58 |
return true;
|
|
|
59 |
},
|
|
|
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: {
|
|
|
121 |
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 |
},
|
|
|
133 |
|
|
|
134 |
printcesa_notes: function(e) {
|
|
|
135 |
e.preventDefault();
|
|
|
136 |
let note_content_input = $('#id_mynotecontent-' + CONFIG.instanceid);;
|
|
|
137 |
let arg = {
|
|
|
138 |
action: 'print'
|
|
|
139 |
}
|
|
|
140 |
|
|
|
141 |
note_content_input.attr('disabled', true);
|
|
|
142 |
note_content_input.css({
|
|
|
143 |
'backgroundImage': 'url(' + M.util.image_url('i/loading_small', 'core') + ')',
|
|
|
144 |
'backgroundRepeat': 'no-repeat',
|
|
|
145 |
'backgroundPosition': 'center center'
|
|
|
146 |
});
|
|
|
147 |
|
|
|
148 |
this.request({
|
|
|
149 |
params: arg,
|
|
|
150 |
callback: function(id, ret, args) {
|
|
|
151 |
$('#id_mynotecontent-' + CONFIG.instanceid).removeAttr('disabled');
|
|
|
152 |
$('#id_mynotecontent-' + CONFIG.instanceid).css({backgroundImage: ''});
|
|
|
153 |
}
|
|
|
154 |
});
|
|
|
155 |
},
|
|
|
156 |
|
|
|
157 |
savecesa_notes: function(e) {
|
|
|
158 |
e.preventDefault();
|
|
|
159 |
var scope = this;
|
|
|
160 |
|
|
|
161 |
if (scope.checkInputText() == false) {
|
|
|
162 |
return false;
|
|
|
163 |
}
|
|
|
164 |
var ta = $('#id_mynotecontent-' + CONFIG.instanceid);
|
|
|
165 |
if (ta.val() == "" || ta.val() == M.util.get_string('placeholdercontent', 'block_cesa_notes')) {
|
|
|
166 |
return false;
|
|
|
167 |
}
|
|
|
168 |
let editingNoteId = ta.attr('data-editnoteid') ? ta.attr('data-editnoteid').replace('mynote-'+ CONFIG.instanceid + '-', '') : false;
|
|
|
169 |
|
|
|
170 |
var arg = {
|
|
|
171 |
contextid: CONFIG.contextid,
|
|
|
172 |
content: ta.val(),
|
|
|
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({
|
|
|
181 |
'backgroundImage': 'url(' + M.util.image_url('i/loading_small', 'core') + ')',
|
|
|
182 |
'backgroundRepeat': 'no-repeat',
|
|
|
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');
|
|
|
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");
|
|
|
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 |
};
|
|
|
248 |
this.request({
|
|
|
249 |
params: arg,
|
|
|
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);
|
|
|
289 |
if (cesa_notescount > 0) {
|
|
|
290 |
noteinfo.find('.count').html(M.util.get_string('cesa_notescount', 'block_cesa_notes') + '' + cesa_notescount);
|
|
|
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>';
|
|
|
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;
|
|
|
321 |
},
|
|
|
322 |
createLink: function(page, text, classname) {
|
|
|
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) {
|
|
|
342 |
$(el).css('display', 'block');
|
|
|
343 |
}
|
|
|
344 |
});
|
|
|
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()});
|
|
|
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);
|
|
|
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();
|
|
|
387 |
$('.j-delete-cesa-note').removeClass('show_delete_note_btn');
|
|
|
388 |
$('#id_mynotecontent-' + CONFIG.instanceid).removeAttr('data-editnoteid');
|
|
|
389 |
$('#id_mynotecontent-' + CONFIG.instanceid).val('');
|
|
|
390 |
$('#cesa_notes_delete_modal').removeClass('show_delete_modal');
|
|
|
391 |
args.scope.displaycesa_notes();
|
|
|
392 |
}
|
|
|
393 |
});
|
|
|
394 |
}
|
|
|
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;
|
|
|
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 |
|
|
|
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');
|
|
|
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({
|
|
|
454 |
params: arg,
|
|
|
455 |
callback: function(id, ret, args) {
|
|
|
456 |
args.scope.addToList(ret);
|
|
|
457 |
$('#mynote-'+ CONFIG.instanceid + '-' + ret.noteid).remove();
|
|
|
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'},
|
|
|
470 |
{key : 'save', component : 'block_cesa_notes'},
|
|
|
471 |
{key : 'cancel'},
|
|
|
472 |
{key : 'cesa_notessavedundertab', component : 'block_cesa_notes', param: CONFIG.contextareas[scope.currenttabindex]},
|
|
|
473 |
{key : 'placeholdercontent', component : 'block_cesa_notes'}
|
|
|
474 |
]).done(function(s) {
|
|
|
475 |
// Create basic tab structure
|
|
|
476 |
|
|
|
477 |
let deleteModal = `<div id="cesa_notes_delete_modal">
|
|
|
478 |
<div class="cesa_notes_delete_modal_content">
|
|
|
479 |
<p>¿Estás seguro de que quieres eliminar este apunte?</p>
|
|
|
480 |
<button id="cesa_notes_modal_cancel_delete">Cancelar</button>
|
|
|
481 |
<button id="cesa_notes_modal_accept_delete">Eliminar</button>
|
|
|
482 |
</div>
|
|
|
483 |
</div>`;
|
|
|
484 |
var el = $('<div></div>').append($('<div id="' + CSS.cesa_notes_BASE + '" class="' + CSS.cesa_notes_BASE + '">'+ deleteModal +'</div>')
|
|
|
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>' +
|
|
|
486 |
'<div class="textarea"><textarea id="id_mynotecontent-' + CONFIG.instanceid + '" name="mynotecontent" rows="2">' + s[5] + '</textarea></div>' +
|
|
|
487 |
'<p class="notesavedhint">' + s[4] + '</p>' +
|
|
|
488 |
'<p class="cesa_notes_buttons_container"><button class="j-delete-cesa-note">Eliminar</button><input type="submit" id="addmynote_submit"/> </p>' +
|
|
|
489 |
'<p class="cesa_note_bottom_container"><a class="cesa_notes_print" target="_blank" href="'+ CONFIG.printapi +'">Imprimir notas</a> </p>'+
|
|
|
490 |
'</div>'
|
|
|
491 |
)
|
|
|
492 |
.append($('<ul class="tabs-menu"></ul>'))
|
|
|
493 |
.append($('<div class="tab"></div>'))
|
|
|
494 |
);
|
|
|
495 |
el.find('#addmynote_submit').attr('value', s[2]);
|
|
|
496 |
el.find('#addmynote_cancel').attr('value', s[3]);
|
|
|
497 |
var tabsmenu = '';
|
|
|
498 |
var tabcontents = '';
|
|
|
499 |
var i = '';
|
|
|
500 |
for (i in CONFIG.contextareas) {
|
|
|
501 |
if (scope.currenttabindex == i) {
|
|
|
502 |
tabsmenu += '<li class="current" id="tab-' + CONFIG.prefix + i + '"><div class="menu-item">' + CONFIG.contextareas[i] + '</div></li>';
|
|
|
503 |
} else {
|
|
|
504 |
tabsmenu += '<li class="" id="tab-' + CONFIG.prefix + i + '"><div class="menu-item">' + CONFIG.contextareas[i] + '</div></li>';
|
|
|
505 |
}
|
|
|
506 |
tabcontents += '<div class="tab-content" id="' + CONFIG.prefix + i + '" onpage="0" notes-count="0">'
|
|
|
507 |
+ '<div class="notes-info"><div class="cesa_notes-paging"></div><div class="count"></div></div>'
|
|
|
508 |
+ '<ul id="' + CONFIG.prefix + i + '-list" class="cesa_notes_lists"></ul>'
|
|
|
509 |
+ '</div>';
|
|
|
510 |
}
|
|
|
511 |
el.find('.tabs-menu').append(tabsmenu);
|
|
|
512 |
el.find('.tab').append($(tabcontents));
|
|
|
513 |
ModalFactory.create({
|
|
|
514 |
title: s[0],
|
|
|
515 |
body: el.html(),
|
|
|
516 |
}).then(function (modal) {
|
|
|
517 |
if (initnotes === null) {
|
|
|
518 |
initnotes = true;
|
|
|
519 |
// Get initial notes
|
|
|
520 |
scope.getcesa_notes(0);
|
|
|
521 |
$(SELECTORS.cesa_notes_BASE).find(scope.currenttab).attr('data-loaded', "true");
|
|
|
522 |
$(SELECTORS.cesa_notes_BASE).find(scope.currenttab).css('display', 'block');
|
|
|
523 |
}
|
|
|
524 |
|
|
|
525 |
let root = modal.getRoot();
|
|
|
526 |
|
|
|
527 |
root.addClass('modal_cesa_notes_root');
|
|
|
528 |
|
|
|
529 |
panel = modal;
|
|
|
530 |
panel.show();
|
|
|
531 |
scope.registerActions();
|
|
|
532 |
});
|
|
|
533 |
|
|
|
534 |
/*if (initnotes === null) {
|
|
|
535 |
initnotes = true;
|
|
|
536 |
// Get initial notes
|
|
|
537 |
scope.getcesa_notes(0);
|
|
|
538 |
$(SELECTORS.cesa_notes_BASE).find(scope.currenttab).attr('data-loaded', "true");
|
|
|
539 |
$(SELECTORS.cesa_notes_BASE).find(scope.currenttab).css('display', 'block');
|
|
|
540 |
}
|
|
|
541 |
|
|
|
542 |
panel.show();*/
|
|
|
543 |
/*Y.use('moodle-core-notification-dialogue', function() {
|
|
|
544 |
|
|
|
545 |
// TODO: CESA_NOTES Cambiar esto para que no use yui sino https://docs.moodle.org/dev/AMD_Modal
|
|
|
546 |
|
|
|
547 |
panel = new M.core.dialogue({
|
|
|
548 |
draggable: true,
|
|
|
549 |
modal: true,
|
|
|
550 |
closeButton: true,
|
|
|
551 |
headerContent: M.util.get_string('cesa_notes', 'block_cesa_notes'),
|
|
|
552 |
responsive: true,
|
|
|
553 |
classname: 'testing'
|
|
|
554 |
});
|
|
|
555 |
|
|
|
556 |
panel.set('bodyContent', el.html());
|
|
|
557 |
if (initnotes === null) {
|
|
|
558 |
initnotes = true;
|
|
|
559 |
// Get initial notes
|
|
|
560 |
scope.getcesa_notes(0);
|
|
|
561 |
$(SELECTORS.cesa_notes_BASE).find(scope.currenttab).attr('data-loaded', "true");
|
|
|
562 |
$(SELECTORS.cesa_notes_BASE).find(scope.currenttab).css('display', 'block');
|
|
|
563 |
}
|
|
|
564 |
panel.show();
|
|
|
565 |
});*/
|
|
|
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">✍</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">✍</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 |
});
|