Ignore:
Timestamp:
08/17/10 16:17:12 (14 years ago)
Author:
viani
Message:

Ticket #1135 - Merged r1990:3166 from /trunk/workflow into /branches/2.2/workflow

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2/workflow/js/userinterface/orgchartPrint.js

    r795 r3167  
     1/** 
     2* Show / Hide all employees 
     3*/ 
    14function toggleEmployeesVisibility() 
    25{ 
    36        if ($('#employeesVisibility').attr('checked')) 
    4                 $('div.employees').show(); 
     7                $('tr.employees').show(); 
    58        else 
    6                 $('div.employees').hide(); 
    7 } 
    8  
     9                $('tr.employees').hide(); 
     10} 
     11 
     12/** 
     13* Highlight supervisor names? 
     14*/ 
    915function toggleHighlightSupervisor() 
    1016{ 
     
    1521} 
    1622 
     23/** 
     24* Show / Hide orgchart area path visibility 
     25*/ 
    1726function toggleOrgchartPathVisibility() 
    1827{ 
    1928        if ($('#orgchartPathVisibility').attr('checked')) 
    20         { 
    2129                $('span.orgchartPath').css('visibility', 'visible').show(); 
    22         } 
    23         else 
    24         { 
     30        else { 
    2531                if ($('#orgchartPathIndentation').attr('checked')) 
    2632                        $('span.orgchartPath').show().css('visibility', 'hidden'); 
     
    3036} 
    3137 
     38/** 
     39* Group by area or show a single list alphabetically ordered 
     40* For large sets of data this function may be potencially slow 
     41*/ 
     42function toggleGroupByArea() 
     43{ 
     44        /* remove the table and compute it again */ 
     45        $('#employee_table').remove(); 
     46 
     47        if ($('#groupByArea').attr('checked')) 
     48                showGroupedByArea(); 
     49        else 
     50                showUngrouped(); 
     51 
     52        /* updating supervisor highlight and orgchart path visibility */ 
     53        toggleHighlightSupervisor(); 
     54        toggleOrgchartPathVisibility(); 
     55} 
     56 
     57/** 
     58* Centralize the creation of table rows for employees. 
     59* 'showAreaColumn' specifies whether the second column will be shown 
     60*/ 
     61function createEmployeeRow(area_id, user_id, showAreaColumn) 
     62{ 
     63        /* set a special 'class' if the employee is a supervisor one */ 
     64        class_name = 'employee'; 
     65        if (areas[area_id].titular_funcionario_id == areas[area_id].employees[user_id].funcionario_id) 
     66                class_name += 'supervisor'; 
     67 
     68        /* creating the row. */ 
     69        element = $('<tr></tr>') 
     70                                /* name: first column */ 
     71                                .append( 
     72                                                $('<td></td>') 
     73                                                        .append( 
     74                                                                $('<span></span>') 
     75                                                                        .addClass(class_name) 
     76                                                                        .append(areas[area_id].employees[user_id].cn) 
     77                                                        ) 
     78                                                        .css('width', '70%') 
     79                                                ); 
     80 
     81        /* area: second (optional) column */ 
     82        if (showAreaColumn) 
     83                element.append( 
     84                                                $('<td>' + areas[area_id].sigla + '</td>') 
     85                                                        .css('width', '15%') 
     86                                        ); 
     87 
     88        /* telephone: last column */ 
     89        element.append( 
     90                                        $('<td>' + areas[area_id].employees[user_id].telephoneNumber + '</td>') 
     91                                                .css('width', '20%') 
     92                                        ) 
     93                                .addClass('employees'); 
     94 
     95        return element; 
     96} 
     97 
     98/** 
     99* Creating a employee table grouped by area 
     100*/ 
     101function showGroupedByArea() 
     102{ 
     103        var table = $('<table></table>').css('width', '90%').attr('id', 'employee_table'); 
     104        var i, j; 
     105 
     106        /* iterating over areas */ 
     107        for (i=0; i < areas.length; i++) { 
     108 
     109                /* inserting area header */ 
     110                table.append( 
     111                                $('<tr></tr>') 
     112                                .append( 
     113                                        $('<th></th>') 
     114                                                .css('text-align', 'left') 
     115                                                .css('height', '30') 
     116                                                .append( 
     117                                                        $('<span></span>') 
     118                                                                .addClass('orgchartPath') 
     119                                                                .append(areas[i].orgchartPath) 
     120                                                                ) 
     121                                                .append(areas[i].sigla) 
     122                                        ) 
     123                ); 
     124 
     125                /* creating employee rows */ 
     126                for (j=0; j < areas[i].employees.length; j++) 
     127                        table.append(createEmployeeRow(i, j)); 
     128        } 
     129        $('#areas_content').append(table); 
     130} 
     131 
     132/** 
     133* Creating employess ordered alphabetically and ungrouped. In this 
     134* function we implemented a 'merge' of all area's employee arrays. 
     135* 
     136* Be careful if you are going to update this code... =) 
     137*/ 
     138function showUngrouped() 
     139{ 
     140        var table = $('<table></table>').css('width', '90%').attr('id', 'employee_table'); 
     141        var i, less, end; 
     142 
     143        /* creating and reseting indexes */ 
     144        for (i=0; i < areas.length; i++) 
     145                areas[i].index = 0; 
     146 
     147        /* */ 
     148        while (true) { 
     149                less = -1; 
     150                end = true; 
     151 
     152                /* searching the area with smallest employee name */ 
     153                for (i=0; i < areas.length; i++) { 
     154 
     155                        /* if this area have employees left */ 
     156                        if (areas[i].employees.length > areas[i].index) { 
     157 
     158                                /* if it's the first area reached in this iteration */ 
     159                                if (less == -1) 
     160                                        less = i; 
     161 
     162                                /* updating less */ 
     163                                if (areas[i].employees[areas[i].index].cn < areas[less].employees[areas[less].index].cn) 
     164                                        less = i; 
     165 
     166                                /* so, we are not done */ 
     167                                end = false; 
     168                        } 
     169                } 
     170                /* if we are done */ 
     171                if (end) break; 
     172 
     173                /* inserting the row */ 
     174                table.append(createEmployeeRow(less, areas[less].index, true)); 
     175                areas[less].index++; 
     176        } 
     177        $('#areas_content').append(table); 
     178} 
     179 
     180/** 
     181* Print me! 
     182*/ 
    32183function printAction() 
    33184{ 
     
    35186} 
    36187 
     188/** 
     189* Binding events to HTML elements 
     190*/ 
    37191function bindEvents() 
    38192{ 
    39193        $('#employeesVisibility').click(toggleEmployeesVisibility); 
     194        $('#groupByArea').click(toggleGroupByArea); 
    40195        $('#highlightSupervisor').click(toggleHighlightSupervisor); 
    41196        $('#orgchartPathVisibility').click(toggleOrgchartPathVisibility); 
     
    45200function initialSetup() 
    46201{ 
     202        toggleGroupByArea(); 
    47203        toggleEmployeesVisibility(); 
    48204        toggleHighlightSupervisor(); 
     
    50206} 
    51207 
     208/** 
     209* Call setup functions on body onload. 
     210*/ 
    52211function pageLoad() 
    53212{ 
Note: See TracChangeset for help on using the changeset viewer.