Tuesday, 19 July 2016

Shrinking of Navigation Menu on page load

Requirement:
Navigation menu should be shrinking on page load.

Challenges faced: 
 In Oracle Apex 5, universal theme the navigation menu is strengthening on default page load. If we want to shrink the menu we need to click on the  navigation menu controller.

Resolution:
1. Created a dynamic action with event as page load and condition as JavaScript Expression and value as                      $('#t_Button_navControl').attr('aria-expanded') === "true".
2. A true action is provided with JavaScript code as $('#t_Button_navControl').click(); 

Output:

Displaying of 7 Consecutive Dates in Report Header

Step 1:
Create a date field for selecting the date.
Step 2:
Create a report for displaying the data in those dates.
Step 3:
Enter the following code in the page header
Code:
$(function() {
    var month = new Array();
    month[0] = "Jan";
    month[1] = "Feb";
    month[2] = "Mar";
    month[3] = "Apr";
    month[4] = "May";
    month[5] = "Jun";
    month[6] = "Jul";
    month[7] = "Aug";
    month[8] = "Sep";
    month[9] = "Oct";
    month[10] = "Nov";
    month[11] = "Dec";
    var from_date = $("#P215_FROM_DATE").val();
  //alert('from_date'+from_date);
    var sec_date = new Date(from_date);
  //alert('sec_date'+sec_date));
    sec_date.setDate(sec_date.getDate() + 1);
  //alert(sec_date.setDate(sec_date.getDate() + 1));
    var date = new Date(from_date);
    var newdate = new Date(date.getFullYear(), date.getMonth(), date.getDate() + 1);
    var date1 = new Date(newdate);
  //var newdate1 = new Date(newdate.getFullYear(),newdate.getMonth()+1,newdate.getDate()+2);
    var dd = newdate.getDate();
    var mm = newdate.getMonth();
    var y = newdate.getFullYear();
    var someFormattedDate1 = dd + '-' + month[mm] + '-' + y;
  //alert(someFormattedDate1);
    var newdate1=new Date(date.getFullYear(),date.getMonth(),date.getDate()+2);
    dd=newdate1.getDate();
    mm=newdate1.getMonth();
    y=newdate1.getFullYear();
  //var dd1 = newdate.getDate() + 1;
  //alert('dd1'+dd1);
    var someFormattedDate2 = dd + '-' + month[mm] + '-' + y;
  //alert(someFormattedDate2);
    var newdate2=new Date(date.getFullYear(),date.getMonth(),date.getDate()+3);
    dd=newdate2.getDate();
    mm=newdate2.getMonth();
    y=newdate2.getFullYear();
  //var dd2 = newdate.getDate() + 2;
  //alert('dd2'+dd2);
    var someFormattedDate3 = dd + '-' + month[mm] + '-' + y;
 // alert(someFormattedDate3);
    var newdate3=new Date(date.getFullYear(),date.getMonth(),date.getDate()+4);
    dd=newdate3.getDate();
    mm=newdate3.getMonth();
    y=newdate3.getFullYear();
  //var dd3 = newdate.getDate() + 3;
  //alert('dd3'+dd3);
    var someFormattedDate4 = dd + '-' + month[mm] + '-' + y;
    var newdate4=new Date(date.getFullYear(),date.getMonth(),date.getDate()+5);
    dd=newdate4.getDate();
    mm=newdate4.getMonth();
    y=newdate4.getFullYear();
  //var dd4 = newdate.getDate() + 4;
  //alert('dd4'+dd4);
    var someFormattedDate5 = dd + '-' + month[mm] + '-' + y;
    var newdate5=new Date(date.getFullYear(),date.getMonth(),date.getDate()+6);
    dd=newdate5.getDate();
    mm=newdate5.getMonth();
    y=newdate5.getFullYear();
  //var dd5 = newdate.getDate() + 5;
  //alert('dd5'+dd5);
    var someFormattedDate6 = dd + '-' + month[mm] + '-' + y;
    var newdate6=new Date(date.getFullYear(),date.getMonth(),date.getDate()+7);
    dd=newdate6.getDate();
    mm=newdate6.getMonth();
    y=newdate6.getFullYear();
  //var dd6 = newdate.getDate() + 6;
  //alert(dd6);
    var someFormattedDate7 = dd + '-' + month[mm] + '-' + y;
    $('th[id="head1"]').html(from_date);
    $('th[id="head2"]').html(someFormattedDate1);
    $('th[id="head3"]').html(someFormattedDate2);
    $('th[id="head4"]').html(someFormattedDate3);
    $('th[id="head5"]').html(someFormattedDate4);
    $('th[id="head6"]').html(someFormattedDate5);
    $('th[id="head7"]').html(someFormattedDate6);
    $('th[id="head8"]').html(someFormattedDate7);
});

