~dhis2-devs-core/dhis2/dhis2-patient-tz

« back to all changes in this revision

Viewing changes to local/tz/dhis-web-maintenance-patient-tz/src/main/webapp/dhis-web-maintenance-patient/javascript/programAttribute.js

  • Committer: John Francis Mukulu
  • Date: 2011-08-09 06:36:18 UTC
  • mfrom: (4244.1.21 dhis2)
  • Revision ID: john.f.mukulu@gmail.com-20110809063618-wad1pcc9fd1mnc6k
[merge]

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// -----------------------------------------------------------------------------
2
 
// View details
3
 
// -----------------------------------------------------------------------------
4
 
 
5
 
function showProgramAttributeDetails( programAttributeId )
6
 
{
7
 
        $.ajax({
8
 
                url: 'getProgramAttribute.action?id=' + programAttributeId,
9
 
                cache: false,
10
 
                dataType: "xml",
11
 
                success: programAttributeReceived
12
 
        });
13
 
}
14
 
 
15
 
function programAttributeReceived( programAttributeElement )
16
 
{
17
 
        setInnerHTML( 'idField', $( programAttributeElement).find('id' ).text() );
18
 
        setInnerHTML( 'nameField',  $( programAttributeElement).find('name').text() );  
19
 
    setInnerHTML( 'descriptionField', $( programAttributeElement).find('description').text() );
20
 
    
21
 
    var valueTypeMap = { 'NUMBER':i18n_number, 'BOOL':i18n_yes_no, 'TEXT':i18n_text, 'DATE':i18n_date, 'COMBO':i18n_combo };
22
 
    var valueType =  $( programAttributeElement).find('valueType' ).text();    
23
 
        
24
 
    setInnerHTML( 'valueTypeField', valueTypeMap[valueType] );    
25
 
   
26
 
    showDetails();
27
 
}
28
 
 
29
 
// -----------------------------------------------------------------------------
30
 
// Remove Program Attribute
31
 
// -----------------------------------------------------------------------------
32
 
 
33
 
function removeProgramAttribute( programAttributeId, name )
34
 
{
35
 
        removeItem( programAttributeId, name, i18n_confirm_delete, 'removeProgramAttribute.action' );   
36
 
}
37
 
 
38
 
ATTRIBUTE_OPTION = 
39
 
{
40
 
        selectValueType : function (this_)
41
 
        {
42
 
                if ( jQuery(this_).val() == "COMBO" )
43
 
                {
44
 
                        jQuery("#attributeComboRow").show();
45
 
                        if( jQuery("#attrOptionContainer").find("input").length ==0 ) 
46
 
                        {
47
 
                                ATTRIBUTE_OPTION.addOption();
48
 
                                ATTRIBUTE_OPTION.addOption();
49
 
                        }
50
 
                }else {
51
 
                        jQuery("#attributeComboRow").hide();
52
 
                }
53
 
        },
54
 
        checkOnSubmit : function ()
55
 
        {
56
 
                if( jQuery("#valueType").val() != "COMBO" ) 
57
 
                {
58
 
                        jQuery("#attrOptionContainer").children().remove();
59
 
                        return true;
60
 
                }else {
61
 
                        $("input","#attrOptionContainer").each(function(){ 
62
 
                                if( !jQuery(this).val() )
63
 
                                        jQuery(this).remove();
64
 
                        });
65
 
                        if( $("input","#attrOptionContainer").length < 2)
66
 
                        {
67
 
                                alert(i18n_at_least_2_option);
68
 
                                return false;
69
 
                        }else return true;
70
 
                }
71
 
        },
72
 
        addOption : function ()
73
 
        {
74
 
                jQuery("#attrOptionContainer").append(ATTRIBUTE_OPTION.createInput());
75
 
        },
76
 
        remove : function (this_, optionId)
77
 
        {
78
 
                if( jQuery(this_).siblings("input").attr("name") != "attrOptions")
79
 
                {
80
 
                        jQuery.getJSON("removeProgramAttributeOption.action",
81
 
                                { 
82
 
                                        id: optionId 
83
 
                                },function( json )
84
 
                                {
85
 
                                        var type  = json.response;
86
 
                                        
87
 
                                        if( type == "success")
88
 
                                        {
89
 
                                                jQuery(this_).parent().parent().remove();
90
 
                                                showSuccessMessage(json.message);
91
 
                                        }else 
92
 
                                        {
93
 
                                                showWarningMessage(json.message);
94
 
                                        }
95
 
                                });
96
 
                }else
97
 
                {
98
 
                        jQuery(this_).parent().parent().remove();
99
 
                }
100
 
        },
101
 
        removeInAddForm : function(this_)
102
 
        {
103
 
                jQuery(this_).parent().parent().remove();
104
 
        },
105
 
        createInput : function ()
106
 
        {
107
 
                return "<tr><td><input type='text' name='attrOptions' style='width:28em'/><a href='#' style='text-decoration: none; margin-left:0.5em;' title='"+i18n_remove_option+"'  onClick='ATTRIBUTE_OPTION.remove(this,null)'>[ - ]</a></td></tr>";
108
 
        }
109
 
}
 
 
b'\\ No newline at end of file'