Friday, May 13, 2016

Use Bootstrap Glyphicon for icons in text, buttons, toolbars, navigation, or forms





We can use Bootstrap Glyphicon for icons in  text, buttons, toolbars, navigation, or forms :
as long as we have Bootstrap library

Example, comment icon


<span class='glyphicon glyphicon-comment'></span>

And more examples

<p>Envelope icon: <span class="glyphicon glyphicon-envelope"></span></p>
<p>Search icon: <span class="glyphicon glyphicon-search"></span></p>
<p>Print icon: <span class="glyphicon glyphicon-print"></span></p>
 
Reference:

Thursday, May 12, 2016

jQuery, prevent many click fireup





Use jQuery function die to prevent many clicks fire at the same time:
example
                $('#popup_9sp .modal-body .delete').die('click');    
                $('#popup_9sp .modal-body .delete').live('click', function(){
              
                        var id = $(this).parents('tr').attr('data-id');
                        var answer = confirm("Are you sure to delete this row?")
                        if(id>0 && answer){
                          
                              $('#tab1').find('.cid'+id).remove();
                        
                        }        
                        var postdata = {funct: 'DeleteCourse', id:id};
                        var url = '../_ajaxParts/preplanning/preplanning_summary.php';

                        if(id>0 && answer){
                            $.post(url, postdata, function(data) {
                                if(data=='fail')
                                    $("div#notice").html('Delete failed!');
                                else{    
                                    $("div#notice").html('Delete successfully.');
                                }
                                                                                
                                $("div#notice").css('display', 'block');
                                $("div#notice").fadeOut(15000);
                            });
                        }                      
                        if (answer)
                            $(this).parents('tr').css('display','none');
                    });
                  
      

            });

jQuery autocomplete scroll bar for dropdown menu




jQuery autocomplete scroll bar for dropdown menu
add following CSS style:
<style>
.ui-autocomplete { height: 300px; width: 200px; overflow-y: scroll; overflow-x: hidden;}
</style>

jquery - Parse JSON with jQuery Example





jquery - Parse JSON with jQuery Example

 $.parseJSON - Takes a well-formed JSON string and returns the resulting JavaScript value.
Example:
        $.post("../_ajaxParts/preplanning/preplanning.php", {
            funct: 'getPrePlanning',
            stakeholder_id:stakeholder_id,
            pad_id:pad_id,
             site:site,          
        }, function(data) {
             formattedJson= $.parseJSON(data);
             formatPrePlanningBox(formattedJson)
        });


 In preplanning.php, we use json_encode to convert to json format.
<?php
 if($_POST['funct'] == "getPrePlanning") {

    $preplanning = new  preplanning();
    $model =  new PreplanningSummaryModel();
    $pad_id =$_POST['pad_id'];
    $total_semester= $model->get_total_semester($pad_id);
    $coursepre_choice= $model->get_coursepre_choice($pad_id);  
    $data = $preplanning->getPrePlanning($_POST);
    $CoursePre = $preplanning->getCoursePre($_POST);
    $arrayForJSON = array("count" => count($data),  "coursepre_choice" => $coursepre_choice, "total_semester" => $total_semester,  "data" => $data, "CoursePre" => $CoursePre);
    echo json_encode($arrayForJSON);
}

?>

PHPExcel using excel template, increase PHP memory




PHPExcel using excel template:
               $file_path = $_SERVER['DOCUMENT_ROOT'].'/uploads/IAA/IAAtemplate.xlsx';
                $objReader = PHPExcel_IOFactory::createReader('Excel2007');

                $objPHPExcel = $objReader->load($file_path);

        ini_set('zlib.output_compression','Off');
         ob_end_clean();
            header("Pragma: public");
            header("Expires: 0");
            header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
            header("Content-Type: application/force-download");
            header("Content-Type: application/octet-stream");

              header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet; charset=UTF-8');
                $filename = $termFilter."-IAA-".$dept_abbrname."-".date("Ymd").".xlsx";
                header('Content-Disposition: attachment; filename= "'.$filename.'"');
            header("Content-Transfer-Encoding: binary");

        $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
                $objWriter->save('php://output');



This will  take more memory than using without template If you produce  a large
excel file, you may see error: "File not Found" or "Connection reset error".


To fix this: add
         set_time_limit(1000000);
         ini_set("max_input_time", 60000);
         ini_set("memory_limit",-1);