Removal of close button from Select2 plugin

Requirement:
The users who completed their tasks in selected Delivery PDVD must not be deleted from team allocation. Select2 plugin was used for selecting multiple  users, which will have a cross button to remove the users. The cross button must be disabled for the users who completed their tasks in the selected 
Delivery PDVD
Challenges faced: 
Select2 is an external plugin for selecting multiple values at a time. On default plugin don’t have any option to remove the close button. 
Solution:
1. Created a page level item to get all the completed users for selected Delivery PDVD.
2.  Created a dynamic action with event as on Page load and called a JavaScript function.
3. Added JavaScript code in the page header to check the users from the previous page item and removed the close icon.
function remove_close()
{
    var a=$("#P94_ROLE").val();
    //alert(a);
if (a.length!=0)
{
    var numbers = a.toString().split(',');
    for(var i = 0; i < numbers.length; i++)
{
    var b=numbers[i];
     $("ul.select2-choices li").each(function(){
 var s= $(this).text();
         s=s.trim()

   if (s==b)
     {
         var z=$(this).find("div").next().removeClass("select2-search-choice-close");
          //alert('s = '+s);
         
       }
         
    });
    
} 
}
} 
 Output:

Monday, 18 July 2016

HOLD / UNHOLD in APEX Report

In Report Attributes, Call below function in link - URL

function fun(a)
{
     //alert(a);
     var str = a.substring(4);
    // alert(str);
     str = parseInt(str, 10);
     str = pad(str,4);
     //alert(str);
     var id = "#f02_"+str;
     var hold = "#f14_"+str;
     var role = $("#f15_"+str).val();
     var b = $("#f16_"+str).val();
    // alert(b);
    //  alert(hold||''||id);
    if($(hold).val().length == 0||$(hold).val() == 'N')
        {
           
           $(id).closest("tr").find("input,button,textarea,select").attr("readonly", "true");
           $(id).closest("tr").find("input[type!='hidden'],select").on('mousedown', function(e) {return false;});
            $(id).closest("tr").find("a").on('click', function(e) {return false;});
             $(id).closest("tr").find("input[type='checkbox']").attr("onclick","return false");
          /* $(id).closest("tr").find("a").attr("href", "#");*/
           $(id).closest("tr").find("a").css("cursor", "default");
           $(id).closest("tr").find("td").css("background-color","#e6e6e6");
           $(id).closest("tr").find("a").css("color","#696969");
           $(hold).val('Y'); }
    else
        {
            $(id).closest("tr").find("input,button,textarea,select").removeAttr("readonly");
             $(id).closest("tr").find("input[type!='hidden'],select").off('mousedown');
             $(id).closest("tr").find("a").off('click');
            $(id).closest("tr").find("a").css("cursor", "auto");
            $(id).closest("tr").find("td").css("background-color","#FFFFFF");
             $(id).closest("tr").find("a").css("color","#009999");
           // $('#del_item').trigger('apexrefresh');
            $(hold).val('N');          
             if ((role =='Developer' || role =='Validator' || role =='Reviewer') && b != 'red') {
             $(hold).closest('tr').find("td[headers='TITLE'] a").attr( "href", "javascript:void(0);").css({"cursor":"default","color": "black"});
                                                                                                }
             else
                {
                    if ((role =='Developer' || role =='Validator' || role =='Reviewer') && b == 'red'){
                    $(hold).closest('tr').find("td[headers='TITLE'] a").attr( "href", "javascript:void(0);").css({"cursor":"default","color": "red"});
                                                                                                      }
               }
           if( role == 'Programming Manager')
                                       {
               $(hold).closest('tr').find("td[headers='OUTPUT_NAME'] a").attr( "href", "javascript:void(0);").css({"cursor":"default","color": "black"});
                                       }
            if (b == 'red')    
            {
             $(hold).closest('tr').find("td[headers='TITLE'] a").css({"color": "red"});
            }                      

            }
}

