892007c9 by logesh

dev:changes in mynotes with edit option

1 parent 84ba169e
......@@ -2,6 +2,8 @@ define(['jquery', 'core/yui', 'core/str', 'core/config', 'core/notification'], f
var CONFIG;
var NODES = {
DELETE_ICON: '<span class="delete">&#x274C;</span>',
EDIT_ICON: '<i class="far fa-edit" id="mynote-edit"></i>',
SAVE_ICON: '<i class="far fa-save" id="mynote-update"></i>',
};
var SELECTORS = {
MYNOTES_BASE: '#mynotes_base',
......@@ -16,6 +18,8 @@ define(['jquery', 'core/yui', 'core/str', 'core/config', 'core/notification'], f
var panel = null;
var initnotes = null;
var strdeletenote = M.util.get_string('deletemynotes', 'block_mynotes');
var streditnote = M.util.get_string('editmynotes', 'block_mynotes');
// var strupdatenote = M.util.get_string('updatemynotes', 'block_mynotes');
var getMynotesValidatedUrl = function(baseurl) {
var a = document.createElement('a');
a.href = baseurl;
......@@ -368,7 +372,7 @@ define(['jquery', 'core/yui', 'core/str', 'core/config', 'core/notification'], f
var noteinfo = $(SELECTORS.MYNOTES_BASE).find(scope.currenttab);
if (mynotescount > 0) {
noteinfo.find('.count').html(M.util.get_string('mynotescount', 'block_mynotes') + '' + mynotescount);
noteinfo.find('.count').html(M.util.get_string('mynotescount', 'block_mynotes') + '' + mynotescount+')');
} else {
noteinfo.find('.count').html(M.util.get_string('nothingtodisplay', 'block_mynotes'));
}
......@@ -386,21 +390,23 @@ define(['jquery', 'core/yui', 'core/str', 'core/config', 'core/notification'], f
$('#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 = '';
var editlink='<a href="#" id="mynote-edit-'+CONFIG.instanceid + '-' + notes[x].id + '" class="mynote-edit" title="' + streditnote + '">' + NODES.EDIT_ICON + '</a>';
var updatelink='<a href="#" id="mynote-update-'+CONFIG.instanceid + '-' + notes[x].id + '" class="mynote-update" title="Save note">' + NODES.SAVE_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 mynotestime='';
if (notes[x].notestime != ''){
mynotestime = '<br><div class="time">' +'video Time :' +notes[x].notestime +' sec'+ '</div>';
}
var note_html = '<div class="content">' + deletelink + notes[x].content + '</div>';
var note_html = '<div class="content">' + deletelink + editlink + updatelink + notes[x].content + '</div>';
// var note_html = '<div class="content">' + editlink + notes[x].content + '</div>';
lists += '<li id="mynote-' + CONFIG.instanceid + '-' + notes[x].id + '" data-itemid="' + notes[x].id + '">' + note_html + notedetail + userdate + mynotestime +'</li>';
}
return lists;
......@@ -487,6 +493,7 @@ define(['jquery', 'core/yui', 'core/str', 'core/config', 'core/notification'], f
$('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 + '-', '');
......@@ -506,6 +513,49 @@ define(['jquery', 'core/yui', 'core/str', 'core/config', 'core/notification'], f
});
}
});
//edit option function added one
$('body').delegate(SELECTORS.MYNOTES_BASE + ' a.mynote-edit', 'click', function(e) {
e.preventDefault();
var nid = $(this).attr('id');
var mytestid=$(this).attr('id');
var editid = mytestid.replace('edit-','');
$('#'+editid+' .content .no-overflow .text_to_html').attr('id','notes_edit_option');
var vals=document.getElementById('notes_edit_option').contentEditable = true;
document.getElementById('notes_edit_option').focus();
$( "#"+editid+" #mynote-update" ).click(function() {
var newstring= $("#notes_edit_option").text();
if (nid != '' || nid != 'undefined') {
var notescount = $(SELECTORS.MYNOTES_BASE).find(SELECTORS.MYNOTES_LISTS + '-' + scope.currenttab + ' > li').length;
var id = nid.replace('mynote-edit-' + CONFIG.instanceid + '-', '');
var arg = {
contextid: CONFIG.contextid,
action: 'edit',
noteid: id,
lastnotecounts: notescount,
newnotes:newstring,
};
var vals=document.getElementById('notes_edit_option').contentEditable = false;
document.getElementById("notes_edit_option").removeAttribute("id");
scope.request({
params: arg,
callback: function(id, ret, args) {
args.scope.addToList(ret);
// $('#mynote-' + CONFIG.instanceid + '-' + ret.noteid).remove();
args.scope.displayMynotes();
}
});
}
});
});//edit function ends here
},
displayDialogue: function(e) {
......@@ -540,7 +590,7 @@ define(['jquery', 'core/yui', 'core/str', 'core/config', 'core/notification'], f
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="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>')));
var el = $('<div id="tet"></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 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 = '';
......
......@@ -2,6 +2,8 @@ define(['jquery', 'core/yui', 'core/str', 'core/config', 'core/notification'], f
var CONFIG;
var NODES = {
DELETE_ICON: '<span class="delete">&#x274C;</span>',
EDIT_ICON: '<i class="far fa-edit" id="mynote-edit"></i>',
SAVE_ICON: '<i class="far fa-save" id="mynote-update"></i>',
};
var SELECTORS = {
MYNOTES_BASE: '#mynotes_base',
......@@ -16,6 +18,8 @@ define(['jquery', 'core/yui', 'core/str', 'core/config', 'core/notification'], f
var panel = null;
var initnotes = null;
var strdeletenote = M.util.get_string('deletemynotes', 'block_mynotes');
var streditnote = M.util.get_string('editmynotes', 'block_mynotes');
// var strupdatenote = M.util.get_string('updatemynotes', 'block_mynotes');
var getMynotesValidatedUrl = function(baseurl) {
var a = document.createElement('a');
a.href = baseurl;
......@@ -368,7 +372,7 @@ define(['jquery', 'core/yui', 'core/str', 'core/config', 'core/notification'], f
var noteinfo = $(SELECTORS.MYNOTES_BASE).find(scope.currenttab);
if (mynotescount > 0) {
noteinfo.find('.count').html(M.util.get_string('mynotescount', 'block_mynotes') + '' + mynotescount);
noteinfo.find('.count').html(M.util.get_string('mynotescount', 'block_mynotes') + '' + mynotescount+')');
} else {
noteinfo.find('.count').html(M.util.get_string('nothingtodisplay', 'block_mynotes'));
}
......@@ -386,21 +390,23 @@ define(['jquery', 'core/yui', 'core/str', 'core/config', 'core/notification'], f
$('#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 = '';
var editlink='<a href="#" id="mynote-edit-'+CONFIG.instanceid + '-' + notes[x].id + '" class="mynote-edit" title="' + streditnote + '">' + NODES.EDIT_ICON + '</a>';
var updatelink='<a href="#" id="mynote-update-'+CONFIG.instanceid + '-' + notes[x].id + '" class="mynote-update" title="Save note">' + NODES.SAVE_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 mynotestime='';
if (notes[x].notestime != ''){
mynotestime = '<br><div class="time">' +'video Time :' +notes[x].notestime +' sec'+ '</div>';
}
var note_html = '<div class="content">' + deletelink + notes[x].content + '</div>';
var note_html = '<div class="content">' + deletelink + editlink + updatelink + notes[x].content + '</div>';
// var note_html = '<div class="content">' + editlink + notes[x].content + '</div>';
lists += '<li id="mynote-' + CONFIG.instanceid + '-' + notes[x].id + '" data-itemid="' + notes[x].id + '">' + note_html + notedetail + userdate + mynotestime +'</li>';
}
return lists;
......@@ -487,6 +493,7 @@ define(['jquery', 'core/yui', 'core/str', 'core/config', 'core/notification'], f
$('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 + '-', '');
......@@ -506,6 +513,49 @@ define(['jquery', 'core/yui', 'core/str', 'core/config', 'core/notification'], f
});
}
});
//edit option function added one
$('body').delegate(SELECTORS.MYNOTES_BASE + ' a.mynote-edit', 'click', function(e) {
e.preventDefault();
var nid = $(this).attr('id');
var mytestid=$(this).attr('id');
var editid = mytestid.replace('edit-','');
$('#'+editid+' .content .no-overflow .text_to_html').attr('id','notes_edit_option');
var vals=document.getElementById('notes_edit_option').contentEditable = true;
document.getElementById('notes_edit_option').focus();
$( "#"+editid+" #mynote-update" ).click(function() {
var newstring= $("#notes_edit_option").text();
if (nid != '' || nid != 'undefined') {
var notescount = $(SELECTORS.MYNOTES_BASE).find(SELECTORS.MYNOTES_LISTS + '-' + scope.currenttab + ' > li').length;
var id = nid.replace('mynote-edit-' + CONFIG.instanceid + '-', '');
var arg = {
contextid: CONFIG.contextid,
action: 'edit',
noteid: id,
lastnotecounts: notescount,
newnotes:newstring,
};
var vals=document.getElementById('notes_edit_option').contentEditable = false;
document.getElementById("notes_edit_option").removeAttribute("id");
scope.request({
params: arg,
callback: function(id, ret, args) {
args.scope.addToList(ret);
// $('#mynote-' + CONFIG.instanceid + '-' + ret.noteid).remove();
args.scope.displayMynotes();
}
});
}
});
});//edit function ends here
},
displayDialogue: function(e) {
......@@ -540,7 +590,7 @@ define(['jquery', 'core/yui', 'core/str', 'core/config', 'core/notification'], f
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="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>')));
var el = $('<div id="tet"></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 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 = '';
......
......@@ -2,18 +2,20 @@ define(['jquery'], function($) {
return {
init: function() {
var url= $(location).attr('href');
// tab-mynotes_user
$('document').ready(function(){
// tab-mynotes_user mynotepencil
if(url.includes('/mod/page/view.php')){
console.log('init function got invoked ');
var iframe = document.querySelector('iframe');
$('#mynotepencil').click(function(){
console.log('init function got invoked ');
var player = new Vimeo.Player(iframe);
}
});
// document.getElementById("panel").style.display = "none"; Nothing to display
// $("#tab-mynotes_user").removeAttr("style").hide();
}
};
});
......
......@@ -103,6 +103,7 @@ class block_mynotes extends block_base {
*/
private function block_mynotes_get_required_javascript() {
global $PAGE, $CFG;
$PAGE->requires->js_call_amd('block_mynotes/script', 'init');
list($context, $course, $cm) = get_context_info_array($PAGE->context->id);
$config = get_config('block_mynotes');
......@@ -121,10 +122,6 @@ class block_mynotes extends block_base {
),
);
// $PAGE->requires->string_for_js('charactersleft', 'block_mynotes');
// $PAGE->requires->js_call_amd('block_mynotes/player', 'init');
// $PAGE->requires->js('/blocks/mynotes/javascript/player.min.js');
// $PAGE->requires->js( new moodle_url($CFG->wwwroot . '/blocks/mynotes/javascript/player.min.js') );
$PAGE->requires->js_call_amd('block_mynotes/script', 'init');
$PAGE->requires->string_for_js('notmorethan', 'block_mynotes');
$PAGE->requires->string_for_js('mynotes', 'block_mynotes');
......@@ -133,6 +130,7 @@ class block_mynotes extends block_base {
$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('editmynotes', 'block_mynotes');///addition one
$PAGE->requires->string_for_js('mynotescount', 'block_mynotes');
$PAGE->requires->string_for_js('previouspage', 'block_mynotes');
$PAGE->requires->string_for_js('nextpage', 'block_mynotes');
......
......@@ -27,14 +27,17 @@ $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['mynotes:edit'] = 'edit 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['mynotescount'] = 'Notes: (';
$string['mynotesrequirelogin'] = 'You must login to add/view your notes';
$string['deletemynotes'] = 'Delete note';
$string['editmynotes'] = 'Edit note';
$string['updatemynotes'] = 'Save note';
$string['site'] = 'Site';
$string['course'] = 'Course';
$string['mod'] = 'Modules';
......@@ -55,8 +58,10 @@ $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['editfailed'] = 'Edit action failed';
$string['deletefailed'] = 'Delete action failed';
$string['nopermissiontodelete'] = 'You do not have permission to delete this note';
$string['nopermissiontoedit'] = 'You do not have permission to edit this note';
$string['previouspage'] = '<< Previous page';
$string['nextpage'] = 'Next page >>';
$string['nothingtodisplay'] = 'Nothing to display';
......
......@@ -339,6 +339,28 @@ class block_mynotes_manager {
}
return $DB->delete_records('block_mynotes', array('id' => $mynoteid));
}
/**
* Edit a note
*
* @param int $mynoteid
* @return bool
*/
public function edit($mynoteid,$notes) {
global $DB, $USER;
if (!$mynote = $DB->get_record('block_mynotes', array('id' => $mynoteid))) {
throw new mynotes_exception('editfailed', 'block_mynotes');
}
if ($USER->id != $mynote->userid) {
throw new mynotes_exception('nopermissiontoedit', 'block_mynotes');
}
$timecreated = time();
$param = array ($notes,$timecreated,$mynoteid );
$sql4 = 'update {block_mynotes} set content=? , timecreated=? where id=? ';
return $update_record = $DB->execute ( $sql4, $param );
}
}
/**
......
......@@ -27,6 +27,7 @@ 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);
......@@ -38,6 +39,7 @@ if ( $contextid == SYSCONTEXTID || $context->contextlevel == CONTEXT_USER) {
$course = get_site();
}
$PAGE->requires->js_call_amd('block_mynotes/script', 'init');
$PAGE->set_url('/blocks/mynotes/mynotes_ajax.php');
require_course_login($course, true, $cm);
......@@ -89,6 +91,7 @@ switch ($action) {
}
die();
break;
case 'get':
$manager = new block_mynotes_manager();
$options = new stdClass();
......@@ -112,6 +115,30 @@ switch ($action) {
die();
break;
case 'edit':
$noteid = required_param('noteid', PARAM_INT);
// $limitfrom = optional_param('lastnotecounts', 0, PARAM_INT);
$notes = required_param('newnotes', PARAM_TEXT);
$manager = new block_mynotes_manager();
if ($manager->edit($noteid,$notes)) {
$options = new stdClass();
$options->page = $page;
$options->contextid = $context->id;
$options->contextarea = $contextarea;
$options->courseid = $course->id;
$count = $manager->count_mynotes($options);
if ($limitfrom) {
$options->limitfrom = $limitfrom - 1;
}
$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);
......@@ -129,7 +156,6 @@ switch ($action) {
}
$notes = $manager->get_mynotes($options);
echo json_encode(array('notes' => $notes, 'count' => $count, 'noteid' => $noteid));
}
die();
......
#mynotes-opener { position: absolute; bottom:0px; background: #443355; width: 25px; height: 25px; }
div.mdl-align { min-height: 470px; }
div.mdl-align { min-height: 470px;}
#mynote-edit{position: absolute !important;right: 0 !important; margin: 0px 20px !important;}
#mynote-update{position: absolute !important; right: 0 !important; margin:0px 40px !important;}
#notes_edit_option{color: #2310c3 !important;}
.mdl-align { padding:inherit !important; }
.mynotes-pos-inline-text { padding: 10px; margin-left: 35px; cursor: pointer; }
.mynotes-pos-inline,
.mynotes-pos-rb,
......@@ -45,6 +49,6 @@ div.mdl-align { min-height: 470px; }
.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 { position: absolute; right: 0; margin:0 -1px; }
.mynotes_base .tab .tab-content ul.mynotes_lists li a.mynote-delete span { color: #bbb; }
......
......@@ -23,7 +23,7 @@
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2018011201; // The current plugin version (Date: YYYYMMDDXX)
$plugin->version = 2018011202; // 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';
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!