ini_set("memory_limit",-1); will remove PHP  memory limit and will fix memory problem

Tuesday, May 10, 2016

jquery bind paste to get paste content





Below is the code for  jquery bind  paste to get paste content
        $('.coursepre').bind('paste', function(e) {
                //remove placeholder to make sure placeholder not mess with paste text
                $(this).attr("placeholder", "");

              //using setTimeout to get paste text
                 setTimeout(function ()
                {

                   //use $(e.currentTarget) to replace $(this) in paste
                    curname= $(e.currentTarget).val();
                    parent = $(e.currentTarget).parent();   
                     preid =  $(e.currentTarget).attr('data-preid');
                    saveBasicPre(curname, parent, stakeholder_id,pad_id,preid);           
               },0);                   
        });


We can use also add paste in jQuery  on  function
                $('#popup_9sp').on("keydown.autocomplete, paste",".course",function(e){
                $(this).autocomplete({              
                        //    autoFocus: true,
                    source: "../_ajaxParts/preplanning/preplanning.php?funct=courselist",
                    minLength : 2,

                    select : function(event, ui) {

                        $(this).val(ui.item.label);
                        newname = ui.item.value;
                        newvalue = ui.item.label;
                        checked = false;
                        parent = $(this).parent();
                        type='select';
                        campus = parent.find('.campus').val();
                        id =  $(this).parent().parent().attr('data-id');  
                      

              
                          managerttr=1;
                              
                          
                        saveBasicInfo1(row0,type,newvalue, parent, campus, id,sid,term, newname, managerttr,pad_id);

                    },
                    open : function() {
                       // $("#instructorname").attr('data-sid', 0);
                    },

                    change : function() {   
                            curname = $(this).val();
                            parent = $(this).parent();
                            type='change'
                            campus = parent.find('.campus').val();
                            id =  $(this).parent().parent().attr('data-id');
                                                  
                             newname=$('#tab1').find('.cid'+id).html();
                              managerttr=1;
              
                            if(curname.trim()!= newname) {
                                saveBasicInfo1(row0,type,curname, parent, campus, id,sid,term,newname,managerttr,pad_id);
                                //$(this).val(newname);
                             }
                    }
                    }).focus(function(){
                    //    $(this).autocomplete('search');
                        oldname=$(this).val();
                    });
                });              
              
                $('#popup_9sp .modal-body select.ttr, input.comment').die('change');
                $('#popup_9sp .modal-body select.ttr, input.comment').live('change', function(){  
                     row0.find('.ttrpattern').html($(this).val());
                     row0.find('.ttrpattern').attr('data-ttr',$(this).val());
                     row0.parent().find('.term').attr('data-ttr',$(this).val());
                     $td=row0;
                    if($(this).val()=='SL' || $(this).val()=='L'){
                        $td.find('.SLdate').html('');
                        $td.removeClass('teachingCell');  
                        $td.removeClass('researchCell');          
                        $td.addClass('leaveCell');
                        $(this).parent().find('.SLdate').hide();   
                        $td.find('.cidlist').hide();                          
                    }else if($(this).val()=='Research'){
                        $td.removeClass('leaveCell');  
                        $td.removeClass('teachingCell');
                        $td.addClass('researchCell');  
                         $(this).parent().find('.SLdate').hide();                      
                        $td.find('.cidlist').hide();  
                    }else if($(this).val()=='Teaching'){
                        $td.removeClass('leaveCell');  
                        $td.removeClass('researchCell');              
                        $td.addClass('teachingCell');
                         $(this).parent().find('.SLdate').show();   
                        $td.find('.cidlist').show();                        
                      
                    }else{
                        $td.removeClass('teachingCell');  
                        $td.removeClass('researchCell');          
                        $td.removeClass('leaveCell');  
                        $td.find('.cidlist').hide();  
                         $(this).parent().find('.SLdate').hide();   
                    }
                     ttrnew =     $(this).val();              
                    $.post("../_ajaxParts/preplanning/preplanning_summary.php", {
                            funct: 'savettrRevisedTerm',
                            ttrRevised:ttrnew,
                            stakeholder_id:sid,
                            pad_id:pad_id,
                            term: term
                    }, function(data) {
                        if(data=='fail')
                            $("div#notice").html('Updated failed!');
                        else        
                            $("div#notice").html('Updated successfully.');
                        $("div#notice").fadeIn();      
                        $("div#notice").fadeOut(5000);  
                     

                    });                  
                });