/**
 * Implements hook_block_info().
 */
function custom_home_block_info() {
  var blocks = {};
  blocks['custom_home_block'] = {
    delta: 'custom_home_block',
    module: 'custom_home'
  };
  return blocks;
}

function delay(callback, ms) {
  var timer = 0;
  return function() {
    var context = this, args = arguments;
    clearTimeout(timer);
    timer = setTimeout(function () {
      callback.apply(context, args);
    }, ms || 0);
  };
}

function myFunction() { 
    $('#myInput').keyup(delay(function (e) {  
         
        var input = document.getElementById("myInput").value; 
        if(input){
            drupalgap_goto("home/"+input);
        }
    }, 500));
}
/**
 * Implements hook_block_view().
 */
function custom_home_block_view(delta, region) {
    var content = {};
    if (delta == 'custom_home_block') { 
        var uid = Drupal.user.uid;
        var canteen_param = "'product-categorywise/74'";
        var freeparking_param = "'product-categorywise/55'";
        var freewifi_param = "'product-categorywise/27'";
        var freeyoga_param = "'product-categorywise/75'";
        content = '<img src="app/modules/custom/custom_home/images/balgriha.jpg" style="width:100% !important;height:180px;">';
       // content += '<div>Our rooms offer basic amenities with a sleeping area, a separate bathroom, an equipped kitchenette</div>';
        //content = "<form><input type='search' name='mkeyword' id='myInput' onkeyup='myFunction()' style='width:100%;' placeholder='Search your favourite products' style='background:#f4f4f4;'></form>";
        content += '<div class="container" style="display: flex; flex-wrap: nowrap; height: 120px; overflow-x: auto; width: auto;">';
        content += '<table style="width:100%">';
        content += '<tbody>';
        content += '<tr align="center">';
        content += '<td width="20%"><a href="#" style="text-decoration:none;color:#444444;font-weight:normal;" onclick="javascript:drupalgap_goto('+ canteen_param +', {});"><img src="app/modules/custom/custom_home/images/restaurant.png" style="border-radius:8%;width:70px;height:70px;"><br><span style="font-size:12px;">Canteen</span></a></td>';
        content += '<td width="20%"><a href="#" style="text-decoration:none;color:#444444;font-weight:normal;" onclick="javascript:drupalgap_goto('+ freeparking_param +', {});"><img src="app/modules/custom/custom_home/images/freeparking.png" style="border-radius:8%;width:70px;height:70px;"><br><span style="font-size:12px;">Free Parking</span></a></td>';
        content += '<td width="20%"><a href="#" style="text-decoration:none;color:#444444;font-weight:normal;" onclick="javascript:drupalgap_goto('+ freewifi_param +', {});"><img src="app/modules/custom/custom_home/images/freewifi.png" style="border-radius:8%;width:70px;height:70px;"><br><span style="font-size:12px;">Free Wifi</span></a></td>';
        content += '<td width="20%"><a href="#" style="text-decoration:none;color:#444444;font-weight:normal;" onclick="javascript:drupalgap_goto('+ freeyoga_param +', {});"><img src="app/modules/custom/custom_home/images/spa.png" style="border-radius:8%;width:70px;height:70px;"><br><span style="font-size:12px;">Free Yoga</span></a></td>';
        content += '</tr>';
        content += '</tbody>';
        content += '</table>';
        content += '</div><br>';  
    }
    
    return content;
}
//////////////

/**
 * Implements hook_menu().
 */
function custom_home_menu() {
  try {
    var items = {};
    items['home'] = {
      title: 'Donate To Gandhi Vidya Mandir',
      page_callback: 'custom_home_list_page',
      options:{
          reloadPage:true
       }
    }; 
    return items;
  }
  catch (error) {
    console.log('custom_home_menu - ' + error);
  }
}
 
/////////////////////////////////////////////////
/**
 * Page callback function for custom_page title_callback.
 */
