5ca8f561 by logesh

dev:changes in notes

1 parent f9077e02
1 define(['jquery', 'core/yui', 'core/str', 'core/config', 'core/notification'], function($, Y, str, config, notification) { var CONFIG; var NODES = { DELETE_ICON: '<span class="delete">&#x274C;</span>', }; var SELECTORS = { MYNOTES_BASE: '#mynotes_base', MYNOTES_OPENER: '.mynotes-opener', MYNOTES_LISTS: '.mynotes_list', }; var CSS = { MYNOTES_BASE: 'mynotes_base', MYNOTES_OPENER: 'mynotes-opener', MYNOTES_LISTS: 'mynotes_list', }; var panel = null; var initnotes = null; var strdeletenote = M.util.get_string('deletemynotes', 'block_mynotes'); var getMynotesValidatedUrl = function(baseurl) { var a = document.createElement('a'); a.href = baseurl; return (a.search.length > 0) ? baseurl : baseurl + '?'; }; var mynotes = { getMynotesValidatedUrl: function(baseurl) { var a = document.createElement('a'); a.href = baseurl; return (a.search.length > 0) ? baseurl : baseurl + '?'; }, getWarnings: function(status) { if (status == false) { $('#addmynote-label-' + CONFIG.instanceid + ' span.warning').html(CONFIG.maxallowedcharacters_warning); } else { var ta = $('#id_mynotecontent-' + CONFIG.instanceid); if (ta.val() == '') { $('#addmynote-label-' + CONFIG.instanceid + ' span.warning').html(''); } else { var cl = CONFIG.maxallowedcharacters - ta.val().length; $('#addmynote-label-' + CONFIG.instanceid + ' span.warning').html(M.util.get_string('charactersleft', 'block_mynotes') + cl); } } }, checkInputText: function() { var ta = $('#id_mynotecontent-' + CONFIG.instanceid); if (ta.val().length <= CONFIG.maxallowedcharacters) { $('#addmynote_submit').removeAttr('disabled', ''); return true; } else { $('#addmynote_submit').attr('disabled', 'disabled'); return false; } return true; }, toggle_textarea: function(e) { var ta = $('#id_mynotecontent-' + CONFIG.instanceid); if (!ta) { return false; } var focus = (e.type == 'focusin'); if (focus) { if (ta.val() == M.util.get_string('placeholdercontent', 'block_mynotes')) { ta.val(''); $('.textarea').css('border-color', 'black'); } } else{ if (ta.val() == '') { ta.val(M.util.get_string('placeholdercontent', 'block_mynotes')); $('.textarea').css('border-color', 'gray'); $('#addmynote-label-' + CONFIG.instanceid + ' span.warning').html(''); } } }, request: function(args) { var params = {}; var scope = this; if (args['scope']) { scope = args['scope']; } params['contextarea'] = scope.currenttab.replace(CONFIG.prefix, ''); params['contextarea'] = params['contextarea'].replace('#', ''); if (args.params) { for (i in args.params) { params[i] = args.params[i]; } } params['sesskey'] = M.cfg.sesskey; var cfg = { method: 'POST', on: { start: function() { }, complete: function(id,o,p) { if (!o) { alert('IO FATAL'); return false; } var data = Y.JSON.parse(o.responseText); if (data.error) { if (data.error == 'require_login') { args.callback(id,data,p); return true; } alert(data.error); return false; } else { args.callback(id,data,p); return true; } } }, arguments: { scope: scope }, headers: { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' }, data: build_querystring(params) }; if (args.form) { cfg.form = args.form; } Y.io(this.api, cfg); }, saveMynotes: function(e) { e.preventDefault(); var scope = this; if (scope.checkInputText() == false) { return false; } var ta = $('#id_mynotecontent-' + CONFIG.instanceid); if (ta.val() == "" || ta.val() == M.util.get_string('placeholdercontent', 'block_mynotes')) { return false; } var arg = { contextid: CONFIG.contextid, content: ta.val(), action: 'add', contextarea: scope.currenttabindex, }; ta.attr('disabled', true); ta.css({ 'backgroundImage': 'url(' + M.util.image_url('i/loading_small', 'core') + ')', 'backgroundRepeat': 'no-repeat', 'backgroundPosition': 'center center' }); this.request({ params: arg, callback: function(id, ret, args) { if (!ret.notes) { return false; } $('#addmynote-label-' + CONFIG.instanceid + ' span.warning').html(''); $('#id_mynotecontent-' + CONFIG.instanceid).val(M.util.get_string('placeholdercontent', 'block_mynotes')); $('#id_mynotecontent-' + CONFIG.instanceid).removeAttr('disabled'); $('#id_mynotecontent-' + CONFIG.instanceid).css({backgroundImage: ''}); if (scope.currenttab != scope.defaulttab) { scope.currenttab = scope.defaulttab; var tab = scope.currenttab.replace('#', '#tab-'); $(SELECTORS.MYNOTES_BASE + ' ul.tabs-menu li').removeClass("current"); $(SELECTORS.MYNOTES_BASE + ' ' + tab).addClass('current'); $(SELECTORS.MYNOTES_BASE + ' .tab-content').has(scope.currenttab).addClass('current'); $(SELECTORS.MYNOTES_BASE + ' .tab-content').not(scope.currenttab).css("display", "none"); $(SELECTORS.MYNOTES_BASE + ' ' + scope.currenttab + '.tab-content').css("display", "block"); } scope.addToList(ret, 'add'); scope.displayMynotes(); $(SELECTORS.MYNOTES_BASE).find('.responsetext').html(M.util.get_string('savedsuccess', 'block_mynotes')); } } ); }, addToList: function(notesobj, action='') { var scope = this; var el = $(SELECTORS.MYNOTES_BASE).find(scope.currenttab + '-list'); if (action == 'add') { el.prepend(scope.renderMynotes(notesobj.notes)); } else { el.append(scope.renderMynotes(notesobj.notes)); $(el).find('li').sort(sort_li) .appendTo(el); function sort_li(a, b){ return ($(b).data('itemid')) > ($(a).data('itemid')) ? 1 : -1; } } $(SELECTORS.MYNOTES_BASE).find(scope.currenttab).attr('notes-count', notesobj.count); }, getMynotes: function(page=0) { var scope = this; page = parseInt(page); var el = $(SELECTORS.MYNOTES_BASE).find(scope.currenttab + '-list'); var notescount = el.find('li').length; var lastpage = Math.ceil(notescount / CONFIG.perpage); if (notescount > 0 && lastpage > page) { scope.displayMynotes(); return false; } var arg = { contextid: CONFIG.contextid, action: 'get', page: page, }; this.request({ params: arg, callback: function(id, ret, args) { scope.addToList(ret); scope.displayMynotes(); } }); }, updateMynotesInfo: function(mynotescount, page) { page = parseInt(page); mynotescount = parseInt(mynotescount); var scope = this; var paging = ''; if (mynotescount > CONFIG.perpage) { var pagenum = page - 1; var prevlink = ''; var nextlink = ''; if (page > 0) { prevlink = scope.createLink(pagenum, M.util.get_string('previouspage', 'block_mynotes'), 'previous'); } if (CONFIG.perpage > 0) { var lastpage = Math.ceil(mynotescount / CONFIG.perpage); } else { var lastpage = 1; } pagenum = page + 1; if (pagenum != lastpage) { nextlink = scope.createLink(pagenum, M.util.get_string('nextpage', 'block_mynotes'), 'next'); } paging = prevlink; if (prevlink != '' && nextlink != '') { paging += '<span class="separator"></span>'; } paging += nextlink; paging = '<span class="paging">' + paging + '</span>'; } var noteinfo = $(SELECTORS.MYNOTES_BASE).find(scope.currenttab); if (mynotescount > 0) { noteinfo.find('.count').html(M.util.get_string('mynotescount', 'block_mynotes') + '' + mynotescount); } else { noteinfo.find('.count').html(M.util.get_string('nothingtodisplay', 'block_mynotes')); } noteinfo.find('.mynotes-paging').html(paging); }, renderMynotes: function(notes) { if (notes.length < 1) { return false; } var lists = ''; var x = ''; for (x in notes) { $('#mynote-'+ CONFIG.instanceid + '-' + notes[x].id).remove(); var deletelink = '<a href="#" id="mynote-delete-' + CONFIG.instanceid + '-' + notes[x].id + '" class="mynote-delete" title="'+ strdeletenote +'">'+ NODES.DELETE_ICON +'</a>'; var notedetail = ''; if (notes[x].coursename != '') { notedetail = '<div class="note-detail">' + notes[x].coursename + ' - ' + '</div>'; } var userdate = '<div class="time">' + notes[x].timecreated + '</div>'; var note_html = '<div class="content">' + deletelink + notes[x].content + '</div>'; lists += '<li id="mynote-' + CONFIG.instanceid + '-' + notes[x].id + '" data-itemid="' + notes[x].id + '">' + note_html + notedetail + userdate + '</li>'; } return lists; }, createLink: function(page, text, classname) { var classattribute = (typeof(classname) != 'undefined') ? ' class="'+classname+'"' : ''; return '<a href="' + this.api + '&page=' + page + '"' + classattribute + '>' + text + '</a>'; }, displayMynotes: function() { var scope = this; var page = parseInt($(SELECTORS.MYNOTES_BASE).find(scope.currenttab).attr('onpage')); var mynotescount = parseInt($(SELECTORS.MYNOTES_BASE).find(scope.currenttab).attr('notes-count')); var el = $(SELECTORS.MYNOTES_BASE).find(' ' + scope.currenttab + '-list'); var notescount = el.find('li').length; var lastpage = Math.ceil(notescount / CONFIG.perpage); if (notescount > 0 && lastpage <= page) { page = lastpage - 1; } var upperlimit = page * CONFIG.perpage + CONFIG.perpage; var lowerlimit = page * CONFIG.perpage; el.find('li').css('display', 'none'); el.find('li').each(function(i, el) { if (i>=lowerlimit && i<upperlimit) { $(el).css('display', 'block'); } }); scope.updateMynotesInfo(mynotescount, page); }, registerActions: function() { var scope = this; $('body').delegate('#addmynote_cancel', 'click', function() {panel.hide()}); $('body').delegate('#addmynote_submit', 'click', function(e) {scope.saveMynotes(e)}); $('body').delegate(SELECTORS.MYNOTES_BASE + ' ul.tabs-menu li', 'click', function(e) { $(this).addClass("current"); $(this).siblings().removeClass("current"); var tab = $(this).attr("id").replace('tab-', ''); $(SELECTORS.MYNOTES_BASE + ' .tab-content').not('#' + tab).css("display", "none"); $(SELECTORS.MYNOTES_BASE + ' #' + tab + '.tab-content').css("display", "block"); scope.currenttab = '#'+tab; var isloaded = $(scope.currenttab).attr('data-loaded'); if (typeof isloaded == 'undefined' || isloaded == false) { $(SELECTORS.MYNOTES_BASE).find(scope.currenttab).attr('data-loaded', "true"); scope.getMynotes(0); } }); $('body').delegate('#id_mynotecontent-' + CONFIG.instanceid, 'focus blur', function(e) { scope.toggle_textarea(e); }); $('body').delegate('#id_mynotecontent-' + CONFIG.instanceid, 'change keypress keyup', function(e) { scope.getWarnings(scope.checkInputText()); }); $('body').delegate(SELECTORS.MYNOTES_BASE + ' .mynotes-paging .paging a', 'click', function(e) { e.preventDefault(); var regex = new RegExp(/[\?&]page=(\d+)/); var results = regex.exec($(this).attr('href')); var page = 0; if (results[1]) { page = results[1]; } $(SELECTORS.MYNOTES_BASE).find(scope.currenttab).attr('onpage', parseInt(page)); scope.getMynotes(page); }); $('body').delegate(SELECTORS.MYNOTES_BASE + ' a.mynote-delete', 'click', function(e) { e.preventDefault(); var nid = $(this).attr('id'); if (nid != '' || nid != 'undefined') { var notescount = $(SELECTORS.MYNOTES_BASE).find(SELECTORS.MYNOTES_LISTS + '-' + scope.currenttab + ' > li').length; var id = nid.replace('mynote-delete-'+ CONFIG.instanceid + '-', ''); var arg = { contextid: CONFIG.contextid, action: 'delete', noteid: id, lastnotecounts: notescount, }; scope.request({ params: arg, callback: function(id, ret, args) { args.scope.addToList(ret); $('#mynote-'+ CONFIG.instanceid + '-' + ret.noteid).remove(); args.scope.displayMynotes(); } }); } }); }, displayDialogue: function(e) { var scope = mynotes; if (panel === null) { str.get_strings([ {key : 'mynotes', component : 'block_mynotes'}, {key : 'nocharacterlimit', component : 'block_mynotes'}, {key : 'save', component : 'block_mynotes'}, {key : 'cancel'}, {key : 'mynotessavedundertab', component : 'block_mynotes', param: CONFIG.contextareas[scope.currenttabindex]}, {key : 'placeholdercontent', component : 'block_mynotes'} ]).done(function(s) { var el = $('<div></div>').append($('<div id="' + CSS.MYNOTES_BASE + '" class="' + CSS.MYNOTES_BASE + '"></div>') .append('<div class="inputarea"><div id="addmynote-label-' + CONFIG.instanceid + '">' + s[1] + ' ' +'' + '</div>' + '<div class="textarea"><textarea id="id_mynotecontent-' + CONFIG.instanceid + '" name="mynotecontent" rows="2">' + s[5] + '</textarea></div>' + '<p><br></p>' + '<p class="mdl-align"><input type="submit" id="addmynote_submit"/></p>' + '</div>' ) .append($('<ul class="tabs-menu"></ul>')) .append($('<div class="tab"></div>')) ); el.find('#addmynote_submit').attr('value', s[2]); el.find('#addmynote_cancel').attr('value', s[3]); var tabsmenu = ''; var tabcontents = ''; var i = ''; for (i in CONFIG.contextareas) { if (scope.currenttabindex == i) { tabsmenu += '<li class="current" id="tab-' + CONFIG.prefix + i + '"><div class="menu-item">' + CONFIG.contextareas[i] + '</div></li>'; } else { tabsmenu += '<li class="" id="tab-' + CONFIG.prefix + i + '"><div class="menu-item">' + CONFIG.contextareas[i] + '</div></li>'; } tabcontents += '<div class="tab-content" id="' + CONFIG.prefix + i + '" onpage="0" notes-count="0">' + '<div class="notes-info"><div class="mynotes-paging"></div><div class="count"></div></div>' + '<ul id="' + CONFIG.prefix + i + '-list" class="mynotes_lists"></ul>' + '</div>'; } el.find('.tabs-menu').append(tabsmenu); el.find('.tab').append($(tabcontents)); Y.use('moodle-core-notification-dialogue', function() { panel = new M.core.dialogue({ draggable: true, modal: true, closeButton: true, headerContent: M.util.get_string('mynotes', 'block_mynotes'), responsive: true, }); panel.set('bodyContent', el.html()); if (initnotes === null) { initnotes = true; scope.getMynotes(0); $(SELECTORS.MYNOTES_BASE).find(scope.currenttab).attr('data-loaded', "true"); $(SELECTORS.MYNOTES_BASE).find(scope.currenttab).css('display', 'block'); } panel.show(); }); scope.registerActions(); }); } else { panel.show(); } }, init: function(args) { CONFIG = args; CONFIG.prefix = 'mynotes_'; this.perpage = parseInt(CONFIG.perpage); this.currenttab = '#mynotes_' + args.currenttabindex; this.defaulttab = '#mynotes_' + args.currenttabindex; this.currenttabindex = args.currenttabindex; this.api = this.getMynotesValidatedUrl(M.cfg.wwwroot+'/blocks/mynotes/mynotes_ajax.php'); var strtitle = M.util.get_string('showmynotes', 'block_mynotes'); if (!CONFIG.editing) { var handler = $('<div class="'+ CSS.MYNOTES_OPENER +'" title="' + strtitle + '" alt="' + strtitle+ '">' + M.util.get_string('mynotes', 'block_mynotes') + '</div>'); handler.addClass(CONFIG.editingicon_pos); $('body').append(handler); handler.html('<span class="pencil" id="mynotepencil">&#x270D;</span>'); } else { var handler = $('<div class="'+ CSS.MYNOTES_OPENER +'" title="' + strtitle + '" alt="' + strtitle+ '">' + M.util.get_string('mynotes', 'block_mynotes') + '</div>'); handler.addClass(CONFIG.editingicon_pos); handler.html('<span class="pencil">&#x270D;</span>'); $('.inline-'+ CSS.MYNOTES_OPENER).html(handler); $('.inline-'+ CSS.MYNOTES_OPENER).append('<div class="mynotes-pos-inline-text '+ CSS.MYNOTES_OPENER +'">' + strtitle + '</div>'); } var body = $('body'); body.delegate(SELECTORS.MYNOTES_OPENER, 'click', this.displayDialogue); } }; return mynotes; });
...\ No newline at end of file ...\ No newline at end of file
1 define(['jquery', 'core/yui', 'core/str', 'core/config', 'core/notification'], function($, Y, str, config, notification) {
2 var CONFIG;
3 var NODES = {
4 DELETE_ICON: '<span class="delete">&#x274C;</span>',
5 };
6 var SELECTORS = {
7 MYNOTES_BASE: '#mynotes_base',
8 MYNOTES_OPENER: '.mynotes-opener',
9 MYNOTES_LISTS: '.mynotes_list',
10 };
11 var CSS = {
12 MYNOTES_BASE: 'mynotes_base',
13 MYNOTES_OPENER: 'mynotes-opener',
14 MYNOTES_LISTS: 'mynotes_list',
15 };
16 var panel = null;
17 var initnotes = null;
18 var strdeletenote = M.util.get_string('deletemynotes', 'block_mynotes');
19 var getMynotesValidatedUrl = function(baseurl) {
20 var a = document.createElement('a');
21 a.href = baseurl;
22 return (a.search.length > 0) ? baseurl : baseurl + '?';
23 };
24 var mynotes = {
25 getMynotesValidatedUrl: function(baseurl) {
26 var a = document.createElement('a');
27 a.href = baseurl;
28 return (a.search.length > 0) ? baseurl : baseurl + '?';
29 },
30 getWarnings: function(status) {
31 if (status == false) {
32 $('#addmynote-label-' + CONFIG.instanceid + ' span.warning').html(CONFIG.maxallowedcharacters_warning);
33 } else {
34 var ta = $('#id_mynotecontent-' + CONFIG.instanceid);
35 if (ta.val() == '') {
36 $('#addmynote-label-' + CONFIG.instanceid + ' span.warning').html('');
37 } else {
38 var cl = CONFIG.maxallowedcharacters - ta.val().length;
39 $('#addmynote-label-' + CONFIG.instanceid + ' span.warning').html(M.util.get_string('charactersleft', 'block_mynotes') + cl);
40 }
41 }
42 },
43 checkInputText: function() {
44 var ta = $('#id_mynotecontent-' + CONFIG.instanceid);
45 if (ta.val().length <= CONFIG.maxallowedcharacters) {
46 $('#addmynote_submit').removeAttr('disabled', '');
47 return true;
48 } else {
49 $('#addmynote_submit').attr('disabled', 'disabled');
50 return false;
51 }
52 return true;
53 },
54 toggle_textarea: function(e) {
55 var ta = $('#id_mynotecontent-' + CONFIG.instanceid);
56 if (!ta) {
57 return false;
58 }
59 var focus = (e.type == 'focusin');
60 if (focus) {
61 if (ta.val() == M.util.get_string('placeholdercontent', 'block_mynotes')) {
62 ta.val('');
63 $('.textarea').css('border-color', 'black');
64 }
65 } else {
66 if (ta.val() == '') {
67 ta.val(M.util.get_string('placeholdercontent', 'block_mynotes'));
68 $('.textarea').css('border-color', 'gray');
69 $('#addmynote-label-' + CONFIG.instanceid + ' span.warning').html('');
70 }
71 }
72 },
73 request: function(args) {
74 var params = {};
75 var scope = this;
76 if (args['scope']) {
77 scope = args['scope'];
78 }
79 params['contextarea'] = scope.currenttab.replace(CONFIG.prefix, '');
80 params['contextarea'] = params['contextarea'].replace('#', '');
81 if (args.params) {
82 for (i in args.params) {
83 params[i] = args.params[i];
84 }
85 }
86
87 //notes player time starts
88
89 var iframe = document.querySelector('iframe');
90 console.log(iframe);
91 var player = new Vimeo.Player(iframe);
92 console.log(player);
93 var time;
94 player.getCurrentTime().then(function(seconds) {
95
96 time=seconds;
97 })
98 console.log(time);
99
100 params['sesskey'] = M.cfg.sesskey;
101 var str = '</br></br><font color="green">newly You have taken notes at ';
102 // str +=time;
103 str +=" secs in this video.</font>";
104 // var result = str.fontcolor("green");
105 params['notestime'] = str;
106
107 player.pause().then(function() {
108 alert('the video was paused');
109 })
110
111 //notes player time ends
112
113 var cfg = {
114 method: 'POST',
115 on: {
116 start: function() {},
117 complete: function(id, o, p) {
118 if (!o) {
119 alert('IO FATAL');
120 return false;
121 }
122 var data = Y.JSON.parse(o.responseText);
123 if (data.error) {
124 if (data.error == 'require_login') {
125 args.callback(id, data, p);
126 return true;
127 }
128 alert(data.error);
129 return false;
130 } else {
131 args.callback(id, data, p);
132 return true;
133 }
134 }
135 },
136 arguments: {
137 scope: scope
138 },
139 headers: {
140 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
141 },
142 data: build_querystring(params)
143 };
144 if (args.form) {
145 cfg.form = args.form;
146 }
147 Y.io(this.api, cfg);
148 },
149 saveMynotes: function(e) {
150 e.preventDefault();
151 var scope = this;
152 if (scope.checkInputText() == false) {
153 return false;
154 }
155 var ta = $('#id_mynotecontent-' + CONFIG.instanceid);
156 if (ta.val() == "" || ta.val() == M.util.get_string('placeholdercontent', 'block_mynotes')) {
157 return false;
158 }
159 var arg = {
160 contextid: CONFIG.contextid,
161 content: ta.val(),
162 action: 'add',
163 contextarea: scope.currenttabindex,
164 };
165 ta.attr('disabled', true);
166 ta.css({
167 'backgroundImage': 'url(' + M.util.image_url('i/loading_small', 'core') + ')',
168 'backgroundRepeat': 'no-repeat',
169 'backgroundPosition': 'center center'
170 });
171 this.request({
172 params: arg,
173 callback: function(id, ret, args) {
174 if (!ret.notes) {
175 return false;
176 }
177 $('#addmynote-label-' + CONFIG.instanceid + ' span.warning').html('');
178 $('#id_mynotecontent-' + CONFIG.instanceid).val(M.util.get_string('placeholdercontent', 'block_mynotes'));
179 $('#id_mynotecontent-' + CONFIG.instanceid).removeAttr('disabled');
180 $('#id_mynotecontent-' + CONFIG.instanceid).css({
181 backgroundImage: ''
182 });
183 if (scope.currenttab != scope.defaulttab) {
184 scope.currenttab = scope.defaulttab;
185 var tab = scope.currenttab.replace('#', '#tab-');
186 $(SELECTORS.MYNOTES_BASE + ' ul.tabs-menu li').removeClass("current");
187 $(SELECTORS.MYNOTES_BASE + ' ' + tab).addClass('current');
188 $(SELECTORS.MYNOTES_BASE + ' .tab-content').has(scope.currenttab).addClass('current');
189 $(SELECTORS.MYNOTES_BASE + ' .tab-content').not(scope.currenttab).css("display", "none");
190 $(SELECTORS.MYNOTES_BASE + ' ' + scope.currenttab + '.tab-content').css("display", "block");
191 }
192 scope.addToList(ret, 'add');
193 scope.displayMynotes();
194 $(SELECTORS.MYNOTES_BASE).find('.responsetext').html(M.util.get_string('savedsuccess', 'block_mynotes'));
195 }
196 });
197 },
198 addToList: function(notesobj, action = '') {
199 var scope = this;
200 var el = $(SELECTORS.MYNOTES_BASE).find(scope.currenttab + '-list');
201 if (action == 'add') {
202 el.prepend(scope.renderMynotes(notesobj.notes));
203 } else {
204 el.append(scope.renderMynotes(notesobj.notes));
205 $(el).find('li').sort(sort_li).appendTo(el);
206
207 function sort_li(a, b) {
208 return ($(b).data('itemid')) > ($(a).data('itemid')) ? 1 : -1;
209 }
210 }
211 $(SELECTORS.MYNOTES_BASE).find(scope.currenttab).attr('notes-count', notesobj.count);
212 },
213 getMynotes: function(page = 0) {
214 var scope = this;
215 page = parseInt(page);
216 var el = $(SELECTORS.MYNOTES_BASE).find(scope.currenttab + '-list');
217 var notescount = el.find('li').length;
218 var lastpage = Math.ceil(notescount / CONFIG.perpage);
219 if (notescount > 0 && lastpage > page) {
220 scope.displayMynotes();
221 return false;
222 }
223 var arg = {
224 contextid: CONFIG.contextid,
225 action: 'get',
226 page: page,
227 };
228 this.request({
229 params: arg,
230 callback: function(id, ret, args) {
231 scope.addToList(ret);
232 scope.displayMynotes();
233 }
234 });
235 },
236 updateMynotesInfo: function(mynotescount, page) {
237 page = parseInt(page);
238 mynotescount = parseInt(mynotescount);
239 var scope = this;
240 var paging = '';
241 if (mynotescount > CONFIG.perpage) {
242 var pagenum = page - 1;
243 var prevlink = '';
244 var nextlink = '';
245 if (page > 0) {
246 prevlink = scope.createLink(pagenum, M.util.get_string('previouspage', 'block_mynotes'), 'previous');
247 }
248 if (CONFIG.perpage > 0) {
249 var lastpage = Math.ceil(mynotescount / CONFIG.perpage);
250 } else {
251 var lastpage = 1;
252 }
253 pagenum = page + 1;
254 if (pagenum != lastpage) {
255 nextlink = scope.createLink(pagenum, M.util.get_string('nextpage', 'block_mynotes'), 'next');
256 }
257 paging = prevlink;
258 if (prevlink != '' && nextlink != '') {
259 paging += '<span class="separator"></span>';
260 }
261 paging += nextlink;
262 paging = '<span class="paging">' + paging + '</span>';
263 }
264 var noteinfo = $(SELECTORS.MYNOTES_BASE).find(scope.currenttab);
265 if (mynotescount > 0) {
266 noteinfo.find('.count').html(M.util.get_string('mynotescount', 'block_mynotes') + '' + mynotescount);
267 } else {
268 noteinfo.find('.count').html(M.util.get_string('nothingtodisplay', 'block_mynotes'));
269 }
270 noteinfo.find('.mynotes-paging').html(paging);
271 },
272 renderMynotes: function(notes) {
273 if (notes.length < 1) {
274 return false;
275 }
276 var lists = '';
277 var x = '';
278 for (x in notes) {
279 $('#mynote-' + CONFIG.instanceid + '-' + notes[x].id).remove();
280 var deletelink = '<a href="#" id="mynote-delete-' + CONFIG.instanceid + '-' + notes[x].id + '" class="mynote-delete" title="' + strdeletenote + '">' + NODES.DELETE_ICON + '</a>';
281 var notedetail = '';
282 if (notes[x].coursename != '') {
283 notedetail = '<div class="note-detail">' + notes[x].coursename + ' - ' + '</div>';
284 }
285 var userdate = '<div class="time">' + notes[x].timecreated + '</div>';
286 var note_html = '<div class="content">' + deletelink + notes[x].content + '</div>';
287 lists += '<li id="mynote-' + CONFIG.instanceid + '-' + notes[x].id + '" data-itemid="' + notes[x].id + '">' + note_html + notedetail + userdate + '</li>';
288 }
289 return lists;
290 },
291 createLink: function(page, text, classname) {
292 var classattribute = (typeof(classname) != 'undefined') ? ' class="' + classname + '"' : '';
293 return '<a href="' + this.api + '&page=' + page + '"' + classattribute + '>' + text + '</a>';
294 },
295 displayMynotes: function() {
296 var scope = this;
297 var page = parseInt($(SELECTORS.MYNOTES_BASE).find(scope.currenttab).attr('onpage'));
298 var mynotescount = parseInt($(SELECTORS.MYNOTES_BASE).find(scope.currenttab).attr('notes-count'));
299 var el = $(SELECTORS.MYNOTES_BASE).find(' ' + scope.currenttab + '-list');
300 var notescount = el.find('li').length;
301 var lastpage = Math.ceil(notescount / CONFIG.perpage);
302 if (notescount > 0 && lastpage <= page) {
303 page = lastpage - 1;
304 }
305 var upperlimit = page * CONFIG.perpage + CONFIG.perpage;
306 var lowerlimit = page * CONFIG.perpage;
307 el.find('li').css('display', 'none');
308 el.find('li').each(function(i, el) {
309 if (i >= lowerlimit && i < upperlimit) {
310 $(el).css('display', 'block');
311 }
312 });
313 scope.updateMynotesInfo(mynotescount, page);
314 },
315 registerActions: function() {
316 var scope = this;
317 $('body').delegate('#addmynote_cancel', 'click', function() {
318 panel.hide()
319 });
320 $('body').delegate('#addmynote_submit', 'click', function(e) {
321 scope.saveMynotes(e)
322 });
323 $('body').delegate(SELECTORS.MYNOTES_BASE + ' ul.tabs-menu li', 'click', function(e) {
324 $(this).addClass("current");
325 $(this).siblings().removeClass("current");
326 var tab = $(this).attr("id").replace('tab-', '');
327 $(SELECTORS.MYNOTES_BASE + ' .tab-content').not('#' + tab).css("display", "none");
328 $(SELECTORS.MYNOTES_BASE + ' #' + tab + '.tab-content').css("display", "block");
329 scope.currenttab = '#' + tab;
330 var isloaded = $(scope.currenttab).attr('data-loaded');
331 if (typeof isloaded == 'undefined' || isloaded == false) {
332 $(SELECTORS.MYNOTES_BASE).find(scope.currenttab).attr('data-loaded', "true");
333 scope.getMynotes(0);
334 }
335 });
336 $('body').delegate('#id_mynotecontent-' + CONFIG.instanceid, 'focus blur', function(e) {
337 scope.toggle_textarea(e);
338 });
339 $('body').delegate('#id_mynotecontent-' + CONFIG.instanceid, 'change keypress keyup', function(e) {
340 scope.getWarnings(scope.checkInputText());
341 });
342 $('body').delegate(SELECTORS.MYNOTES_BASE + ' .mynotes-paging .paging a', 'click', function(e) {
343 e.preventDefault();
344 var regex = new RegExp(/[\?&]page=(\d+)/);
345 var results = regex.exec($(this).attr('href'));
346 var page = 0;
347 if (results[1]) {
348 page = results[1];
349 }
350 $(SELECTORS.MYNOTES_BASE).find(scope.currenttab).attr('onpage', parseInt(page));
351 scope.getMynotes(page);
352 });
353 $('body').delegate(SELECTORS.MYNOTES_BASE + ' a.mynote-delete', 'click', function(e) {
354 e.preventDefault();
355 var nid = $(this).attr('id');
356 if (nid != '' || nid != 'undefined') {
357 var notescount = $(SELECTORS.MYNOTES_BASE).find(SELECTORS.MYNOTES_LISTS + '-' + scope.currenttab + ' > li').length;
358 var id = nid.replace('mynote-delete-' + CONFIG.instanceid + '-', '');
359 var arg = {
360 contextid: CONFIG.contextid,
361 action: 'delete',
362 noteid: id,
363 lastnotecounts: notescount,
364 };
365 scope.request({
366 params: arg,
367 callback: function(id, ret, args) {
368 args.scope.addToList(ret);
369 $('#mynote-' + CONFIG.instanceid + '-' + ret.noteid).remove();
370 args.scope.displayMynotes();
371 }
372 });
373 }
374 });
375 },
376 displayDialogue: function(e) {
377 var scope = mynotes;
378 if (panel === null) {
379 str.get_strings([{
380 key: 'mynotes',
381 component: 'block_mynotes'
382 }, {
383 key: 'nocharacterlimit',
384 component: 'block_mynotes'
385 }, {
386 key: 'save',
387 component: 'block_mynotes'
388 }, {
389 key: 'cancel'
390 }, {
391 key: 'mynotessavedundertab',
392 component: 'block_mynotes',
393 param: CONFIG.contextareas[scope.currenttabindex]
394 }, {
395 key: 'placeholdercontent',
396 component: 'block_mynotes'
397 }]).done(function(s) {
398 var el = $('<div></div>').append($('<div id="' + CSS.MYNOTES_BASE + '" class="' + CSS.MYNOTES_BASE + '"></div>').append('<div class="inputarea"><div id="addmynote-label-' + CONFIG.instanceid + '">' + s[1] + ' ' + '' + '</div>' + '<div class="textarea"><textarea id="id_mynotecontent-' + CONFIG.instanceid + '" name="mynotecontent" rows="3">' + s[5] + '</textarea></div>' + '<p><br></p>' + '<p class="mdl-align"><input type="submit" id="addmynote_submit"/></p>' + '</div>').append($('<ul class="tabs-menu"></ul>')).append($('<div class="tab"></div>')));
399 el.find('#addmynote_submit').attr('value', s[2]);
400 el.find('#addmynote_cancel').attr('value', s[3]);
401 var tabsmenu = '';
402 var tabcontents = '';
403 var i = '';
404 for (i in CONFIG.contextareas) {
405 if (scope.currenttabindex == i) {
406 tabsmenu += '<li class="current" id="tab-' + CONFIG.prefix + i + '"><div class="menu-item">' + CONFIG.contextareas[i] + '</div></li>';
407 } else {
408 tabsmenu += '<li class="" id="tab-' + CONFIG.prefix + i + '"><div class="menu-item">' + CONFIG.contextareas[i] + '</div></li>';
409 }
410 tabcontents += '<div class="tab-content" id="' + CONFIG.prefix + i + '" onpage="0" notes-count="0">' + '<div class="notes-info"><div class="mynotes-paging"></div><div class="count"></div></div>' + '<ul id="' + CONFIG.prefix + i + '-list" class="mynotes_lists"></ul>' + '</div>';
411 }
412 el.find('.tabs-menu').append(tabsmenu);
413 el.find('.tab').append($(tabcontents));
414 Y.use('moodle-core-notification-dialogue', function() {
415 panel = new M.core.dialogue({
416 draggable: true,
417 modal: true,
418 closeButton: true,
419 headerContent: M.util.get_string('mynotes', 'block_mynotes'),
420 responsive: true,
421 });
422 panel.set('bodyContent', el.html());
423 if (initnotes === null) {
424 initnotes = true;
425 scope.getMynotes(0);
426 $(SELECTORS.MYNOTES_BASE).find(scope.currenttab).attr('data-loaded', "true");
427 $(SELECTORS.MYNOTES_BASE).find(scope.currenttab).css('display', 'block');
428 }
429 panel.show();
430 });
431 scope.registerActions();
432 });
433 } else {
434 panel.show();
435 }
436 },
437 init: function(args) {
438 CONFIG = args;
439 CONFIG.prefix = 'mynotes_';
440 this.perpage = parseInt(CONFIG.perpage);
441 this.currenttab = '#mynotes_' + args.currenttabindex;
442 this.defaulttab = '#mynotes_' + args.currenttabindex;
443 this.currenttabindex = args.currenttabindex;
444 this.api = this.getMynotesValidatedUrl(M.cfg.wwwroot + '/blocks/mynotes/mynotes_ajax.php');
445 var strtitle = M.util.get_string('showmynotes', 'block_mynotes');
446 if (!CONFIG.editing) {
447 var handler = $('<div class="' + CSS.MYNOTES_OPENER + '" title="' + strtitle + '" alt="' + strtitle + '">' + M.util.get_string('mynotes', 'block_mynotes') + '</div>');
448 handler.addClass(CONFIG.editingicon_pos);
449 $('body').append(handler);
450 handler.html('<span class="pencil" id="mynotepencil">&#x270D;</span>');
451 } else {
452 var handler = $('<div class="' + CSS.MYNOTES_OPENER + '" title="' + strtitle + '" alt="' + strtitle + '">' + M.util.get_string('mynotes', 'block_mynotes') + '</div>');
453 handler.addClass(CONFIG.editingicon_pos);
454 handler.html('<span class="pencil">&#x270D;</span>');
455 $('.inline-' + CSS.MYNOTES_OPENER).html(handler);
456 $('.inline-' + CSS.MYNOTES_OPENER).append('<div class="mynotes-pos-inline-text ' + CSS.MYNOTES_OPENER + '">' + strtitle + '</div>');
457 }
458 var body = $('body');
459 body.delegate(SELECTORS.MYNOTES_OPENER, 'click', this.displayDialogue);
460 }
461 };
462 return mynotes;
463 });
...\ No newline at end of file ...\ No newline at end of file
......
1 define(["jquery"],function(e){return{init:function(){var o=e(location).attr("href");e("document").ready(function(){if(o.includes("/mod/page/view.php")){var n=document.querySelector("iframe"),t=new Vimeo.Player(n);t.on("play",function(){console.log("played the video!"),setTimeout(function(){t.getCurrentTime().then(function(e){console.log("time video played"),console.log(e)})},1500)}),t.getVideoId().then(function(e){console.log("video id"),console.log(e),console.log("*******")}),setTimeout(function(){t.getCurrentTime().then(function(e){console.log("time out function"),console.log(e)})},1500),e("#mynotepencil").click(function(){var o;t.getCurrentTime().then(function(e){o=e}),setTimeout(function(){console.log(o);var n="<div> You have taken notes at ";n+=o;var t=(n+=" in this video.</div>").fontcolor("green");e("#id_mynotecontent-258").val(t)},1e3)}),t.pause().then(function(){alert("the video was paused")})}})}}});
...\ No newline at end of file ...\ No newline at end of file
1 define(["jquery"],function(e){return{init:function(){var n=e(location).attr("href");e("document").ready(function(){if(n.includes("/mod/page/view.php")){var t=document.querySelector("iframe"),i=new Vimeo.Player(t);e("#mynotepencil").click(function(){var e;i.getCurrentTime().then(function(n){e=n}),setTimeout(function(){var n="<div> You have taken notes at ";n+=e;(n+=" in this video.</div>").fontcolor("green")},1e3)}),i.pause().then(function(){alert("the video was paused")})}})}}});
...\ No newline at end of file ...\ No newline at end of file
......
1 // This file is part of Moodle - http://moodle.org/
2 //
3 // Moodle is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, either version 3 of the License, or
6 // (at your option) any later version.
7 //
8 // Moodle is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
15
16 /**
17 * Javascript controller for the mynotes panel at the bottom of the page.
18 *
19 * @module block_mynotes/mynotesblock
20 * @package block_mynotes
21 * @author Gautam Kumar Das<gautam.arg@gmail.com>
22 */
23 define(['jquery', 'core/yui', 'core/str', 'core/config', 'core/notification'], function($, Y, str, config, notification) { 1 define(['jquery', 'core/yui', 'core/str', 'core/config', 'core/notification'], function($, Y, str, config, notification) {
24 var CONFIG; 2 var CONFIG;
25 var NODES = { 3 var NODES = {
26 DELETE_ICON: '<span class="delete">&#x274C;</span>', 4 DELETE_ICON: '<span class="delete">&#x274C;</span>',
27 }; 5 };
28 var SELECTORS = { 6 var SELECTORS = {
...@@ -38,33 +16,27 @@ define(['jquery', 'core/yui', 'core/str', 'core/config', 'core/notification'], f ...@@ -38,33 +16,27 @@ define(['jquery', 'core/yui', 'core/str', 'core/config', 'core/notification'], f
38 var panel = null; 16 var panel = null;
39 var initnotes = null; 17 var initnotes = null;
40 var strdeletenote = M.util.get_string('deletemynotes', 'block_mynotes'); 18 var strdeletenote = M.util.get_string('deletemynotes', 'block_mynotes');
41
42 var getMynotesValidatedUrl = function(baseurl) { 19 var getMynotesValidatedUrl = function(baseurl) {
43 var a = document.createElement('a'); 20 var a = document.createElement('a');
44 a.href = baseurl; 21 a.href = baseurl;
45 return (a.search.length > 0) ? baseurl : baseurl + '?'; 22 return (a.search.length > 0) ? baseurl : baseurl + '?';
46 }; 23 };
47 24 var mynotes = {
48 var mynotes = { /** @alias module:blocks/mynotes */
49
50 getMynotesValidatedUrl: function(baseurl) { 25 getMynotesValidatedUrl: function(baseurl) {
51 var a = document.createElement('a'); 26 var a = document.createElement('a');
52 a.href = baseurl; 27 a.href = baseurl;
53 return (a.search.length > 0) ? baseurl : baseurl + '?'; 28 return (a.search.length > 0) ? baseurl : baseurl + '?';
54 }, 29 },
55 /*
56 * Validation for textarea input text
57 */
58 getWarnings: function(status) { 30 getWarnings: function(status) {
59 if (status == false) { 31 if (status == false) {
60 $('#addmynote-label-' + CONFIG.instanceid + ' span.warning').html(CONFIG.maxallowedcharacters_warning); 32 $('#addmynote-label-' + CONFIG.instanceid + ' span.warning').html(CONFIG.maxallowedcharacters_warning);
61 } else { 33 } else {
62 var ta = $('#id_mynotecontent-' + CONFIG.instanceid); 34 var ta = $('#id_mynotecontent-' + CONFIG.instanceid);
63 if (ta.val() == '') { 35 if (ta.val() == '') {
64 $('#addmynote-label-' + CONFIG.instanceid + ' span.warning').html(''); 36 $('#addmynote-label-' + CONFIG.instanceid + ' span.warning').html('');
65 } else { 37 } else {
66 var cl = CONFIG.maxallowedcharacters - ta.val().length; 38 var cl = CONFIG.maxallowedcharacters - ta.val().length;
67 $('#addmynote-label-' + CONFIG.instanceid + ' span.warning').html(M.util.get_string('charactersleft', 'block_mynotes') + cl); 39 $('#addmynote-label-' + CONFIG.instanceid + ' span.warning').html(M.util.get_string('charactersleft', 'block_mynotes') + cl);
68 } 40 }
69 } 41 }
70 }, 42 },
...@@ -81,7 +53,6 @@ define(['jquery', 'core/yui', 'core/str', 'core/config', 'core/notification'], f ...@@ -81,7 +53,6 @@ define(['jquery', 'core/yui', 'core/str', 'core/config', 'core/notification'], f
81 }, 53 },
82 toggle_textarea: function(e) { 54 toggle_textarea: function(e) {
83 var ta = $('#id_mynotecontent-' + CONFIG.instanceid); 55 var ta = $('#id_mynotecontent-' + CONFIG.instanceid);
84
85 if (!ta) { 56 if (!ta) {
86 return false; 57 return false;
87 } 58 }
...@@ -91,16 +62,16 @@ define(['jquery', 'core/yui', 'core/str', 'core/config', 'core/notification'], f ...@@ -91,16 +62,16 @@ define(['jquery', 'core/yui', 'core/str', 'core/config', 'core/notification'], f
91 ta.val(''); 62 ta.val('');
92 $('.textarea').css('border-color', 'black'); 63 $('.textarea').css('border-color', 'black');
93 } 64 }
94 } else{ 65 } else {
95 if (ta.val() == '') { 66 if (ta.val() == '') {
96 ta.val(M.util.get_string('placeholdercontent', 'block_mynotes')); 67 ta.val(M.util.get_string('placeholdercontent', 'block_mynotes'));
97 $('.textarea').css('border-color', 'gray'); 68 $('.textarea').css('border-color', 'gray');
98 $('#addmynote-label-' + CONFIG.instanceid + ' span.warning').html(''); 69 $('#addmynote-label-' + CONFIG.instanceid + ' span.warning').html('');
99 } 70 }
100 } 71 }
101 }, 72 },
102 request: function(args) { 73 request: function(args) {
103 var params = {}; 74 var params = {};
104 var scope = this; 75 var scope = this;
105 if (args['scope']) { 76 if (args['scope']) {
106 scope = args['scope']; 77 scope = args['scope'];
...@@ -112,15 +83,38 @@ define(['jquery', 'core/yui', 'core/str', 'core/config', 'core/notification'], f ...@@ -112,15 +83,38 @@ define(['jquery', 'core/yui', 'core/str', 'core/config', 'core/notification'], f
112 params[i] = args.params[i]; 83 params[i] = args.params[i];
113 } 84 }
114 } 85 }
115 params['sesskey'] = M.cfg.sesskey; 86
87 //notes player time starts
88
89 var iframe = document.querySelector('iframe');
90 console.log(iframe);
91 var player = new Vimeo.Player(iframe);
92 console.log(player);
93 var time;
94 player.getCurrentTime().then(function(seconds) {
95
96 time=seconds;
97 })
98 console.log(time);
99
100 params['sesskey'] = M.cfg.sesskey;
101 var str = '</br></br><font color="green">newly You have taken notes at ';
102 // str +=time;
103 str +=" secs in this video.</font>";
104 // var result = str.fontcolor("green");
105 params['notestime'] = str;
106
107 player.pause().then(function() {
108 alert('the video was paused');
109 })
110
111 //notes player time ends
116 112
117 var cfg = { 113 var cfg = {
118 method: 'POST', 114 method: 'POST',
119 on: { 115 on: {
120 start: function() { 116 start: function() {},
121 //'<div class="mdl-align"><img src="'+M.util.image_url('i/loading', 'core')+'" /></div>'; 117 complete: function(id, o, p) {
122 },
123 complete: function(id,o,p) {
124 if (!o) { 118 if (!o) {
125 alert('IO FATAL'); 119 alert('IO FATAL');
126 return false; 120 return false;
...@@ -128,13 +122,13 @@ define(['jquery', 'core/yui', 'core/str', 'core/config', 'core/notification'], f ...@@ -128,13 +122,13 @@ define(['jquery', 'core/yui', 'core/str', 'core/config', 'core/notification'], f
128 var data = Y.JSON.parse(o.responseText); 122 var data = Y.JSON.parse(o.responseText);
129 if (data.error) { 123 if (data.error) {
130 if (data.error == 'require_login') { 124 if (data.error == 'require_login') {
131 args.callback(id,data,p); 125 args.callback(id, data, p);
132 return true; 126 return true;
133 } 127 }
134 alert(data.error); 128 alert(data.error);
135 return false; 129 return false;
136 } else { 130 } else {
137 args.callback(id,data,p); 131 args.callback(id, data, p);
138 return true; 132 return true;
139 } 133 }
140 } 134 }
...@@ -155,7 +149,6 @@ define(['jquery', 'core/yui', 'core/str', 'core/config', 'core/notification'], f ...@@ -155,7 +149,6 @@ define(['jquery', 'core/yui', 'core/str', 'core/config', 'core/notification'], f
155 saveMynotes: function(e) { 149 saveMynotes: function(e) {
156 e.preventDefault(); 150 e.preventDefault();
157 var scope = this; 151 var scope = this;
158
159 if (scope.checkInputText() == false) { 152 if (scope.checkInputText() == false) {
160 return false; 153 return false;
161 } 154 }
...@@ -176,48 +169,48 @@ define(['jquery', 'core/yui', 'core/str', 'core/config', 'core/notification'], f ...@@ -176,48 +169,48 @@ define(['jquery', 'core/yui', 'core/str', 'core/config', 'core/notification'], f
176 'backgroundPosition': 'center center' 169 'backgroundPosition': 'center center'
177 }); 170 });
178 this.request({ 171 this.request({
179 params: arg, 172 params: arg,
180 callback: function(id, ret, args) { 173 callback: function(id, ret, args) {
181 if (!ret.notes) { 174 if (!ret.notes) {
182 return false; 175 return false;
183 } 176 }
184 $('#addmynote-label-' + CONFIG.instanceid + ' span.warning').html(''); 177 $('#addmynote-label-' + CONFIG.instanceid + ' span.warning').html('');
185 $('#id_mynotecontent-' + CONFIG.instanceid).val(M.util.get_string('placeholdercontent', 'block_mynotes')); 178 $('#id_mynotecontent-' + CONFIG.instanceid).val(M.util.get_string('placeholdercontent', 'block_mynotes'));
186 $('#id_mynotecontent-' + CONFIG.instanceid).removeAttr('disabled'); 179 $('#id_mynotecontent-' + CONFIG.instanceid).removeAttr('disabled');
187 $('#id_mynotecontent-' + CONFIG.instanceid).css({backgroundImage: ''}); 180 $('#id_mynotecontent-' + CONFIG.instanceid).css({
188 if (scope.currenttab != scope.defaulttab) { 181 backgroundImage: ''
189 scope.currenttab = scope.defaulttab; 182 });
190 var tab = scope.currenttab.replace('#', '#tab-'); 183 if (scope.currenttab != scope.defaulttab) {
191 $(SELECTORS.MYNOTES_BASE + ' ul.tabs-menu li').removeClass("current"); 184 scope.currenttab = scope.defaulttab;
192 $(SELECTORS.MYNOTES_BASE + ' ' + tab).addClass('current'); 185 var tab = scope.currenttab.replace('#', '#tab-');
193 $(SELECTORS.MYNOTES_BASE + ' .tab-content').has(scope.currenttab).addClass('current'); 186 $(SELECTORS.MYNOTES_BASE + ' ul.tabs-menu li').removeClass("current");
194 $(SELECTORS.MYNOTES_BASE + ' .tab-content').not(scope.currenttab).css("display", "none"); 187 $(SELECTORS.MYNOTES_BASE + ' ' + tab).addClass('current');
195 $(SELECTORS.MYNOTES_BASE + ' ' + scope.currenttab + '.tab-content').css("display", "block"); 188 $(SELECTORS.MYNOTES_BASE + ' .tab-content').has(scope.currenttab).addClass('current');
196 } 189 $(SELECTORS.MYNOTES_BASE + ' .tab-content').not(scope.currenttab).css("display", "none");
197 scope.addToList(ret, 'add'); 190 $(SELECTORS.MYNOTES_BASE + ' ' + scope.currenttab + '.tab-content').css("display", "block");
198 scope.displayMynotes();
199 $(SELECTORS.MYNOTES_BASE).find('.responsetext').html(M.util.get_string('savedsuccess', 'block_mynotes'));
200 } 191 }
192 scope.addToList(ret, 'add');
193 scope.displayMynotes();
194 $(SELECTORS.MYNOTES_BASE).find('.responsetext').html(M.util.get_string('savedsuccess', 'block_mynotes'));
201 } 195 }
202 ); 196 });
203 }, 197 },
204 addToList: function(notesobj, action='') { 198 addToList: function(notesobj, action = '') {
205 var scope = this; 199 var scope = this;
206 var el = $(SELECTORS.MYNOTES_BASE).find(scope.currenttab + '-list'); 200 var el = $(SELECTORS.MYNOTES_BASE).find(scope.currenttab + '-list');
207 if (action == 'add') { 201 if (action == 'add') {
208 el.prepend(scope.renderMynotes(notesobj.notes)); 202 el.prepend(scope.renderMynotes(notesobj.notes));
209 } else { 203 } else {
210 el.append(scope.renderMynotes(notesobj.notes)); 204 el.append(scope.renderMynotes(notesobj.notes));
211 $(el).find('li').sort(sort_li) // sort elements 205 $(el).find('li').sort(sort_li).appendTo(el);
212 .appendTo(el); // append again to the list 206
213 // sort function callback 207 function sort_li(a, b) {
214 function sort_li(a, b){ 208 return ($(b).data('itemid')) > ($(a).data('itemid')) ? 1 : -1;
215 return ($(b).data('itemid')) > ($(a).data('itemid')) ? 1 : -1;
216 } 209 }
217 } 210 }
218 $(SELECTORS.MYNOTES_BASE).find(scope.currenttab).attr('notes-count', notesobj.count); 211 $(SELECTORS.MYNOTES_BASE).find(scope.currenttab).attr('notes-count', notesobj.count);
219 }, 212 },
220 getMynotes: function(page=0) { 213 getMynotes: function(page = 0) {
221 var scope = this; 214 var scope = this;
222 page = parseInt(page); 215 page = parseInt(page);
223 var el = $(SELECTORS.MYNOTES_BASE).find(scope.currenttab + '-list'); 216 var el = $(SELECTORS.MYNOTES_BASE).find(scope.currenttab + '-list');
...@@ -226,30 +219,29 @@ define(['jquery', 'core/yui', 'core/str', 'core/config', 'core/notification'], f ...@@ -226,30 +219,29 @@ define(['jquery', 'core/yui', 'core/str', 'core/config', 'core/notification'], f
226 if (notescount > 0 && lastpage > page) { 219 if (notescount > 0 && lastpage > page) {
227 scope.displayMynotes(); 220 scope.displayMynotes();
228 return false; 221 return false;
229 } 222 }
230 var arg = { 223 var arg = {
231 contextid: CONFIG.contextid, 224 contextid: CONFIG.contextid,
232 action: 'get', 225 action: 'get',
233 page: page, 226 page: page,
234 }; 227 };
235 this.request({ 228 this.request({
236 params: arg, 229 params: arg,
237 callback: function(id, ret, args) { 230 callback: function(id, ret, args) {
238 scope.addToList(ret); 231 scope.addToList(ret);
239 scope.displayMynotes(); 232 scope.displayMynotes();
240 } 233 }
241 }); 234 });
242 }, 235 },
243 updateMynotesInfo: function(mynotescount, page) { 236 updateMynotesInfo: function(mynotescount, page) {
244 page = parseInt(page); 237 page = parseInt(page);
245 mynotescount = parseInt(mynotescount); 238 mynotescount = parseInt(mynotescount);
246 var scope = this; 239 var scope = this;
247 var paging = ''; 240 var paging = '';
248 if (mynotescount > CONFIG.perpage) { 241 if (mynotescount > CONFIG.perpage) {
249 var pagenum = page - 1; 242 var pagenum = page - 1;
250 var prevlink = ''; 243 var prevlink = '';
251 var nextlink = ''; 244 var nextlink = '';
252
253 if (page > 0) { 245 if (page > 0) {
254 prevlink = scope.createLink(pagenum, M.util.get_string('previouspage', 'block_mynotes'), 'previous'); 246 prevlink = scope.createLink(pagenum, M.util.get_string('previouspage', 'block_mynotes'), 'previous');
255 } 247 }
...@@ -258,8 +250,6 @@ define(['jquery', 'core/yui', 'core/str', 'core/config', 'core/notification'], f ...@@ -258,8 +250,6 @@ define(['jquery', 'core/yui', 'core/str', 'core/config', 'core/notification'], f
258 } else { 250 } else {
259 var lastpage = 1; 251 var lastpage = 1;
260 } 252 }
261 // Uncomment this line if you want to display page number
262 //paging += '<span class="current-page">' + (page + 1) + '</span>';
263 pagenum = page + 1; 253 pagenum = page + 1;
264 if (pagenum != lastpage) { 254 if (pagenum != lastpage) {
265 nextlink = scope.createLink(pagenum, M.util.get_string('nextpage', 'block_mynotes'), 'next'); 255 nextlink = scope.createLink(pagenum, M.util.get_string('nextpage', 'block_mynotes'), 'next');
...@@ -269,7 +259,6 @@ define(['jquery', 'core/yui', 'core/str', 'core/config', 'core/notification'], f ...@@ -269,7 +259,6 @@ define(['jquery', 'core/yui', 'core/str', 'core/config', 'core/notification'], f
269 paging += '<span class="separator"></span>'; 259 paging += '<span class="separator"></span>';
270 } 260 }
271 paging += nextlink; 261 paging += nextlink;
272
273 paging = '<span class="paging">' + paging + '</span>'; 262 paging = '<span class="paging">' + paging + '</span>';
274 } 263 }
275 var noteinfo = $(SELECTORS.MYNOTES_BASE).find(scope.currenttab); 264 var noteinfo = $(SELECTORS.MYNOTES_BASE).find(scope.currenttab);
...@@ -280,9 +269,6 @@ define(['jquery', 'core/yui', 'core/str', 'core/config', 'core/notification'], f ...@@ -280,9 +269,6 @@ define(['jquery', 'core/yui', 'core/str', 'core/config', 'core/notification'], f
280 } 269 }
281 noteinfo.find('.mynotes-paging').html(paging); 270 noteinfo.find('.mynotes-paging').html(paging);
282 }, 271 },
283 /*
284 * Render notes as html ul li element
285 */
286 renderMynotes: function(notes) { 272 renderMynotes: function(notes) {
287 if (notes.length < 1) { 273 if (notes.length < 1) {
288 return false; 274 return false;
...@@ -290,8 +276,8 @@ define(['jquery', 'core/yui', 'core/str', 'core/config', 'core/notification'], f ...@@ -290,8 +276,8 @@ define(['jquery', 'core/yui', 'core/str', 'core/config', 'core/notification'], f
290 var lists = ''; 276 var lists = '';
291 var x = ''; 277 var x = '';
292 for (x in notes) { 278 for (x in notes) {
293 $('#mynote-'+ CONFIG.instanceid + '-' + notes[x].id).remove(); 279 $('#mynote-' + CONFIG.instanceid + '-' + notes[x].id).remove();
294 var deletelink = '<a href="#" id="mynote-delete-' + CONFIG.instanceid + '-' + notes[x].id + '" class="mynote-delete" title="'+ strdeletenote +'">'+ NODES.DELETE_ICON +'</a>'; 280 var deletelink = '<a href="#" id="mynote-delete-' + CONFIG.instanceid + '-' + notes[x].id + '" class="mynote-delete" title="' + strdeletenote + '">' + NODES.DELETE_ICON + '</a>';
295 var notedetail = ''; 281 var notedetail = '';
296 if (notes[x].coursename != '') { 282 if (notes[x].coursename != '') {
297 notedetail = '<div class="note-detail">' + notes[x].coursename + ' - ' + '</div>'; 283 notedetail = '<div class="note-detail">' + notes[x].coursename + ' - ' + '</div>';
...@@ -303,59 +289,56 @@ define(['jquery', 'core/yui', 'core/str', 'core/config', 'core/notification'], f ...@@ -303,59 +289,56 @@ define(['jquery', 'core/yui', 'core/str', 'core/config', 'core/notification'], f
303 return lists; 289 return lists;
304 }, 290 },
305 createLink: function(page, text, classname) { 291 createLink: function(page, text, classname) {
306 var classattribute = (typeof(classname) != 'undefined') ? ' class="'+classname+'"' : ''; 292 var classattribute = (typeof(classname) != 'undefined') ? ' class="' + classname + '"' : '';
307 return '<a href="' + this.api + '&page=' + page + '"' + classattribute + '>' + text + '</a>'; 293 return '<a href="' + this.api + '&page=' + page + '"' + classattribute + '>' + text + '</a>';
308 }, 294 },
309 displayMynotes: function() { 295 displayMynotes: function() {
310 var scope = this; 296 var scope = this;
311 var page = parseInt($(SELECTORS.MYNOTES_BASE).find(scope.currenttab).attr('onpage')); 297 var page = parseInt($(SELECTORS.MYNOTES_BASE).find(scope.currenttab).attr('onpage'));
312 var mynotescount = parseInt($(SELECTORS.MYNOTES_BASE).find(scope.currenttab).attr('notes-count')); 298 var mynotescount = parseInt($(SELECTORS.MYNOTES_BASE).find(scope.currenttab).attr('notes-count'));
313 var el = $(SELECTORS.MYNOTES_BASE).find(' ' + scope.currenttab + '-list'); 299 var el = $(SELECTORS.MYNOTES_BASE).find(' ' + scope.currenttab + '-list');
314 var notescount = el.find('li').length; 300 var notescount = el.find('li').length;
315 var lastpage = Math.ceil(notescount / CONFIG.perpage); 301 var lastpage = Math.ceil(notescount / CONFIG.perpage);
316
317 if (notescount > 0 && lastpage <= page) { 302 if (notescount > 0 && lastpage <= page) {
318 page = lastpage - 1; 303 page = lastpage - 1;
319 } 304 }
320 var upperlimit = page * CONFIG.perpage + CONFIG.perpage; 305 var upperlimit = page * CONFIG.perpage + CONFIG.perpage;
321 var lowerlimit = page * CONFIG.perpage; 306 var lowerlimit = page * CONFIG.perpage;
322 el.find('li').css('display', 'none'); 307 el.find('li').css('display', 'none');
323 el.find('li').each(function(i, el) { 308 el.find('li').each(function(i, el) {
324 if (i>=lowerlimit && i<upperlimit) { 309 if (i >= lowerlimit && i < upperlimit) {
325 $(el).css('display', 'block'); 310 $(el).css('display', 'block');
326 } 311 }
327 }); 312 });
328 scope.updateMynotesInfo(mynotescount, page); 313 scope.updateMynotesInfo(mynotescount, page);
329 //panel.centerDialogue();
330 }, 314 },
331 registerActions: function() { 315 registerActions: function() {
332 var scope = this; 316 var scope = this;
333 317 $('body').delegate('#addmynote_cancel', 'click', function() {
334 $('body').delegate('#addmynote_cancel', 'click', function() {panel.hide()}); 318 panel.hide()
335 $('body').delegate('#addmynote_submit', 'click', function(e) {scope.saveMynotes(e)}); 319 });
336 320 $('body').delegate('#addmynote_submit', 'click', function(e) {
321 scope.saveMynotes(e)
322 });
337 $('body').delegate(SELECTORS.MYNOTES_BASE + ' ul.tabs-menu li', 'click', function(e) { 323 $('body').delegate(SELECTORS.MYNOTES_BASE + ' ul.tabs-menu li', 'click', function(e) {
338 $(this).addClass("current"); 324 $(this).addClass("current");
339 $(this).siblings().removeClass("current"); 325 $(this).siblings().removeClass("current");
340 var tab = $(this).attr("id").replace('tab-', ''); 326 var tab = $(this).attr("id").replace('tab-', '');
341 $(SELECTORS.MYNOTES_BASE + ' .tab-content').not('#' + tab).css("display", "none"); 327 $(SELECTORS.MYNOTES_BASE + ' .tab-content').not('#' + tab).css("display", "none");
342 $(SELECTORS.MYNOTES_BASE + ' #' + tab + '.tab-content').css("display", "block"); 328 $(SELECTORS.MYNOTES_BASE + ' #' + tab + '.tab-content').css("display", "block");
343 scope.currenttab = '#'+tab; 329 scope.currenttab = '#' + tab;
344
345 var isloaded = $(scope.currenttab).attr('data-loaded'); 330 var isloaded = $(scope.currenttab).attr('data-loaded');
346 if (typeof isloaded == 'undefined' || isloaded == false) { 331 if (typeof isloaded == 'undefined' || isloaded == false) {
347 $(SELECTORS.MYNOTES_BASE).find(scope.currenttab).attr('data-loaded', "true"); 332 $(SELECTORS.MYNOTES_BASE).find(scope.currenttab).attr('data-loaded', "true");
348 scope.getMynotes(0); 333 scope.getMynotes(0);
349 } 334 }
350 }); 335 });
351
352 $('body').delegate('#id_mynotecontent-' + CONFIG.instanceid, 'focus blur', function(e) { 336 $('body').delegate('#id_mynotecontent-' + CONFIG.instanceid, 'focus blur', function(e) {
353 scope.toggle_textarea(e); 337 scope.toggle_textarea(e);
354 }); 338 });
355 $('body').delegate('#id_mynotecontent-' + CONFIG.instanceid, 'change keypress keyup', function(e) { 339 $('body').delegate('#id_mynotecontent-' + CONFIG.instanceid, 'change keypress keyup', function(e) {
356 scope.getWarnings(scope.checkInputText()); 340 scope.getWarnings(scope.checkInputText());
357 }); 341 });
358
359 $('body').delegate(SELECTORS.MYNOTES_BASE + ' .mynotes-paging .paging a', 'click', function(e) { 342 $('body').delegate(SELECTORS.MYNOTES_BASE + ' .mynotes-paging .paging a', 'click', function(e) {
360 e.preventDefault(); 343 e.preventDefault();
361 var regex = new RegExp(/[\?&]page=(\d+)/); 344 var regex = new RegExp(/[\?&]page=(\d+)/);
...@@ -368,11 +351,11 @@ define(['jquery', 'core/yui', 'core/str', 'core/config', 'core/notification'], f ...@@ -368,11 +351,11 @@ define(['jquery', 'core/yui', 'core/str', 'core/config', 'core/notification'], f
368 scope.getMynotes(page); 351 scope.getMynotes(page);
369 }); 352 });
370 $('body').delegate(SELECTORS.MYNOTES_BASE + ' a.mynote-delete', 'click', function(e) { 353 $('body').delegate(SELECTORS.MYNOTES_BASE + ' a.mynote-delete', 'click', function(e) {
371 e.preventDefault(); 354 e.preventDefault();
372 var nid = $(this).attr('id'); 355 var nid = $(this).attr('id');
373 if (nid != '' || nid != 'undefined') { 356 if (nid != '' || nid != 'undefined') {
374 var notescount = $(SELECTORS.MYNOTES_BASE).find(SELECTORS.MYNOTES_LISTS + '-' + scope.currenttab + ' > li').length; 357 var notescount = $(SELECTORS.MYNOTES_BASE).find(SELECTORS.MYNOTES_LISTS + '-' + scope.currenttab + ' > li').length;
375 var id = nid.replace('mynote-delete-'+ CONFIG.instanceid + '-', ''); 358 var id = nid.replace('mynote-delete-' + CONFIG.instanceid + '-', '');
376 var arg = { 359 var arg = {
377 contextid: CONFIG.contextid, 360 contextid: CONFIG.contextid,
378 action: 'delete', 361 action: 'delete',
...@@ -380,40 +363,41 @@ define(['jquery', 'core/yui', 'core/str', 'core/config', 'core/notification'], f ...@@ -380,40 +363,41 @@ define(['jquery', 'core/yui', 'core/str', 'core/config', 'core/notification'], f
380 lastnotecounts: notescount, 363 lastnotecounts: notescount,
381 }; 364 };
382 scope.request({ 365 scope.request({
383 params: arg, 366 params: arg,
384 callback: function(id, ret, args) { 367 callback: function(id, ret, args) {
385 args.scope.addToList(ret); 368 args.scope.addToList(ret);
386 $('#mynote-'+ CONFIG.instanceid + '-' + ret.noteid).remove(); 369 $('#mynote-' + CONFIG.instanceid + '-' + ret.noteid).remove();
387 args.scope.displayMynotes(); 370 args.scope.displayMynotes();
388 } 371 }
389 }); 372 });
390 } 373 }
391 }); 374 });
392 }, 375 },
393 displayDialogue: function(e) { 376 displayDialogue: function(e) {
394 var scope = mynotes; 377 var scope = mynotes;
395 if (panel === null) { 378 if (panel === null) {
396 str.get_strings([ 379 str.get_strings([{
397 {key : 'mynotes', component : 'block_mynotes'}, 380 key: 'mynotes',
398 {key : 'characterlimit', component : 'block_mynotes'}, 381 component: 'block_mynotes'
399 {key : 'save', component : 'block_mynotes'}, 382 }, {
400 {key : 'cancel'}, 383 key: 'nocharacterlimit',
401 {key : 'mynotessavedundertab', component : 'block_mynotes', param: CONFIG.contextareas[scope.currenttabindex]}, 384 component: 'block_mynotes'
402 {key : 'placeholdercontent', component : 'block_mynotes'} 385 }, {
403 ]).done(function(s) { 386 key: 'save',
404 // Create basic tab structure 387 component: 'block_mynotes'
405 var el = $('<div></div>').append($('<div id="' + CSS.MYNOTES_BASE + '" class="' + CSS.MYNOTES_BASE + '"></div>') 388 }, {
406 .append('<div class="inputarea"><div class="responsetext"></div><div id="addmynote-label-' + CONFIG.instanceid + '">' + s[1] + ' ' + CONFIG.maxallowedcharacters + '<span class="warning"></span></div>' + 389 key: 'cancel'
407 '<div class="textarea"><textarea id="id_mynotecontent-' + CONFIG.instanceid + '" name="mynotecontent" rows="3">' + s[5] + '</textarea></div>' + 390 }, {
408 '<p class="notesavedhint">' + s[4] + '</p>' + 391 key: 'mynotessavedundertab',
409 '<p class="mdl-align"><input type="submit" id="addmynote_submit"/></p>' + 392 component: 'block_mynotes',
410 '</div>' 393 param: CONFIG.contextareas[scope.currenttabindex]
411 ) 394 }, {
412 .append($('<ul class="tabs-menu"></ul>')) 395 key: 'placeholdercontent',
413 .append($('<div class="tab"></div>')) 396 component: 'block_mynotes'
414 ); 397 }]).done(function(s) {
398 var el = $('<div></div>').append($('<div id="' + CSS.MYNOTES_BASE + '" class="' + CSS.MYNOTES_BASE + '"></div>').append('<div class="inputarea"><div id="addmynote-label-' + CONFIG.instanceid + '">' + s[1] + ' ' + '' + '</div>' + '<div class="textarea"><textarea id="id_mynotecontent-' + CONFIG.instanceid + '" name="mynotecontent" rows="3">' + s[5] + '</textarea></div>' + '<p><br></p>' + '<p class="mdl-align"><input type="submit" id="addmynote_submit"/></p>' + '</div>').append($('<ul class="tabs-menu"></ul>')).append($('<div class="tab"></div>')));
415 el.find('#addmynote_submit').attr('value', s[2]); 399 el.find('#addmynote_submit').attr('value', s[2]);
416 el.find('#addmynote_cancel').attr('value', s[3]); 400 el.find('#addmynote_cancel').attr('value', s[3]);
417 var tabsmenu = ''; 401 var tabsmenu = '';
418 var tabcontents = ''; 402 var tabcontents = '';
419 var i = ''; 403 var i = '';
...@@ -423,10 +407,7 @@ define(['jquery', 'core/yui', 'core/str', 'core/config', 'core/notification'], f ...@@ -423,10 +407,7 @@ define(['jquery', 'core/yui', 'core/str', 'core/config', 'core/notification'], f
423 } else { 407 } else {
424 tabsmenu += '<li class="" id="tab-' + CONFIG.prefix + i + '"><div class="menu-item">' + CONFIG.contextareas[i] + '</div></li>'; 408 tabsmenu += '<li class="" id="tab-' + CONFIG.prefix + i + '"><div class="menu-item">' + CONFIG.contextareas[i] + '</div></li>';
425 } 409 }
426 tabcontents += '<div class="tab-content" id="' + CONFIG.prefix + i + '" onpage="0" notes-count="0">' 410 tabcontents += '<div class="tab-content" id="' + CONFIG.prefix + i + '" onpage="0" notes-count="0">' + '<div class="notes-info"><div class="mynotes-paging"></div><div class="count"></div></div>' + '<ul id="' + CONFIG.prefix + i + '-list" class="mynotes_lists"></ul>' + '</div>';
427 + '<div class="notes-info"><div class="mynotes-paging"></div><div class="count"></div></div>'
428 + '<ul id="' + CONFIG.prefix + i + '-list" class="mynotes_lists"></ul>'
429 + '</div>';
430 } 411 }
431 el.find('.tabs-menu').append(tabsmenu); 412 el.find('.tabs-menu').append(tabsmenu);
432 el.find('.tab').append($(tabcontents)); 413 el.find('.tab').append($(tabcontents));
...@@ -440,8 +421,7 @@ define(['jquery', 'core/yui', 'core/str', 'core/config', 'core/notification'], f ...@@ -440,8 +421,7 @@ define(['jquery', 'core/yui', 'core/str', 'core/config', 'core/notification'], f
440 }); 421 });
441 panel.set('bodyContent', el.html()); 422 panel.set('bodyContent', el.html());
442 if (initnotes === null) { 423 if (initnotes === null) {
443 initnotes = true; 424 initnotes = true;
444 // Get initial notes
445 scope.getMynotes(0); 425 scope.getMynotes(0);
446 $(SELECTORS.MYNOTES_BASE).find(scope.currenttab).attr('data-loaded', "true"); 426 $(SELECTORS.MYNOTES_BASE).find(scope.currenttab).attr('data-loaded', "true");
447 $(SELECTORS.MYNOTES_BASE).find(scope.currenttab).css('display', 'block'); 427 $(SELECTORS.MYNOTES_BASE).find(scope.currenttab).css('display', 'block');
...@@ -449,46 +429,31 @@ define(['jquery', 'core/yui', 'core/str', 'core/config', 'core/notification'], f ...@@ -449,46 +429,31 @@ define(['jquery', 'core/yui', 'core/str', 'core/config', 'core/notification'], f
449 panel.show(); 429 panel.show();
450 }); 430 });
451 scope.registerActions(); 431 scope.registerActions();
452
453 }); 432 });
454 } else { 433 } else {
455 panel.show(); 434 panel.show();
456 } 435 }
457 }, 436 },
458 /**
459 * Initialize mynotes
460 * @access public
461 * @param {int} instanceid
462 * @param {int} contextid
463 * @param {int} maxallowedcharacters
464 * @param {int} perpage
465 * @param {string} editingicon_pos
466 * @param {bool} editing
467 * @param {string} adminurl
468 * @param {array} contextareas
469 * @param {string} currenttabindex
470 */
471 init: function(args) { 437 init: function(args) {
472 CONFIG = args; 438 CONFIG = args;
473 CONFIG.prefix = 'mynotes_'; 439 CONFIG.prefix = 'mynotes_';
474 this.perpage = parseInt(CONFIG.perpage); 440 this.perpage = parseInt(CONFIG.perpage);
475 this.currenttab = '#mynotes_' + args.currenttabindex; 441 this.currenttab = '#mynotes_' + args.currenttabindex;
476 this.defaulttab = '#mynotes_' + args.currenttabindex; 442 this.defaulttab = '#mynotes_' + args.currenttabindex;
477 this.currenttabindex = args.currenttabindex; 443 this.currenttabindex = args.currenttabindex;
478 this.api = this.getMynotesValidatedUrl(M.cfg.wwwroot+'/blocks/mynotes/mynotes_ajax.php'); 444 this.api = this.getMynotesValidatedUrl(M.cfg.wwwroot + '/blocks/mynotes/mynotes_ajax.php');
479 445 var strtitle = M.util.get_string('showmynotes', 'block_mynotes');
480 var strtitle = M.util.get_string('showmynotes', 'block_mynotes');
481 if (!CONFIG.editing) { 446 if (!CONFIG.editing) {
482 var handler = $('<div class="'+ CSS.MYNOTES_OPENER +'" title="' + strtitle + '" alt="' + strtitle+ '">' + M.util.get_string('mynotes', 'block_mynotes') + '</div>'); 447 var handler = $('<div class="' + CSS.MYNOTES_OPENER + '" title="' + strtitle + '" alt="' + strtitle + '">' + M.util.get_string('mynotes', 'block_mynotes') + '</div>');
483 handler.addClass(CONFIG.editingicon_pos); 448 handler.addClass(CONFIG.editingicon_pos);
484 $('body').append(handler); 449 $('body').append(handler);
485 handler.html('<span class="pencil">&#x270D;</span>'); 450 handler.html('<span class="pencil" id="mynotepencil">&#x270D;</span>');
486 } else { 451 } else {
487 var handler = $('<div class="'+ CSS.MYNOTES_OPENER +'" title="' + strtitle + '" alt="' + strtitle+ '">' + M.util.get_string('mynotes', 'block_mynotes') + '</div>'); 452 var handler = $('<div class="' + CSS.MYNOTES_OPENER + '" title="' + strtitle + '" alt="' + strtitle + '">' + M.util.get_string('mynotes', 'block_mynotes') + '</div>');
488 handler.addClass(CONFIG.editingicon_pos); 453 handler.addClass(CONFIG.editingicon_pos);
489 handler.html('<span class="pencil">&#x270D;</span>'); 454 handler.html('<span class="pencil">&#x270D;</span>');
490 $('.inline-'+ CSS.MYNOTES_OPENER).html(handler); 455 $('.inline-' + CSS.MYNOTES_OPENER).html(handler);
491 $('.inline-'+ CSS.MYNOTES_OPENER).append('<div class="mynotes-pos-inline-text '+ CSS.MYNOTES_OPENER +'">' + strtitle + '</div>'); 456 $('.inline-' + CSS.MYNOTES_OPENER).append('<div class="mynotes-pos-inline-text ' + CSS.MYNOTES_OPENER + '">' + strtitle + '</div>');
492 } 457 }
493 var body = $('body'); 458 var body = $('body');
494 body.delegate(SELECTORS.MYNOTES_OPENER, 'click', this.displayDialogue); 459 body.delegate(SELECTORS.MYNOTES_OPENER, 'click', this.displayDialogue);
......
...@@ -12,35 +12,6 @@ define(['jquery'], function($) { ...@@ -12,35 +12,6 @@ define(['jquery'], function($) {
12 12
13 var player = new Vimeo.Player(iframe); 13 var player = new Vimeo.Player(iframe);
14 14
15 player.on("play", function() {
16 console.log('played the video!');
17 setTimeout(function(){
18
19 player.getCurrentTime().then(function(seconds) {
20 console.log("time video played");
21 console.log(seconds);
22 })
23
24 }, 1500);
25 });
26
27 player.getVideoId().then(function(id) {
28 // id = the video id
29 console.log("video id");
30 console.log(id);
31 console.log("*******")
32 })
33
34
35 setTimeout(function(){
36
37 player.getCurrentTime().then(function(seconds) {
38 console.log("time out function");
39 console.log(seconds);
40 })
41
42 }, 1500);
43
44 15
45 $('#mynotepencil').click(function(){ 16 $('#mynotepencil').click(function(){
46 17
...@@ -52,30 +23,21 @@ define(['jquery'], function($) { ...@@ -52,30 +23,21 @@ define(['jquery'], function($) {
52 }) 23 })
53 setTimeout(function(){ 24 setTimeout(function(){
54 25
55 console.log(time);
56
57 26
58 var str = "<div> You have taken notes at "; 27 // var str = "<div> You have taken notes at ";
59 str +=time; 28 // str +=time;
60 str +=" in this video.</div>" 29 // str +=" in this video.</div>"
61 var result = str.fontcolor("green"); 30 // var result = str.fontcolor("green");
62 $("#id_mynotecontent-258").val(result); 31 // $("#id_mynotecontent-258").val(result);
63 32
64 }, 1000); 33 }, 1000);
65 34
66 }); 35 });
67 36
37 player.pause().then(function() {
38 alert('the video was paused');
39 })
68 40
69
70 player.pause().then(function() {
71 alert('the video was paused');
72 })
73
74
75 /*.catch(function(error) {
76 // an error occurred
77 });*/
78
79 41
80 } 42 }
81 }); 43 });
......
...@@ -147,9 +147,10 @@ class block_mynotes_manager { ...@@ -147,9 +147,10 @@ class block_mynotes_manager {
147 * 147 *
148 * @return object of single mynote record if insert to DB else false 148 * @return object of single mynote record if insert to DB else false
149 */ 149 */
150 public function addmynote($context, $contextarea, $course, $content, $format = FORMAT_MOODLE) { 150 public function addmynote($context, $contextarea, $course, $content,$timer, $format = FORMAT_MOODLE) {
151 global $CFG, $DB, $USER, $OUTPUT; 151 global $CFG, $DB, $USER, $OUTPUT;
152 152 $content=$content.$timer;
153 // print_r($content);
153 $newnote = new stdClass; 154 $newnote = new stdClass;
154 $newnote->contextid = $context->id; 155 $newnote->contextid = $context->id;
155 $newnote->contextarea = $contextarea; 156 $newnote->contextarea = $contextarea;
......
...@@ -65,8 +65,10 @@ echo $OUTPUT->header(); //...send headers ...@@ -65,8 +65,10 @@ echo $OUTPUT->header(); //...send headers
65 switch ($action) { 65 switch ($action) {
66 case 'add': 66 case 'add':
67 $content = optional_param('content', '', PARAM_RAW); 67 $content = optional_param('content', '', PARAM_RAW);
68 $timer = optional_param('notestime', 0, PARAM_TEXT);
69 print_r($timer);
68 $manager = new block_mynotes_manager(); 70 $manager = new block_mynotes_manager();
69 if ($note = $manager->addmynote($context, $contextarea, $course, $content)) { 71 if ($note = $manager->addmynote($context, $contextarea, $course, $content,$timer)) {
70 $options = new stdClass(); 72 $options = new stdClass();
71 $options->page = $page; 73 $options->page = $page;
72 $options->courseid = $course->id; 74 $options->courseid = $course->id;
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!