Monday, 13 January 2014

Concatenation/Joining of two string using Smarty

// Concatenation / Join of two string using Smarty using '|cat:' keyword.
{$param_key = "param_"|cat:$item_name.id}

Friday, 10 January 2014

Bootstrap Date Picker - Auto close of Date1/ Check In and jump to Date2/ Check Out with 7days difference

In Bootstrap Date Picker, if you need to auto close a date select popup and auto jump to Date2/ Check Out popup with 7days difference, afterwards auto close the Check Out popup once selected. Use the below function.
/** Auto closing of In/Out POPUP on Select */
var enableInOutDatePicker = function (date1, date2) {
 
 // $( "#start_date" ).datepicker( { startDate:null, format:'dd/mm/yyyy', todayHighlight:true } );
 
 if ( (date1 =="" )  || (date1 == undefined) ) { var date1 = 'start_date'; }
 if ( (date2 =="" )  || (date2 == undefined) ) { var date1 = 'end_date'; }
 
 var nowTemp = new Date();
 var now = new Date(nowTemp.getFullYear(), nowTemp.getMonth(), nowTemp.getDate(), 0, 0, 0, 0);
 //alert(nowTemp);

 var checkin = $('#' + date1).datepicker({

     beforeShowDay: function (date) {
         return date.valueOf() >= now.valueOf();
     }
 }).on('changeDate', function (ev) {
     if (ev.date.valueOf() > checkout.date.valueOf()) {
         var newDate = new Date(ev.date);
         newDate.setDate(newDate.getDate() + 7);
         //alert(newDate);
         checkout.setValue(newDate);
         //checkout.setDate(newDate);
         checkout.update();
     }
     checkin.hide();
     $('#' + date2).focus();
 }).data('datepicker');

 var checkout = $('#' + date2).datepicker({
     beforeShowDay: function (date) {
         return date.valueOf() > checkin.date.valueOf();
     }
 }).on('changeDate', function (ev) {
     checkout.hide();
 }).data('datepicker');
};
/** Auto closing of In/Out POPUP on Select */


Bootstrap Datepicker - Auto closing of POPUP on date selection

In the Bootstrap Datepicker, if you need to auto close of popup date selector,
please use the below function.
/** Auto closing of POPUP on single date Selection */
var enableSingleDatePicker = function (date) {
 
 if ( (date =="" )  || (date == undefined) ) { var date = 'start_date'; }
 
 var nowTemp = new Date();
 var now = new Date(nowTemp.getFullYear(), nowTemp.getMonth(), nowTemp.getDate(), 0, 0, 0, 0);

 var checkout = $('#' + date).datepicker({
     beforeShowDay: function (date) {
      return date.valueOf() >= now.valueOf();
     }
 }).on('changeDate', function (ev) {
     checkout.hide();
 }).data('datepicker');
};

Friday, 29 November 2013

Reload the Page via AJAX using Jquery

/** Reload the Page via AJAX using Jquery. */
(function () {
 $('#dvLoading').fadeOut(10); // To Switch Off the loader..

 location.reload();
 
} ()); 

Wednesday, 27 November 2013

To serialise the Input Form field by ID using Jquery

/** To serialise the Input Form field by ID using Jquery. */
var formData = new FormData(document.getElementById("fieldId"));
alert(formData);

Wednesday, 20 November 2013

Jquery function to auto scroll to the page to any position in Javascript

Please find the below function to make auto scroll of the page based on the parameter provided.

/** Auto Scroll to Top. */
var autoScrollToTop = function (value) { 
 
 //var scrollTopVal = 90; 
 if (typeof value == 'undefined') { 
  var scrollTopVal = 90;
 }
 else if ((value != "") && isNaN(value)) {
  scrollTopVal = $(value).offset().top;
 }
 else if (value > 0 ) {
  scrollTopVal = value;
 }
 //alert(scrollTopVal);
 $('html, body').animate({ scrollTop: scrollTopVal }, 500); // 500 (mili second) or 'slow'
};

// The function can be called as below;
autoScrollToTop() // Type: Blank, (Default:90)-> Scroll to 90px from top.
autoScrollToTop(0) // Type: Zero -> Top scroll to very top
autoScrollToTop(150) // Type: Numeric -> Scroll to Provided Numeric value(150px) from top.
autoScrollToTop('.className'); // Type: 'className' -> Auto calculate the distance from top to that className component
autoScrollToTop('#elementID'); // Type: 'elementID' -> Auto calculate the distance from top to that elementIDcomponent


Wednesday, 30 October 2013

Codeigniter Pagination problem to locate the current page (if using CI default Library), AJAX Pagination Calls

If you are using default CI Pagination library then it would be chances of displaying the current page active although results status is displaying correctly.

In particular, when you are using config/routes.php to rewrite the URLs.

Well, if that case, you can resolve that issue by adding the uri_segment's value while initializing the pagination as below;

PS:  First find which segment of URI carries the page value, then add the segment value (not page value coz once you provide segment value then, it will use it to pull out the page value)
// Locate the uri_segment to locate the current page value.
$pagination['uri_segment'] = 3; 
Also, if you are wondering how to find the uri_segment value, then use below code to print all uri_segments array
$segments = $this->uri->segment_array();
print_r($segments);
Please find the sample pagination code as below;
$pagination = array();
$pagination['start']  = $start+1;
$pagination['limit']  = $limit;
$pagination['per_page'] = $limit;
$pagination['ipage']  = $ipage;
$pagination['total_rows'] = $this->m_yourmodel->function_result_count($where=array()); // only pull the approved ones.
$pagination['anchor_class'] = 'class="loadAjaxPage" '; // This class is added to make a AJAX Call if you want to load the pages via AJAX
$pagination['offset']  = ($start+$limit); // This is just for the View;

$pagination['uri_segment'] = 3; // Locate the uri_segment to locate the current page value.

$this->load->library('pagination');
$this->pagination->initialize($pagination);
a$pagination['page_links'] = $this->pagination->create_links();

To Load the Page from AJAX Call
Also I have added the loadAjaxPage class name on anchor_class pagination variable to load the page from AJAX calls.
// This class is added to make a AJAX Call if you want to load the pages via 
$pagination['anchor_class'] = 'class="loadAjaxPage" ';