~mortenoh/+junk/dhis2-detailed-import-export

« back to all changes in this revision

Viewing changes to local/in/dhis-web-dashboard/src/main/webapp/dhis-web-dashboard/javascript/lists.js

  • Committer: larshelge at gmail
  • Date: 2009-03-03 16:46:36 UTC
  • Revision ID: larshelge@gmail.com-20090303164636-2sjlrquo7ib1gf7r
Initial check-in

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
/*
 
3
 * Move selected elements in a list to the target list
 
4
 */
 
5
function moveSelectedById( fromListId, targetListId )
 
6
{
 
7
    var fromList = document.getElementById( fromListId );
 
8
    var targetList = document.getElementById( targetListId );
 
9
 
 
10
    moveSelected( fromList, targetList );
 
11
}
 
12
 
 
13
function moveSelected( fromList, targetList )
 
14
{
 
15
    if ( fromList.selectedIndex == -1 )
 
16
    {
 
17
        return;
 
18
    }
 
19
 
 
20
    while ( fromList.selectedIndex > -1 )
 
21
    {
 
22
        option = fromList.options[ fromList.selectedIndex ];
 
23
        fromList.remove( fromList.selectedIndex );
 
24
        targetList.add(option, null);
 
25
        option.selected = true;
 
26
    }
 
27
}
 
28
 
 
29
/*
 
30
 * Move all elements in a list to the target list
 
31
 */
 
32
function moveAllById( fromListId, targetListId )
 
33
{
 
34
    var fromList = document.getElementById( fromListId );
 
35
    var targetList = document.getElementById( targetListId );
 
36
 
 
37
    moveAll( fromList, targetList );
 
38
}
 
39
 
 
40
function moveAll( fromList, targetList )
 
41
{
 
42
    for ( var i = fromList.options.length - 1; i >= 0; i-- )
 
43
    {
 
44
        option = fromList.options[i];
 
45
        fromList.remove( i );
 
46
        targetList.add(option, null);
 
47
        option.selected = true;
 
48
    }
 
49
}
 
50
 
 
51
/*
 
52
 * Clears the list
 
53
 */
 
54
function clearListById( listId )
 
55
{
 
56
    var list = document.getElementById( listId );
 
57
    
 
58
    clearList( list );
 
59
}
 
60
 
 
61
function clearList( list )
 
62
{
 
63
    list.options.length = 0;
 
64
}
 
65
 
 
66
/*
 
67
 * Returns true if the list contains the value
 
68
 */
 
69
function listContainsById( listId, value )
 
70
{
 
71
    var list = document.getElementById( listId );
 
72
    
 
73
    return listContains( list, value );
 
74
}
 
75
 
 
76
function listContains( list, value )
 
77
{
 
78
    for ( var i = 0; i < list.options.length; i++ )
 
79
    {
 
80
        if ( list.options[i].value == value )
 
81
        {
 
82
            return true;
 
83
        }
 
84
    }
 
85
 
 
86
    return false;
 
87
}
 
88
 
 
89
/*
 
90
 * Marks all elements in a list as selected
 
91
 */
 
92
function selectAllById( listId )
 
93
{
 
94
        var list = document.getElementById( listId );
 
95
        
 
96
        selectAll( list );
 
97
}
 
98
 
 
99
function selectAll( list )
 
100
{
 
101
        for ( var i = 0; i < list.options.length; i++ )
 
102
        {
 
103
                list.options[i].selected = true;
 
104
        }
 
105
}
 
106
 
 
107
/*
 
108
 * Marks all elements in a list as not selected
 
109
 */
 
110
function deselectAllById( listId )
 
111
{
 
112
        var list = document.getElementById( listId );
 
113
        
 
114
        deselectAll( list );
 
115
}
 
116
 
 
117
function deselectAll( list )
 
118
{
 
119
        for ( var i = 0; i < list.options.length; i++ )
 
120
        {
 
121
                list.options[i].selected = false;
 
122
        }
 
123
}