39da5eb9 by logesh

notes plugin

1 parent c1ef11fc
Copyright (c) 2013-2016 GitHub, Inc. and contributors
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\ No newline at end of file
Mynotes Block
--------------
A simpler mynotes system that integrates as moodle block to save user's notes
from different areas such as site, course, modules, etc.
This is a free plugin for Moodle that help to preserve uesr's notes.
Settings
--------
* Set the position for display editing icon.
* Set the number of records to be display
Appearances
----------------------
* This block display on site page, any course-* and user page.
Features
--------
Any authenticated users can:
* Save new notes
* View saved notes by him/her
* Delete own notes
Requirements
------------
* Moodle version 3.4
Installation
------------
Within the ZIP file is a folder named mynotes, copy this folder into
your Moodle blocks folder (e.g /var/moodle/htdocs/blocks/ ). Once the folder
has been copied into your blocks folder, login to Moodle as admin and it should
detect the new block and install it.
Note that if you download the ZIP from Github the mynotes folder is called
'moodle-block_mynotes' and needs to be renamed after extraction to 'mynotes'.
Once installed this block, automatically added to page while installing. There is no need to add to every page.
\ No newline at end of file
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
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Javascript controller for the mynotes panel at the bottom of the page.
*
* @module block_mynotes/mynotesblock
* @package block_mynotes
* @author Gautam Kumar Das<gautam.arg@gmail.com>
*/
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 = { /** @alias module:blocks/mynotes */
getMynotesValidatedUrl: function(baseurl) {
var a = document.createElement('a');
a.href = baseurl;
return (a.search.length > 0) ? baseurl : baseurl + '?';
},
/*
* Validation for textarea input text
*/
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() {
//'<div class="mdl-align"><img src="'+M.util.image_url('i/loading', 'core')+'" /></div>';
},
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) // sort elements
.appendTo(el); // append again to the list
// sort function callback
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;
}
// Uncomment this line if you want to display page number
//paging += '<span class="current-page">' + (page + 1) + '</span>';
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);
},
/*
* Render notes as html ul li element
*/
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);
//panel.centerDialogue();
},
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 : 'characterlimit', 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) {
// Create basic tab structure
var el = $('<div></div>').append($('<div id="' + CSS.MYNOTES_BASE + '" class="' + CSS.MYNOTES_BASE + '"></div>')
.append('<div class="inputarea"><div class="responsetext"></div><div id="addmynote-label-' + CONFIG.instanceid + '">' + s[1] + ' ' + CONFIG.maxallowedcharacters + '<span class="warning"></span></div>' +
'<div class="textarea"><textarea id="id_mynotecontent-' + CONFIG.instanceid + '" name="mynotecontent" rows="2">' + s[5] + '</textarea></div>' +
'<p class="notesavedhint">' + s[4] + '</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;
// Get initial notes
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();
}
},
/**
* Initialize mynotes
* @access public
* @param {int} instanceid
* @param {int} contextid
* @param {int} maxallowedcharacters
* @param {int} perpage
* @param {string} editingicon_pos
* @param {bool} editing
* @param {string} adminurl
* @param {array} contextareas
* @param {string} currenttabindex
*/
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">&#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
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* The mynotes block
*
* @package block_mynotes
* @author Gautam Kumar Das<gautam.arg@gmail.com>
*/
defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot . '/blocks/mynotes/lib.php');
/**
* Mynotes block.
*
* @package block_mynotes
*
*/
class block_mynotes extends block_base {
public function init() {
$this->title = get_string('pluginname', 'block_mynotes');
}
public function has_config() {
return true;
}
public function applicable_formats() {
return array('all' => true);
}
public function instance_allow_multiple() {
return false;
}
public function hide_header() {
global $PAGE;
if (!$PAGE->user_is_editing()) {
return true;
}
}
/**
* The content object.
*
* @return stdObject
*/
public function get_content() {
global $CFG, $PAGE;
static $jscount = 0;
if ($this->content !== null) {
return $this->content;
}
if (!isloggedin() or isguestuser()) {
return ''; // Never useful unless you are logged in as real users
}
if (!in_array($PAGE->context->contextlevel, array(CONTEXT_COURSE, CONTEXT_SYSTEM, CONTEXT_MODULE, CONTEXT_USER))) {
return '';
}
$this->content = new stdClass();
$this->content->footer = '';
$this->content->text = '';
if (empty($this->instance)) {
return $this->content;
}
$this->content = new stdClass();
$this->content->text = '';
if ($PAGE->user_is_editing()) {
$this->content->text = '<div class="inline-mynotes-opener">'.get_string('showmynotes', 'block_mynotes').'</div>';
}
$this->content->footer = '';
if ($jscount == 0) {
$this->block_mynotes_get_required_javascript();
$jscount++;
}
return $this->content;
}
/*
* load JS that requires into the page.
*/
private function block_mynotes_get_required_javascript() {
global $PAGE, $CFG;
list($context, $course, $cm) = get_context_info_array($PAGE->context->id);
$config = get_config('block_mynotes');
$mm = new block_mynotes_manager();
$currenttabindex = $mm->get_current_tab($context, $PAGE);
$arguments = array( 'arg'=> array(
'instanceid' => $this->instance->id,
'editing' => ($PAGE->user_is_editing()),
'editingicon_pos' => ($PAGE->user_is_editing()) ? 'mynotes-pos-inline' : $config->icondisplayposition,
'maxallowedcharacters' => $config->characterlimit,
'contextid' => $context->id,
'maxallowedcharacters_warning' => get_string('notmorethan', 'block_mynotes', $config->characterlimit),
'contextareas' => $mm->get_available_contextareas(),
'currenttabindex' => ($currenttabindex == null ? 'site' : $currenttabindex),
'perpage' => $config->mynotesperpage,
),
);
// $PAGE->requires->string_for_js('charactersleft', 'block_mynotes');
$PAGE->requires->string_for_js('notmorethan', 'block_mynotes');
$PAGE->requires->string_for_js('mynotes', 'block_mynotes');
$PAGE->requires->string_for_js('showmynotes', 'block_mynotes');
$PAGE->requires->string_for_js('savedsuccess', 'block_mynotes');
$PAGE->requires->string_for_js('save', 'block_mynotes');
$PAGE->requires->string_for_js('placeholdercontent', 'block_mynotes');
$PAGE->requires->string_for_js('deletemynotes', 'block_mynotes');
$PAGE->requires->string_for_js('mynotescount', 'block_mynotes');
$PAGE->requires->string_for_js('previouspage', 'block_mynotes');
$PAGE->requires->string_for_js('nextpage', 'block_mynotes');
$PAGE->requires->string_for_js('nothingtodisplay', 'block_mynotes');
$PAGE->requires->string_for_js('mynotessavedundertab', 'block_mynotes');
$PAGE->requires->string_for_js('cancel', 'moodle');
$this->page->requires->js_call_amd('block_mynotes/mynotesblock', 'init', $arguments);
}
}
\ No newline at end of file
if (url.includes('/mod/hvp/')){
$(document).ready(function(){
var m = document.getElementsByClassName("h5p-iv-hotkey-instructions");
console.log(m);
var check=$("div.h5p-iv-hotkey-instructions").html();
var check1=$('div.h5p-iv-hotkey-instructions').text();
console.log(check);
console.log(check1);
setTimeout(function(){
$('#mynotepencil').click(function(){
var check=$('.h5p-iv-hotkey-instructions').html();
var check1=$('.h5p-iv-hotkey-instructions').text();
console.log(check);
console.log(check1);
alert(check);
// var valuetime= $(".h5p-control, .h5p-simple-time, .h5p-current, span.human-time").text();
// var newvalue= $('.h5p-control, .h5p-simple-time, .h5p-current, span.human-time').text();
var valuetime1= $(".h5p-controls-right .h5p-control .h5p-time .h5p-current .human-time").text();
var newvalue1= $('.h5p-controls-right .h5p-control .h5p-time .h5p-current .human-time').text();
// console.log(" click notes"+newvalue);
// var y =$('.human-time').html();
// console.log("first"+valuetime);console.log("second"+newvalue);
console.log("first"+valuetime1);console.log("second"+newvalue1);
// alert("hi");
});
}, 0500);
});
}
\ No newline at end of file
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Mynotes block caps.
*
* @package block_mynotes
* @author Gautam Kumar Das<gautam.arg@gmail.com>
*/
defined('MOODLE_INTERNAL') || die();
$capabilities = array(
'block/mynotes:myaddinstance' => array(
'captype' => 'write',
'contextlevel' => CONTEXT_SYSTEM,
'archetypes' => array(
'user' => CAP_ALLOW
),
'clonepermissionsfrom' => 'moodle/my:manageblocks'
),
'block/mynotes:addinstance' => array(
'riskbitmask' => RISK_SPAM | RISK_XSS,
'captype' => 'write',
'contextlevel' => CONTEXT_BLOCK,
'archetypes' => array(
'editingteacher' => CAP_ALLOW,
'manager' => CAP_ALLOW
),
'clonepermissionsfrom' => 'moodle/site:manageblocks'
),
);
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
defined('MOODLE_INTERNAL') || die();
/**
* Mynotes block installation.
*
* @package block_mynotes
*/
function xmldb_block_mynotes_install() {
global $DB;
$obj = new stdClass();
$obj->blockname = 'mynotes';
$obj->parentcontextid = SITEID;
$obj->showinsubcontexts = 1;
$obj->pagetypepattern = '*';
$obj->defaultweight = 0;
$obj->defaultregion = BLOCK_POS_LEFT;
$obj->configdata = '';
$obj->timecreated = time();
$obj->timemodified = time();
$DB->insert_record('block_instances', $obj);
}
\ No newline at end of file
<?php
<?xml version="1.0" encoding="UTF-8" ?>
<XMLDB PATH="blocks/mynotes/db" VERSION="20160404" COMMENT="XMLDB file for my notes"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd">
<TABLES>
<TABLE NAME="block_mynotes" COMMENT="My Notes">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
<FIELD NAME="contextid" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="contextarea" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="content" TYPE="text" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="courseid" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="format" TYPE="int" LENGTH="2" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="userid" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
</KEYS>
</TABLE>
</TABLES>
</XMLDB>
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Strings for component 'block_mynotes', language 'en', branch 'MOODLE_29_STABLE'
*
* @package block_mynotes
* @author Gautam Kumar Das<gautam.arg@gmail.com>
*/
$string['mynotes:myaddinstance'] = 'Add a new mynotes block to Dashboard';
$string['mynotes:addinstance'] = 'Add a new mynotes block';
$string['mynotes:post'] = 'Add a new note';
$string['mynotes:view'] = 'View own notes';
$string['mynotes:delete'] = 'Delete own notes';
$string['pluginname'] = 'My Notes';
$string['disabledmynotes'] = 'Disabled my notes';
$string['showmynotes'] = 'Show my notes';
$string['addnotes'] = 'Add notes';
$string['mynotes'] = 'My notes';
$string['mynotescount'] = 'Total count: ';
$string['mynotesrequirelogin'] = 'You must login to add/view your notes';
$string['deletemynotes'] = 'Delete note';
$string['site'] = 'Site';
$string['course'] = 'Course';
$string['mod'] = 'Modules';
$string['user'] = 'Personal';
$string['save'] = 'Save';
$string['savedsuccess'] = 'Your note has been added successfully';
$string['mynotessavedundertab'] = 'For this page, your notes will be saved under <strong>{$a} tab</strong>.';
$string['placeholdercontent'] = 'Enter note content...';
$string['charactersleft'] = 'Characters left: ';
$string['characterlimit'] = 'Characters limit: ';
$string['characterlimit_help'] = 'This setting defines the maximum characters limit to write a note.';
$string['notmorethan'] = 'Can not enter more than {$a} characters';
$string['bottomright'] = 'Bottom-Right';
$string['bottomleft'] = 'Bottom-Left';
$string['topright'] = 'Top-Right';
$string['topleft'] = 'Top-Left';
$string['icondisplayposition'] = 'Icon position';
$string['icondisplayposition_help'] = 'Choose the position for Note-Icon which will used to open popup.';
$string['mynotesperpage'] = 'Per page';
$string['mynotesperpage_help'] = 'Limit the notes display on per page';
$string['deletefailed'] = 'Delete action failed';
$string['nopermissiontodelete'] = 'You do not have permission to delete this note';
$string['previouspage'] = '<< Previous page';
$string['nextpage'] = 'Next page >>';
$string['nothingtodisplay'] = 'Nothing to display';
$string['nocharacterlimit'] = ' ';
\ No newline at end of file
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* The mynotes block helper functions and callbacks
*
* @package block_mynotes
* @author Gautam Kumar Das<gautam.arg@gmail.com>
*/
defined('MOODLE_INTERNAL') || die();
class block_mynotes_manager {
public $perpage = 5;
private $config = null;
/*
* Constructor.
*/
public function __construct() {
$this->config = get_config('block_mynotes');
$this->perpage = $this->config->mynotesperpage;
}
/**
* Returns matched mynotes
*
* @param int $page
* @return array
*/
public function get_mynotes($options) {
global $DB, $CFG, $USER, $OUTPUT;
$page = (!isset($options->page) || !$options->page) ? 0 : $options->page;
$perpage = $this->perpage;
$params = array();
$start = $page * $perpage;
$ufields = 'u.id';
$where = ' m.userid = :userid';
$params['userid'] = $USER->id;
/* if (isset($options->contextarea) && !empty($options->contextarea)) {
$where .= ' AND m.contextarea = :contextarea';
$params['contextarea'] = $options->contextarea;
}
if (isset($options->courseid) && $options->courseid) {
$where .= ' AND m.courseid = :courseid';
$params['courseid'] = $options->courseid;
} */
if(isset($options->contextid) && $options->contextid){
$where .= ' AND m.contextid = :contextid';
$params['contextid'] = $options->contextid;
}
$sql = "SELECT $ufields,
m.id AS mynoteid, m.content AS ccontent, m.contextarea, m.contextid, m.format AS cformat,
m.timecreated AS timecreated, c.fullname as coursename, m.courseid
FROM {block_mynotes} m
JOIN {user} u ON u.id = m.userid
LEFT JOIN {course} c ON c.id = m.courseid
WHERE $where
ORDER BY m.timecreated DESC";
$strftime = get_string('strftimerecentfull', 'langconfig');
$mynotes = array();
$formatoptions = array('overflowdiv' => true);
$start = (isset($options->limitfrom)) ? $options->limitfrom : $start;
$rs = $DB->get_recordset_sql($sql, $params, $start, $perpage);
foreach ($rs as $u) {
$c = new stdClass();
$c->id = $u->mynoteid;
$c->userid = $u->id;
if ($u->courseid != SITEID) {
$c->coursename = html_writer::link(course_get_url($u->courseid), $u->coursename);
} else {
$c->coursename = '';
}
$c->content = $u->ccontent;
$c->contextarea = $u->contextarea;
$c->format = $u->cformat;
$c->timecreated = userdate($u->timecreated, $strftime);
$c->content = format_text($c->content, $c->format, $formatoptions);
$c->delete = true;
$mynotes[] = $c;
}
$rs->close();
return $mynotes;
}
/**
* Returns count of the mynotes in a table where all the given conditions met.
*
* @param object $options
* @return int The count of records
*/
public function count_mynotes($options) {
global $DB, $USER;
$params = array();
// $params ['contextid']= $options->contextid;
// $params= $options->contextid;
$sql='select COUNT(contextarea) from {block_mynotes} where contextid= :contextid';
$params ['contextid']= $options->contextid;
return $DB->count_records_sql($sql,$params);
/* $params['userid'] = $USER->id;
if (isset($options->contextarea) && !empty($options->contextarea)) {
$params['contextarea'] = $options->contextarea;
}
if (isset($options->contextid) && !empty($options->contextid)) {
$params['contextid'] = $options->contextid;
}
return $DB->count_records('block_mynotes',$params); */
}
/*
* Returns paging bar for mynotes
*
* @param object $options must contain properties(contextid, count, page, perpage)
* @return html
*/
public function get_pagination($options) {
global $OUTPUT;
$baseurl = new moodle_url('/blocks/mynotes/mynotes_ajax.php',
array(
'contextid' => $options->contextid)
);
return $OUTPUT->paging_bar($options->count, $options->page, $this->perpage, $baseurl);
}
/*
* Adding new record of mynote.
*
* @return object of single mynote record if insert to DB else false
*/
public function addmynote($context, $contextarea, $course, $content, $format = FORMAT_MOODLE) {
global $CFG, $DB, $USER, $OUTPUT;
$newnote = new stdClass;
$newnote->contextid = $context->id;
$newnote->contextarea = $contextarea;
$newnote->content = $content;
$newnote->courseid = $course->id;
$newnote->format = $format;
$newnote->userid = $USER->id;
$newnote->timecreated = time();
if ($cmtid = $DB->insert_record('block_mynotes', $newnote)) {
$newnote->id = $cmtid;
$newnote->content = format_text($newnote->content, $newnote->format, array('overflowdiv' => true));
$newnote->timecreated = userdate($newnote->timecreated, get_string('strftimerecentfull', 'langconfig'));
$newnote->coursename = ($newnote->courseid == SITEID) ? '' : $course->fullname;
if (!empty($newnote->coursename)) {
$newnote->coursename = html_writer::link(course_get_url($course), $newnote->coursename);
}
return $newnote;
} else {
return false;
}
}
/*
* Find all available context areas which is used to store and retrieve mynotes.
*
* @return array
*/
public function get_available_contextareas() {
return array(
// 'site' => get_string('site', 'block_mynotes'),
// 'course' => get_string('course', 'block_mynotes'),
// 'mod' => get_string('mod', 'block_mynotes'),
'user' => get_string('user', 'block_mynotes'),
);
}
/*
* Find context area using context level.
*
* @param object $context
* @retrun string
*/
public function get_current_tab($context, $page) {
/* if ($page->url->compare(new moodle_url('/user/view.php'), URL_MATCH_BASE)) {
return 'user';
} else if ($page->url->compare(new moodle_url('/user/profile.php'), URL_MATCH_BASE)) {
return 'user';
} else if ($context->contextlevel == CONTEXT_SYSTEM) {
return 'site';
} else if ($context->contextlevel == CONTEXT_COURSE) {
if ($context->instanceid == SITEID) {
return 'site';
}
return 'course';
} else if ($context->contextlevel == CONTEXT_MODULE) {
return 'mod';
} else if ($context->contextlevel == CONTEXT_USER) {
return 'user';
} else if ($context->contextlevel == CONTEXT_BLOCK) {
$parent = $context->get_parent_context();
if ($parent->contextlevel == CONTEXT_COURSE) {
return 'course';
} else if ($parent->contextlevel == CONTEXT_MODULE) {
return 'mod';
}
} */
return 'user';
}
/**
* Delete a note
*
* @param int $mynoteid
* @return bool
*/
public function delete($mynoteid) {
global $DB, $USER;
if (!$mynote = $DB->get_record('block_mynotes', array('id' => $mynoteid))) {
throw new mynotes_exception('deletefailed', 'block_mynotes');
}
if ($USER->id != $mynote->userid) {
throw new mynotes_exception('nopermissiontodelete', 'block_mynotes');
}
return $DB->delete_records('block_mynotes', array('id' => $mynoteid));
}
}
/**
* Mynotes exception class
*/
class mynotes_exception extends moodle_exception {
}
\ No newline at end of file
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/*
* Handling all ajax request for mynotes API
*
* @package block_mynotes
* @author Gautam Kumar Das<gautam.arg@gmail.com>
*/
define('AJAX_SCRIPT', true);
define('NO_DEBUG_DISPLAY', true);
require_once('../../config.php');
require_once($CFG->dirroot.'/course/lib.php');
require_once($CFG->dirroot . '/blocks/mynotes/lib.php');
$contextid = optional_param('contextid', SYSCONTEXTID, PARAM_INT);
$contextarea = optional_param('contextarea', 'site', PARAM_ALPHA);
$action = optional_param('action', '', PARAM_ALPHA);
$page = optional_param('page', 0, PARAM_INT);
list($context, $course, $cm) = get_context_info_array($contextid);
if ( $contextid == SYSCONTEXTID || $context->contextlevel == CONTEXT_USER) {
$course = get_site();
}
$PAGE->set_url('/blocks/mynotes/mynotes_ajax.php');
require_course_login($course, true, $cm);
$PAGE->set_context($context);
if (!empty($cm)) {
$PAGE->set_cm($cm, $course);
} else if (!empty($course)) {
$PAGE->set_course($course);
}
if (!confirm_sesskey()) {
$error = array('error' => get_string('invalidsesskey', 'error'));
die(json_encode($error));
}
if (!isloggedin()) {
echo json_encode(array('error' => 'require_login'));
die();
}
$config = get_config('block_mynotes');
echo $OUTPUT->header(); //...send headers
// process ajax request
switch ($action) {
case 'add':
$content = optional_param('content', '', PARAM_RAW);
$manager = new block_mynotes_manager();
if ($note = $manager->addmynote($context, $contextarea, $course, $content)) {
$options = new stdClass();
$options->page = $page;
$options->courseid = $course->id;
$options->contextid = $context->id;
$options->context = $context;
$options->contextarea = $contextarea;
unset($options->courseid);
$count = $manager->count_mynotes($options);
echo json_encode(array('notes' => array($note), 'count' => $count));
} else {
echo json_encode(array('error' => 'Unable to add note'));
}
die();
break;
case 'get':
$manager = new block_mynotes_manager();
$options = new stdClass();
$options->page = $page;
$options->contextid = $context->id;
$options->contextarea = $contextarea;
$count = $manager->count_mynotes($options);
$notes = $manager->get_mynotes($options);
echo json_encode(array('notes' => $notes, 'count' => $count));
die();
break;
case 'delete':
$noteid = required_param('noteid', PARAM_INT);
$limitfrom = optional_param('lastnotecounts', 0, PARAM_INT);
$manager = new block_mynotes_manager();
if ($manager->delete($noteid)) {
$options = new stdClass();
$options->page = $page;
$options->contextarea = $contextarea;
$count = $manager->count_mynotes($options);
if ($limitfrom) {
$options->limitfrom = $limitfrom - 1;
}
$notes = $manager->get_mynotes($options);
echo json_encode(array('notes' => $notes, 'count' => $count, 'noteid' => $noteid));
}
die();
break;
}
die();
\ No newline at end of file
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Settings for the Mynotes block
*
* @package block_mynotes
* @author Gautam Kumar Das<gautam.arg@gmail.com>
*/
defined('MOODLE_INTERNAL') || die;
if ($ADMIN->fulltree) {
$perpageoptions = array();
for ($i = 1; $i < 20; $i++) {
$perpageoptions[$i] = $i;
}
$settings->add(new admin_setting_configselect('block_mynotes/mynotesperpage', get_string('mynotesperpage', 'block_mynotes'),
get_string('mynotesperpage_help', 'block_mynotes'), 5, $perpageoptions));
$settings->add(new admin_setting_configtext('block_mynotes/characterlimit', get_string('characterlimit', 'block_mynotes'),
get_string('characterlimit_help', 'block_mynotes'), 180, PARAM_INT, 3));
$positionoptions = array();
$positionoptions['mynotes-pos-rb'] = get_string('bottomright', 'block_mynotes');
$positionoptions['mynotes-pos-lb'] = get_string('bottomleft', 'block_mynotes');
$positionoptions['mynotes-pos-rt'] = get_string('topright', 'block_mynotes');
$positionoptions['mynotes-pos-lt'] = get_string('topleft', 'block_mynotes');
$settings->add(new admin_setting_configselect('block_mynotes/icondisplayposition', get_string('icondisplayposition', 'block_mynotes'),
get_string('icondisplayposition_help', 'block_mynotes'), 'mynotes-pos-rb', $positionoptions));
}
\ No newline at end of file
#mynotes-opener { position: absolute; bottom:0px; background: #443355; width: 25px; height: 25px; }
div.mdl-align { min-height: 470px; }
.mynotes-pos-inline-text { padding: 10px; margin-left: 35px; cursor: pointer; }
.mynotes-pos-inline,
.mynotes-pos-rb,
.mynotes-pos-lb,
.mynotes-pos-rt,
.mynotes-pos-lt { width: 40px; height: 40px; position: fixed; background: #b31b1b; padding: 0; border-radius: 30px; text-align: center; }
.mynotes-pos-rb { bottom: 5px; right: 20px; }
.mynotes-pos-lb { bottom: 5px; left: 20px; }
.mynotes-pos-rt { top: 100px; right: 20px; }
.mynotes-pos-lt { top: 100px; left: 20px; }
.mynotes-pos-inline { position: relative; float: left; }
.mynotes-pos-inline >span.pencil, .mynotes-pos-rb >span.pencil, .mynotes-pos-lb>span.pencil, .mynotes-pos-rt>span.pencil, .mynotes-pos-lt>span.pencil { color: #fff; font-size: 29px; margin: 0; display: inline-block; font-weight: bold; cursor: pointer; line-height: 40px; }
.mynotes_base { display: inline-block; width: 100%; }
.mynotes_base .inputarea { background: #fff4d5; padding: 5px; margin-bottom: 10px; }
.mynotes_base .inputarea p {margin: 0; font-size: 13px; }
.mynotes_base .textarea { border: 1px solid gray; padding: 5px; background: #fff; }
.mynotes_base textArea:focus { border: none; box-shadow: none; }
.mynotes_base textArea {width:100%; max-width: 100%; margin: 0; padding: 0; max-height: 125px; border: none; box-shadow: none; }
.mynotes_base input[type="submit"], .mynotes_base input[type="submit"]:hover { margin: 0; padding: 3px 10px; border: none; background: #63ab36; color: #fff; }
.mynotes_base input[type="submit"][disabled="disabled"]:hover { background: #63ab36; cursor: not-allowed; }
.mynotes_base span.warning { color: #bd3c2f; margin-left: 15px; }
.mynotes_base .responsetext { color: #33b733; line-height: 20px; }
.mynotes_base .tabs-menu { height: 30px; float: left; clear: both; margin-bottom: 1px; }
.mynotes_base .tabs-menu li { padding: 0 10px; margin-right: 1px; height: 30px; line-height: 30px; float: left; list-style: none; background-color: #d84e36; cursor: pointer; }
.mynotes_base .tabs-menu li:first-child { border-radius: 7px 0 0 0; }
.mynotes_base .tabs-menu li:last-child { border-radius: 0 7px 0 0; }
.mynotes_base .tabs-menu li.current { position: relative; background-color: #ffe6a4; border-bottom: 1px solid #fff; z-index: 5; border-bottom: 2px solid #ffe6a4; }
.mynotes_base .tabs-menu li:first-child.current { border-left: 1px solid #d4d4d1; border-top: 1px solid #d4d4d4; }
.mynotes_base .tabs-menu li:last-child.current { border-right: 1px solid #d4d4d1; border-top: 1px solid #d4d4d4; }
.mynotes_base .tabs-menu li .menu-item { text-transform: uppercase; color: #fff; text-decoration: none; }
.mynotes_base .tabs-menu .current .menu-item { color: #000; }
.mynotes_base .tab { border: 1px solid #d4d4d1; clear: both; width: auto; background: #f7f7f4; }
.mynotes_base .tab .tab-content { display: none; }
.mynotes_base .tab .tab-content .notes-info { background: #ffe6a4; padding: 5px; position: relative; }
.mynotes_base .tab .tab-content .notes-info .count { color: #000; }
.mynotes_base .tab .tab-content .notes-info .mynotes-paging { position: absolute; right: 0; }
.mynotes_base .tab .tab-content .notes-info .mynotes-paging .paging a { margin: 5px; background: #c1621e; padding: 4px 10px; border-radius: 15px; color: #fff; }
.mynotes_base .tab .tab-content .notes-info .mynotes-paging .paging .separator { border-left: 1px solid gray; }
.mynotes_base .tab .tab-content ul.mynotes_lists { margin:0; clear: both; }
.mynotes_base .tab .tab-content ul.mynotes_lists li { list-style: none; position: relative; margin: 0 0 5px 0; padding: 5px; list-style: none; background-color: #fff; border-top: 1px solid #e3e4e4; }
.mynotes_base .tab .tab-content ul.mynotes_lists li .content { margin-right: 10px; word-wrap: break-word; }
.mynotes_base .tab .tab-content ul.mynotes_lists li .note-detail { display: inline-block; font-size: 11px; }
.mynotes_base .tab .tab-content ul.mynotes_lists li .time { color: #888; font-style: italic; display: inline-block; margin-left: 5px; font-size: 11px; }
.mynotes_base .tab .tab-content ul.mynotes_lists li a.mynote-delete { position: absolute; right: 0; margin:0 4px; }
.mynotes_base .tab .tab-content ul.mynotes_lists li a.mynote-delete span { color: #bbb; }
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Version details
*
* @package block_mynotes
* @author Gautam Kumar Das<gautam.arg@gmail.com>
*/
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2018011200; // The current plugin version (Date: YYYYMMDDXX)
$plugin->requires = 2015050500; // Requires this Moodle version
$plugin->component = 'block_mynotes'; // Full name of the plugin (used for diagnostics)
$plugin->release = 'V3.4 r1';
$plugin->maturity = MATURITY_STABLE;
\ No newline at end of file
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!