issue48, make sure no pending comma is shown at the end of the available-tags
[phpfspot.git] / phpfspot.js
1 function showImage(id)
2 {
3    var image_div = document.getElementById("content");
4    image_div.innerHTML = HTML_AJAX.grab(encodeURI('rpc.php?action=showphoto&id=' + id));
5 }
6
7 function showCredits()
8 {
9    var credits = document.getElementById("content");
10    credits.innerHTML = HTML_AJAX.grab(encodeURI('rpc.php?action=showcredits'));
11 }
12
13 function Tags(mode, id)
14 {
15    if(mode == "add") {
16       // add the tag to users session
17       HTML_AJAX.grab(encodeURI('rpc.php?action=addtag&id=' + id));
18    }
19    else if(mode == "del") {
20       // del the tag from users session
21       HTML_AJAX.grab(encodeURI('rpc.php?action=deltag&id=' + id));
22    }
23    else if(mode == "condition") {
24       setCheckedValue(id, id.value);
25       HTML_AJAX.grab(encodeURI('rpc.php?action=tagcondition&mode=' + id.value));
26    }
27
28    refreshAvailableTags();
29    refreshSelectedTags();
30    refreshPhotoIndex();
31
32 }
33
34 function refreshAvailableTags()
35 {
36    // update available tags
37    var avail_tags = document.getElementById('available_tags');
38    avail_tags.innerHTML = "Loading...";
39    avail_tags.innerHTML = HTML_AJAX.grab(encodeURI('rpc.php?action=show_available_tags'));
40 }
41
42 function refreshSelectedTags()
43 {
44    // update selected tags
45    var selected_tags = document.getElementById("selected_tags");
46    selected_tags.innerHTML = "Loading...";
47    selected_tags.innerHTML = HTML_AJAX.grab(encodeURI('rpc.php?action=show_selected_tags'));
48 }
49
50 function showPhotoIndex(begin_with)
51 {
52    if(begin_with == undefined)
53       HTML_AJAX.replace(document.getElementById("content"), encodeURI('rpc.php?action=show_photo_index'));
54    else
55       HTML_AJAX.replace(document.getElementById("content"), encodeURI('rpc.php?action=show_photo_index&begin_with=' + begin_with));
56 }
57
58 // if photo index is currently shown, refresh it
59 function refreshPhotoIndex()
60 {
61    if(document.getElementById("matrix") != undefined || startup == 1) {
62       showPhotoIndex();
63       startup = 0;
64    }
65 }
66
67 function click(object)
68 {
69    if(object.blur)
70       object.blur();
71
72 }
73
74 // set the radio button with the given value as being checked
75 // do nothing if there are no radio buttons
76 // if the given value does not exist, all the radio buttons
77 // are reset to unchecked
78 function setCheckedValue(condition, value) {
79
80    var count = condition.length;
81    if(count == undefined) {
82       condition.checked = (condition.value == value.toString());
83       return;
84    }
85    for(var i = 0; i < count; i++) {
86       condition[i].checked = false;
87       if(condition[i].value == value.toString()) {
88          condition[i].checked = true;
89       }
90    }
91 }
92
93 function startTagSearch(searchfor)
94 {
95    HTML_AJAX.grab(encodeURI('rpc.php?action=tag_search&for=' + searchfor));
96    refreshAvailableTags();
97    refreshSelectedTags();
98    showPhotoIndex();
99 }
100
101 function startDateSearch()
102 {
103    from_year = document.getElementById('fromyear').value;
104    from_month = document.getElementById('frommonth').value;
105    from_day = document.getElementById('fromday').value;
106    from = from_year +"-"+ from_month +"-"+ from_day;
107    to_year = document.getElementById('toyear').value;
108    to_month = document.getElementById('tomonth').value;
109    to_day = document.getElementById('today').value;
110    to = to_year +"-"+ to_month +"-"+ to_day;
111
112    HTML_AJAX.grab(encodeURI('rpc.php?action=date_search&from='+ from +'&to='+ to));
113    
114    clearSearch();
115    refreshAvailableTags();
116    refreshSelectedTags();
117    refreshPhotoIndex();
118    refreshPhotoIndex();
119 }
120
121 function setViewMode(mode)
122 {
123    var exprt = document.getElementById('output');
124    exprt.innerHTML = "Loading...";
125    exprt.innerHTML = HTML_AJAX.grab(encodeURI('rpc.php?action=get_export&mode=' + mode));
126 }
127
128 function clearSearch()
129 {
130    document.getElementsByName('searchfor')[0].value = '';
131 }
132
133 function AskServerWhatToDo()
134 {
135    return HTML_AJAX.grab(encodeURI('rpc.php?action=what_to_do'));
136 }
137
138 function init_phpfspot()
139 {
140    refreshAvailableTags();
141
142    whattodo = AskServerWhatToDo();
143
144    if(whattodo == 'showpi' || whattodo == 'showpi_date') {
145       showPhotoIndex();
146    }
147    if(whattodo == 'showpi_tags') {
148       refreshSelectedTags();
149       showPhotoIndex();
150    }
151    if(whattodo == 'show_photo') {
152       if(photo = getPhotoToShow()) {
153          showImage(photo)
154          refreshSelectedTags();
155       }
156    }
157 }
158
159 function setBackGrdColor(item, color)
160 {
161    if(color == 'mouseover')
162       item.style.backgroundColor='#c6e9ff';
163    if(color == 'mouseout')
164       item.style.backgroundColor='#eeeeee';
165    if(color == 'mouseclick')
166       item.style.backgroundColor='#93A8CA';
167 }
168
169 function getPhotoToShow()
170 {
171    // update selected tags
172    var photo_to_show = HTML_AJAX.grab(encodeURI('rpc.php?action=get_photo_to_show'));
173
174    // if no image needs to be shown, return false from here
175    if(photo_to_show == "")
176       return false;
177    
178    return photo_to_show;
179 }
180
181 function showCalendar(date_box, click_obj)
182 {
183    var calendar = document.getElementById('calendar');
184    if(date_box == 'from') {
185       var xpos = document.getElementById('frompic').offsetLeft;
186       var ypos = document.getElementById('frompic').offsetTop;
187       calendar_mode = 'from';
188    }
189    if(date_box == 'to') {
190       var xpos = document.getElementById('topic').offsetLeft;
191       var ypos = document.getElementById('topic').offsetTop;
192       calendar_mode = 'to';
193    }
194    calendar.style.left = xpos + 60 + 'px';
195    calendar.style.top = ypos + 80 + 'px';
196
197    if(calendar.style.visibility == "" || calendar.style.visibility == 'hidden') {
198       calendar.style.visibility = 'visible';
199       calendar.innerHTML = "Loading...";
200       calendar.innerHTML = HTML_AJAX.grab(encodeURI('rpc.php?action=get_calendar_matrix'));
201       calendar_shown = 1;
202    }
203    else {
204       calendar.style.visibility = 'hidden';
205       calendar_shown = 0;
206    }
207 }
208
209 function setMonth(year, month, day)
210 {
211    var calendar = document.getElementById('calendar');
212    calendar.innerHTML = "Loading...";
213    calendar.innerHTML = HTML_AJAX.grab(encodeURI('rpc.php?action=get_calendar_matrix&year='+ year +'&month='+ month +'&day='+ day));
214 }
215
216 function setCalendarDate(year, month, day)
217 {
218    document.getElementById(calendar_mode+'year').value = year;
219    document.getElementById(calendar_mode+'month').value = month;
220    document.getElementById(calendar_mode+'day').value = day;
221 }
222
223 function resetAll()
224 {
225    HTML_AJAX.grab(encodeURI('rpc.php?action=reset'));
226    clearSearch();
227    refreshAvailableTags();
228    refreshSelectedTags();
229    refreshPhotoIndex();
230 }
231
232 var startup = 1;
233 var calendar_shown = 0;
234 var calendar_mode = '';