Key Controlled Report View in APEX

 Every application all over world is in fond of key controlled or having shortcuts to report view. I have implemented this with some Javascript.


Step:1:  By Default , report should not be visible , So we have added attribute to      region as: 

          Region Attributes : style= “display:none;”

Step: 2:  Create a new html region and following javascript code for key recognition    and report view :  [Shortcut Key: Ctrl+S]

<html>
        <head>
<script>
function test(e) {
 e = e || window.event; //Get event
 if (e.ctrlKey) {
 var c = e.which || e.keyCode; //Get key code
 switch (c) {
  case 83:// Block Ctrl+S
  e.preventDefault();     // Prevents Default Fuctionality
  e.stopPropagation();
  $("#TEST_REPORT").dialog();  // Opens Dialog
        }
    }
};
</script>
</head>

<body onkeydown="javascript:test(event);"> </body>
</html>

Global Alert Box in APEX

GLOBAL ALERT BOX is developed as we need customized alert boxes all over application. A region created in global page and been referred in dialog box wherever been called.

Step:1: Create region in global page with Static ID. 
       For Example: alert.
Step:2: For alert box, JQuery Dialog been called.Alert messages can be     dynamically changed and customized.
      $("#alert").html("Blank row already exists. Hence cannot add row");
// .html() - Dynamically we can change content of region
 $("#alert").dialog({modal:true,resizable: false,minHeight: 105,width:380,dialogClass: 'testclass'});
//$("#alert") - Global region referred for dialog.

Output: 





You can notice change of message dynamically.

Full View/ Normal View of Tabular Form Columns in APEX

                    
Step:1:
Create relation between table header and table data



<td class="t-Report-cell" rel="#COLUMN_HEADER_NAME#" #ALIGNMENT# headers="#COLUMN_HEADER_NAME#">#COLUMN_VALUE#</td> 

Step:2:
Normal View  

Functionality: Show / Hide required columns on-click 
Order the Columns accordingly,
  1.Create Button with dynamic action as Execute Javascript Code,
  2. For Example, If you have 25 columns, Arrange first 6 as your main visible columns
and so that you can form a loop and hide after 6, Use following Jquery inside your loop
 var a = $('.t-Report-report').find("td:eq("+i+")").attr("rel");
 $('.t-Report-report').find("th:eq("+i+"), td:eq("+i+")").hide();
 $('td[rel='+a+']').hide();
i                         Represents the nth column of <table> 
.t-Report-report            Class of the report
.find                      Finds the selector specified in braces
td:eq("+i+")               equals (eq) nth(i)  table data(td) 
.attr("rel")                Finds attribute rel
.hide()                    Hides the selector
Step:3:
Full View

Functionality: Show / Hide required columns on-click 
   1.Create Button with dynamic action as Execute Javascript Code,
   2. After main columns we should show remaining columns so that here loop starts         with last column of Normal View. Include following Jquery in loop, 
 var a = $('.t-Report-report').find("td:eq("+i+")").attr("rel");
 $('.t-Report-report').find("th:eq("+i+"), td:eq("+i+")").show();
 $('td[rel='+a+']').show();
i                         Represents the nth column of <table> 
.t-Report-report            Class of the report
.find                      Finds the selector specified in braces
td:eq("+i+")               equals (eq) nth(i)  table data(td) 
.attr("rel")                Finds attribute rel
.hide()                    Hides the selector


Output : Normal View 

Notice Buttons , Above is in Normal View. So, Full View button is displayed 

Output : Full View

Notice Buttons , Above is in Full View. So, Normal View button is displayed