Project

General

Profile

1
dojo.require("dojo.rpc.*");
2
dojo.hostenv.writeIncludes();
3

    
4
var smdUrl="AnnouncementsManager.action";
5

    
6
var currentPage = 0;
7
var service = new dojo.rpc.JsonService( smdUrl );
8

    
9
var announcementIds = [];
10
var numOfIds = 0;
11

    
12
function loadIds() {
13
    var call = function( ids ) {
14
        var destList = document.getElementById( "announcementIdsControl" );
15
        destList.length = 0;
16
        for( var i = 0; i < ids.length; i++ ){
17
            announcementIds[ i ] = ids[ i ];
18
            var newOption = document.createElement("OPTION");
19
            newOption.text = '' + ids[ i ];
20
            newOption.value = '' + ids[ i ];
21
            var len = destList.length;
22
            destList.options[len] = newOption;
23
        }
24
        numOfIds = ids.length;
25
    };
26

    
27
    var defered = service.getIds();
28
    defered.addCallback(call);
29
}
30

    
31
loadIds();
32

    
33
function addNew() {
34

    
35
    //function called when remote method returns
36
    var callback = function( newId ) {
37
        announcementIds[ numOfIds ] = newId;
38
        numOfIds ++;
39
        var destList = document.getElementById( "announcementIdsControl" );
40
        var len = destList.length;
41
        var newOption = document.createElement("OPTION");
42
        newOption.text = '' + newId;
43
        newOption.value = '' + newId;
44
        destList.options[len] = newOption;
45
        alert( "Announcement has been commited" );
46
    };
47

    
48
    var dojoObj = dojo.widget.byId( "newAnnouncement.expirationDate" );
49
    var dateObj = dojoObj.getDate();
50

    
51
    //parameter
52
    var vDate =  dateObj.getTime();
53

    
54
    var title = document.getElementById( "newAnnouncement.title" ).value;
55
    var content = document.getElementById( "newAnnouncement.content" ).value;
56
    //alert( "is it going to pass this" );
57
    //var contentObj = dijit.byId( "newAnnouncement.content" );
58
    //var content = contentObj.getValue( false );
59
    
60
    var isActive;
61
    var showTitle;
62

    
63
    if( document.getElementById( "newAnnouncement.active" ).checked == true ) {
64
        isActive = true;
65
    } else {
66
        isActive = false;
67
    }
68
    if ( document.getElementById( "newAnnouncement.showTitle" ).checked == true ) {
69
        showTitle = true;
70
    } else {
71
        showTitle = false;
72
    }
73
    //alert("content is : " + content );
74
    var announcement = {
75
        "content": content,
76
        "title": title,
77
        "active": isActive,
78
        "showTitle": showTitle
79
    };
80
    //execute remote method
81
    var defered = service.addAnnouncement(announcement, vDate );
82
    //var defered = service.execute();
83
    //attach callback to defered object
84
    defered.addCallback(callback);
85
}
86

    
87
function showSelected(){
88
    var dropdownIndex = document.getElementById('announcementIdsControl').selectedIndex;
89
    var dropdownValue = document.getElementById('announcementIdsControl')[dropdownIndex].value;
90

    
91
    var callback = function( ann ) {
92
        document.getElementById( "announcement.title" ).value = ann.title;
93
        document.getElementById( "announcement.content" ).value = ann.content;
94
        //dijit.byID(self, id) .byId( "announcement.content" ).setValue( ann.content );
95
        document.getElementById( "announcement.active" ).checked = ann.active;
96
        document.getElementById( "announcement.showTitle" ).checked = ann.showTitle;
97
        var dateObj = ann.expirationDate;
98
        var dojoObj = dojo.widget.byId( "announcement.expirationDate" );
99
        dojoObj.setDate( dateObj );
100
    }
101
    var defered = service.getAnnouncement( dropdownValue );
102

    
103
    defered.addCallback(callback);
104
}
105

    
106
function up(){
107
    var aids = document.getElementById('announcementIdsControl');
108
    if( aids.length <2 )
109
        return;
110
    var dropdownIndex = document.getElementById('announcementIdsControl').selectedIndex;
111
    if(  dropdownIndex == 0 ){
112
        return;
113
    }
114
    var dropdownValue = document.getElementById('announcementIdsControl')[dropdownIndex].value;
115

    
116
    var defered = service.up( dropdownValue );
117

    
118
    var moveText1 = aids[dropdownIndex - 1 ].text;
119
    var moveText2 = aids[dropdownIndex].text;
120
    var moveValue1 = aids[dropdownIndex - 1 ].value;
121
    var moveValue2 = aids[dropdownIndex].value;
122

    
123
    aids[ dropdownIndex ].text = moveText1;
124
    aids[ dropdownIndex ].value = moveValue1;
125
    aids[ dropdownIndex - 1 ].text = moveText2;
126
    aids[ dropdownIndex - 1 ].value = moveValue2;
127
    aids.selectedIndex = dropdownIndex - 1; // Select the one that was selected before
128
}
129

    
130
function down(){
131
    var aids = document.getElementById('announcementIdsControl');
132
    if( aids.length <2 )
133
        return;
134
    var dropdownIndex = document.getElementById('announcementIdsControl').selectedIndex;
135
    if(  dropdownIndex == aids.length - 1 ){
136
        return;
137
    }
138
    var dropdownValue = document.getElementById('announcementIdsControl')[dropdownIndex].value;
139

    
140
    var defered = service.down( dropdownValue );
141

    
142
    var moveText1 = aids[dropdownIndex + 1 ].text;
143
    var moveText2 = aids[dropdownIndex].text;
144
    var moveValue1 = aids[dropdownIndex + 1 ].value;
145
    var moveValue2 = aids[dropdownIndex].value;
146

    
147
    aids[ dropdownIndex ].text = moveText1;
148
    aids[ dropdownIndex ].value = moveValue1;
149
    aids[ dropdownIndex + 1 ].text = moveText2;
150
    aids[ dropdownIndex + 1 ].value = moveValue2;
151
    aids.selectedIndex = dropdownIndex + 1; // Select the one that was selected before
152
}
153

    
154
function remove(){
155
    var dropdownIndex = document.getElementById('announcementIdsControl').selectedIndex;
156
    var dropdownValue = document.getElementById('announcementIdsControl')[dropdownIndex].value;
157
    document.getElementById('announcementIdsControl').remove( dropdownIndex );
158
    var defered = service.remove( dropdownValue );
159
    alert( "Announcement has been removed" );
160
}
161

    
162
function update(){
163
    var dropdownIndex = document.getElementById('announcementIdsControl').selectedIndex;
164
    var dropdownValue = document.getElementById('announcementIdsControl')[dropdownIndex].value;
165
    //function called when remote method returns
166
    var callback = function( ret ) {
167
        if( ret == true )
168
            alert( "Announcement has been updated" );
169
        else
170
            alert( "There was an error with the Announcement updat" );
171
    };
172

    
173
    var dojoObj = dojo.widget.byId( "announcement.expirationDate" );
174
    var dateObj = dojoObj.getDate();
175

    
176
    //parameter
177
    var vDate =  dateObj.getTime();
178

    
179
    var title = document.getElementById( "announcement.title" ).value;
180
    var content = document.getElementById( "announcement.content" ).value;
181
    var isActive;
182
    var showTitle;
183

    
184
    if( document.getElementById( "announcement.active" ).checked == true ) {
185
        isActive = true;
186
    } else {
187
        isActive = false;
188
    }
189
    if ( document.getElementById( "announcement.showTitle" ).checked == true ) {
190
        showTitle = true;
191
    } else {
192
        showTitle = false;
193
    }
194
    var announcement = {
195
        "content": content,
196
        "title": title,
197
        "active": isActive,
198
        "showTitle": showTitle
199
    };
200
    //execute remote method
201
    var defered = service.updateAnnouncement( dropdownValue, announcement, vDate );
202
    //var defered = service.execute();
203
    //attach callback to defered object
204
    defered.addCallback(callback);
205
}
(6-6/21)