function custom_home_list_page() {
  try {
    var content = {};
    
    //var content_param = "'content-list'"; 
    var content_param = "'https://donategvm.iaseuniversityonline.org/donate/admin/content-list', '_blank', 'location=yes'";
    var userlist_param = "'https://donategvm.iaseuniversityonline.org/donate/admin/user-list', '_blank', 'location=yes'";
    //var donate_param = "'node/3'";
    var donate_param = "'https://donategvm.iaseuniversityonline.org/donate/donateform', '_blank', 'location=yes'"; 
    var donations_param = "'https://donategvm.iaseuniversityonline.org/donate/admin/manage-donations', '_blank', 'location=yes'";
    var totalpayment_param = "'https://donategvm.iaseuniversityonline.org/donate/admin/total-payment-done', '_blank', 'location=yes'";
    var alldonations_param = "'https://donategvm.iaseuniversityonline.org/donate/admin/all-donations', '_blank', 'location=yes'";
    var uid = Drupal.user.uid;
    var rolesarray = Drupal.user.roles;
    
    if(uid > 0){
        var uname = "Hi " + Drupal.user.name + ',';
        var uemail = Drupal.user.mail;
    }else{
        var uname = "Hi User,";
        var uemail = '';
    }
    
     
    
    if(uid > 0){
        if (rolesarray.length != 0) {
            $.each(rolesarray, function(role_id, role) { 
                if(role=="sitemanager" || role=="administrator"){
                    content['home_block_user'] = {
                       markup: '<div style="margin:10px 10px;"><table width="100%" border="0" cellspacing="0" cellpadding="1"><tr><td width="50px"><img src="app/modules/custom/custom_home/images/user.png" style="width:40px;height:40px;"></td> <td valign="top" style="padding-left:2px;"><span style="font-size:13px;color:#444444;">'+ uname +'</span><br><span style="font-size:12px;color:#444444;">'+ uemail +'</span</td></tr></table> </div>'
                    };
                    content['home_block_one'] = {
                       markup: '<div class="ui-grid-a"><div class="ui-block-a"><div class="ui-bar"><a style="font-size:13px;text-decoration:none;text-shadow:none;font-weight:normal;background-color:#ffffff;background-image: linear-gradient(to right, #ffffff , #ffffff);color:#444444;height:160px;" href="#" onclick="javascript:window.open('+ content_param +');"><br><br><img src="app/modules/custom/custom_home/images/b_content.png" style="width:70px;height:70px;border-radius:50%"><br><br>Content<br></a></div></div><div class="ui-block-b"><div class="ui-bar"><a style="font-size:13px;text-decoration:none;text-shadow:none;background-color:#ffffff;background-image: linear-gradient(to right, #ffffff , #ffffff);color:#444444;font-weight:normal;height:160px;" href="#" onclick="javascript:window.open('+ userlist_param +');"><br><br><img src="app/modules/custom/custom_home/images/b_manageuser.png" style="width:70px;height:70px;border-radius:50%"><br><br>User<br></a></div></div></div>'
                    };
                    /*content['home_block_two'] = {
                       markup: '<div class="ui-grid-a"><div class="ui-block-a"><div class="ui-bar"><a style="font-size:13px;text-decoration:none;text-shadow:none;font-weight:normal;background-color:#ffffff;background-image: linear-gradient(to right, #ffffff , #ffffff);color:#444444;height:160px;" href="#" onclick="javascript:window.open('+ donate_param +');"><br><br><img src="app/modules/custom/custom_home/images/b_donate.png" style="width:70px;height:70px;border-radius:50%"><br><br>Donate<br></a></div></div><div class="ui-block-b"><div class="ui-bar"><a style="font-size:13px;text-decoration:none;text-shadow:none;background-color:#ffffff;background-image: linear-gradient(to right, #ffffff , #ffffff);color:#444444;font-weight:normal;height:160px;" href="#" onclick="javascript:window.open('+ donations_param +');"><br><br><img src="app/modules/custom/custom_home/images/b_donations.png" style="width:70px;height:70px;border-radius:50%"><br><br>Donations<br></a></div></div></div>'
                    };
                    content['home_block_two'] = {
                       markup: '<div class="ui-grid-a"><div class="ui-block-a"><div class="ui-bar"><a style="font-size:13px;text-decoration:none;text-shadow:none;font-weight:normal;background-color:#ffffff;background-image: linear-gradient(to right, #ffffff , #ffffff);color:#444444;height:160px;" href="#" onclick="javascript:window.open('+ donate_param +');"><br><br><img src="app/modules/custom/custom_home/images/b_donate.png" style="width:70px;height:70px;border-radius:50%"><br><br>Donate<br></a></div></div><div class="ui-block-b"><div class="ui-bar"><a style="font-size:13px;text-decoration:none;text-shadow:none;background-color:#ffffff;background-image: linear-gradient(to right, #ffffff , #ffffff);color:#444444;font-weight:normal;height:160px;" href="#" onclick="javascript:window.open('+ donations_param +');"><br><br><img src="app/modules/custom/custom_home/images/b_donations.png" style="width:70px;height:70px;border-radius:50%"><br><br>Donations<br></a></div></div></div>'
                    }; */
                    content['home_block_three'] = {
                       markup: '<div class="ui-grid-a"><div class="ui-block-a"><div class="ui-bar"><a style="font-size:13px;text-decoration:none;text-shadow:none;font-weight:normal;background-color:#ffffff;background-image: linear-gradient(to right, #ffffff , #ffffff);color:#444444;height:160px;" href="#" onclick="javascript:window.open('+ alldonations_param +');"><br><br><img src="app/modules/custom/custom_home/images/b_donations.png" style="width:70px;height:70px;border-radius:50%"><br><br>All Donations<br></a></div></div><div class="ui-block-b"><div class="ui-bar"><a style="font-size:13px;text-decoration:none;text-shadow:none;background-color:#ffffff;background-image: linear-gradient(to right, #ffffff , #ffffff);color:#444444;font-weight:normal;height:160px;" href="#" onclick="javascript:window.open('+ totalpayment_param +');"><br><br><img src="app/modules/custom/custom_home/images/b_donations.png" style="width:70px;height:70px;border-radius:50%"><br><br>Total Payment Done<br></a></div></div></div>'
                    }; 
                     
                }else if(role=="donation manager"){
                    content['home_block_user'] = {
                       markup: '<div style="margin:10px 10px;"><table width="100%" border="0" cellspacing="0" cellpadding="1"><tr><td width="50px"><img src="app/modules/custom/custom_home/images/user.png" style="width:40px;height:40px;"></td> <td valign="top" style="padding-left:2px;"><span style="font-size:13px;color:#444444;">'+ uname +'</span><br><span style="font-size:12px;color:#444444;">'+ uemail +'</span</td></tr></table> </div>'
                    };
                    /*content['home_block_two'] = {
                       markup: '<div class="ui-grid-a"><div class="ui-block-a"><div class="ui-bar"><a style="font-size:13px;text-decoration:none;text-shadow:none;font-weight:normal;background-color:#ffffff;background-image: linear-gradient(to right, #ffffff , #ffffff);color:#444444;height:160px;" href="#" onclick="javascript:window.open('+ donate_param +');"><br><br><img src="app/modules/custom/custom_home/images/b_donate.png" style="width:70px;height:70px;border-radius:50%"><br><br>Donate<br></a></div></div><div class="ui-block-b"><div class="ui-bar"><a style="font-size:13px;text-decoration:none;text-shadow:none;background-color:#ffffff;background-image: linear-gradient(to right, #ffffff , #ffffff);color:#444444;font-weight:normal;height:160px;" href="#" onclick="javascript:window.open('+ donations_param +');"><br><br><img src="app/modules/custom/custom_home/images/b_donations.png" style="width:70px;height:70px;border-radius:50%"><br><br>Donations<br></a></div></div></div>'
                    };*/
                    content['home_block_three'] = {
                       markup: '<div class="ui-grid-a"><div class="ui-block-a"><div class="ui-bar"><a style="font-size:13px;text-decoration:none;text-shadow:none;font-weight:normal;background-color:#ffffff;background-image: linear-gradient(to right, #ffffff , #ffffff);color:#444444;height:160px;" href="#" onclick="javascript:window.open('+ alldonations_param +');"><br><br><img src="app/modules/custom/custom_home/images/b_donations.png" style="width:70px;height:70px;border-radius:50%"><br><br>All Donations<br></a></div></div><div class="ui-block-b"><div class="ui-bar"><a style="font-size:13px;text-decoration:none;text-shadow:none;background-color:#ffffff;background-image: linear-gradient(to right, #ffffff , #ffffff);color:#444444;font-weight:normal;height:160px;" href="#" onclick="javascript:window.open('+ totalpayment_param +');"><br><br><img src="app/modules/custom/custom_home/images/b_donations.png" style="width:70px;height:70px;border-radius:50%"><br><br>Total Payment Done<br></a></div></div></div>'
                    }; 
                }else{
                    var about_param = "'node/2'";
                    var donate_param = "'node/3'";
                    var onlineproduct_param = "'node/8'"; 
                    var contact_param = "'node/14'";
                    var aboutchuran_param = "'node/7'";
                    var donateonline_param = "'https://donategvm.iaseuniversityonline.org/donate/donateform', '_blank', 'location=yes'"; 
                    content['home_block_user'] = {
                       markup: '<div style="margin:10px 10px;"><table width="100%" border="0" cellspacing="0" cellpadding="1"><tr><td width="50px"><img src="app/modules/custom/custom_home/images/user.png" style="width:40px;height:40px;"></td> <td valign="top" style="padding-left:2px;"><span style="font-size:13px;color:#444444;">'+ uname +'</span><br><span style="font-size:12px;color:#444444;">'+ uemail +'</span</td></tr></table> </div>'
                    };
                    content['home_block_one'] = {
                       markup: '<br><div class="ui-grid-a"><div class="ui-block-a"><div class="ui-bar"><a style="font-size:14px;text-decoration:none;text-shadow:none;font-weight:normal;background-color:#ffffff;background-image: linear-gradient(to right, #ffffff , #ffffff);color:#444444;height:160px;" href="#" onclick="javascript:drupalgap_goto('+ about_param +', {});"><br><br><img src="app/modules/custom/custom_home/images/b_about.png" style="width:70px;height:70px;border-radius:50%"><br><br>Abous GVM<br></a></div></div><div class="ui-block-b"><div class="ui-bar"><a style="font-size:14px;text-decoration:none;text-shadow:none;background-color:#ffffff;background-image: linear-gradient(to right, #ffffff , #ffffff);color:#444444;font-weight:normal;height:160px;" href="#" onclick="javascript:drupalgap_goto('+ aboutchuran_param +', {});"><br><br><img src="app/modules/custom/custom_home/images/b_about.png" style="width:70px;height:70px;border-radius:50%"><br><br>About Churan<br></a></div></div></div>'
                    };
                    content['home_block_two'] = {
                       markup: '<div class="ui-grid-a"><div class="ui-block-a"><div class="ui-bar"><a style="font-size:14px;text-decoration:none;text-shadow:none;font-weight:normal;background-color:#ffffff;background-image: linear-gradient(to right, #ffffff , #ffffff);color:#444444;height:160px;" href="#" onclick="javascript:drupalgap_goto('+ donate_param +', {});"><br><br><img src="app/modules/custom/custom_home/images/b_donate.png" style="width:70px;height:70px;border-radius:50%"><br><br>Donate<br></a></div></div><div class="ui-block-b"><div class="ui-bar"><a style="font-size:14px;text-decoration:none;text-shadow:none;background-color:#ffffff;background-image: linear-gradient(to right, #ffffff , #ffffff);color:#444444;font-weight:normal;height:160px;" href="#" onclick="javascript:window.open('+ donateonline_param +');"><br><br><img src="app/modules/custom/custom_home/images/b_donate.png" style="width:70px;height:70px;border-radius:50%"><br><br>Donate Online<br></a></div></div></div>'
                    };
                    content['home_block_three'] = {
                       markup: '<div class="ui-grid-a"><div class="ui-block-a"><div class="ui-bar"><a style="font-size:14px;text-decoration:none;text-shadow:none;font-weight:normal;background-color:#ffffff;background-image: linear-gradient(to right, #ffffff , #ffffff);color:#444444;height:160px;" href="#" onclick="javascript:drupalgap_goto('+ onlineproduct_param +', {});"><br><br><img src="app/modules/custom/custom_home/images/b_facility.png" style="width:70px;height:70px;border-radius:50%"><br><br>Online Products<br></a></div></div><div class="ui-block-b"><div class="ui-bar"><a style="font-size:14px;text-decoration:none;text-shadow:none;background-color:#ffffff;background-image: linear-gradient(to right, #ffffff , #ffffff);color:#444444;font-weight:normal;height:160px;" href="#" onclick="javascript:drupalgap_goto('+ contact_param +', {});"><br><br><img src="app/modules/custom/custom_home/images/b_contact.png" style="width:70px;height:70px;border-radius:50%"><br><br>Contact Us<br></a></div></div></div>'
                    }; 
                }
            });
        }
    }else{
        var about_param = "'node/2'";
        var donate_param = "'node/3'";
        var onlineproduct_param = "'node/8'"; 
        var contact_param = "'node/14'";
        var aboutchuran_param = "'node/7'";
        var donateonline_param = "'https://donategvm.iaseuniversityonline.org/donate/donateform', '_blank', 'location=yes'"; 
         
        content['home_block_image'] = {
           markup: '<img src="app/modules/custom/custom_home/images/donatebg.jpeg" style="width:100% !important;height:200px;">'
        };
        content['home_block_one'] = {
           markup: '<br><div class="ui-grid-a"><div class="ui-block-a"><div class="ui-bar"><a style="font-size:14px;text-decoration:none;text-shadow:none;font-weight:normal;background-color:#ffffff;background-image: linear-gradient(to right, #ffffff , #ffffff);color:#444444;height:160px;" href="#" onclick="javascript:drupalgap_goto('+ about_param +', {});"><br><br><img src="app/modules/custom/custom_home/images/b_about.png" style="width:70px;height:70px;border-radius:50%"><br><br>Abous GVM<br></a></div></div><div class="ui-block-b"><div class="ui-bar"><a style="font-size:14px;text-decoration:none;text-shadow:none;background-color:#ffffff;background-image: linear-gradient(to right, #ffffff , #ffffff);color:#444444;font-weight:normal;height:160px;" href="#" onclick="javascript:drupalgap_goto('+ aboutchuran_param +', {});"><br><br><img src="app/modules/custom/custom_home/images/b_about.png" style="width:70px;height:70px;border-radius:50%"><br><br>About Churan<br></a></div></div></div>'
        };
        content['home_block_two'] = {
           markup: '<div class="ui-grid-a"><div class="ui-block-a"><div class="ui-bar"><a style="font-size:14px;text-decoration:none;text-shadow:none;font-weight:normal;background-color:#ffffff;background-image: linear-gradient(to right, #ffffff , #ffffff);color:#444444;height:160px;" href="#" onclick="javascript:drupalgap_goto('+ donate_param +', {});"><br><br><img src="app/modules/custom/custom_home/images/b_donate.png" style="width:70px;height:70px;border-radius:50%"><br><br>Donate<br></a></div></div><div class="ui-block-b"><div class="ui-bar"><a style="font-size:14px;text-decoration:none;text-shadow:none;background-color:#ffffff;background-image: linear-gradient(to right, #ffffff , #ffffff);color:#444444;font-weight:normal;height:160px;" href="#" onclick="javascript:window.open('+ donateonline_param +');"><br><br><img src="app/modules/custom/custom_home/images/b_donate.png" style="width:70px;height:70px;border-radius:50%"><br><br>Donate Online<br></a></div></div></div>'
        };
        content['home_block_three'] = {
           markup: '<div class="ui-grid-a"><div class="ui-block-a"><div class="ui-bar"><a style="font-size:14px;text-decoration:none;text-shadow:none;font-weight:normal;background-color:#ffffff;background-image: linear-gradient(to right, #ffffff , #ffffff);color:#444444;height:160px;" href="#" onclick="javascript:drupalgap_goto('+ onlineproduct_param +', {});"><br><br><img src="app/modules/custom/custom_home/images/b_facility.png" style="width:70px;height:70px;border-radius:50%"><br><br>Online Products<br></a></div></div><div class="ui-block-b"><div class="ui-bar"><a style="font-size:14px;text-decoration:none;text-shadow:none;background-color:#ffffff;background-image: linear-gradient(to right, #ffffff , #ffffff);color:#444444;font-weight:normal;height:160px;" href="#" onclick="javascript:drupalgap_goto('+ contact_param +', {});"><br><br><img src="app/modules/custom/custom_home/images/b_contact.png" style="width:70px;height:70px;border-radius:50%"><br><br>Contact Us<br></a></div></div></div>'
        }; 
    } 
    return content;
  }
  catch (error) { console.log('custom_home_list_page - ' + error); }
}

 
 
