script.min.js 4.74 KB
define(['jquery','core/config',], function($,config) {
 
    return {
        init: function() {
        	
        	var CONFIG;
        	
        	
        	$('.notes_overview').hide();
        	
        	
        	var url=  $(location).attr('href');
        	
        	
        	if(url.includes('/mynotes/view.php')){
        		
        		$('.page-header').css('margin-top','2em !important');
        		
            	$('.page-title').css('margin-top','inherit !important');
        		
        	}

        	$(document).ready(function(){
        		
        		$(".notes_section").click(function(){

        			var eventId=this.id;
        			$('#notes_table_id'+eventId).toggle();
        		});
        		
        		$(".notes_section").click(function(){
        			var eventId=this.id;
        			
        			var classname=$( "div#"+eventId ).children()[0].className;
        			
        			if (classname === 'notes_course fa fa-chevron-circle-right'){
        				
        				$( "#icon"+eventId ).removeClass( 'notes_course fa fa-chevron-circle-right' );
        				$( "#icon"+eventId ).addClass( 'notes_course fa fa-chevron-circle-down' );
        			}
        			else if (classname === 'notes_course fa fa-chevron-circle-down'){
        				$( "#icon"+eventId ).removeClass( 'notes_course fa fa-chevron-circle-down' );
        				$( "#icon"+eventId ).addClass( 'notes_course fa fa-chevron-circle-right' );
        			}

        		});
        		
        		
        		$("#excel_download").click(function(){
        			var rootPath = M.cfg.wwwroot
        			
        			 var arg = {
                            action: 'download',
                            
                        };
        			
                        $.ajax({
                            url: rootPath+"/blocks/mynotes/notes_excel.php",
                            type: "POST",
                            data: arg,
                            success: function(response){
                                  //do action  
                            },
                            error: function(){
                                  // do action
                            }
        			
                        });
        			
        		});
        		


        		$("a.delete_note").click(function(){

        			var deleteId=this.id;

        			var arg = {
        					action: 'delete',
        					noteid: deleteId,
        			};

        			var rootPath = M.cfg.wwwroot;
        			$.ajax({
        				type: 'post',
        				url: rootPath+'/blocks/mynotes/allnotes_ajax.php',
        				data:arg,
        				success: function( data ) {
        					var deleteid=data.noteid;
        					$("#notes"+deleteid).remove();
        				},
        				error: function(data, errorThrown)
        		          {
        		              alert('request failed :'+errorThrown);
        		          }
        			});

        			
        		});
        		
        		
        		
        		$("a.edit_note").click(function(){

        			var editId=this.id;
        			
//        			notes_content+editId;
        			var vals=document.getElementById('notes_content'+editId).contentEditable = true;
                    document.getElementById('notes_content'+editId).focus();
//        			console.log('notes_content'+editId);
        			  $('#notes_content'+editId).keypress(function(event) {
        				  
        				  if (event.keyCode == 13) {
        					 
        					  var newstring= $('#notes_content'+editId).text();
//        					  console.log(newstring);
        					  
        					  var vals=document.getElementById('notes_content'+editId).contentEditable = false;
        					  
        					  var arg = {
                                      action: 'edit',
                                      noteid: editId,
                                      newnotes:newstring,
                                  };
        					  
        					  var rootPath = M.cfg.wwwroot;
        	        			$.ajax({
        	        				type: 'post',
        	        				url: rootPath+'/blocks/mynotes/allnotes_ajax.php',
        	        				data:arg,
        	        				success: function( data ) {
        	        					
        	        				},
        	        				error: function(data, errorThrown)
        	        		          {
        	        		              alert('request failed :'+errorThrown);
        	        		              var vals=document.getElementById('notes_content'+editId).contentEditable = true;
        	        		          }
        	        			}); 
        					  
        					  
        					  
        					  
        					  
        				  }
        				  
        				  
        				  
        				  
        			  });
        			
        			

        		});

        	    
        	    
        	    
        	});
        	

        }
    };
});