issue42, reset-all is now also refreshing the views
[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    // if no tags are currently selected, return false from here
50    if(selected_tags.innerHTML == "")
51       return false;
52
53    return true;
54
55 }
56
57 function showPhotoIndex(begin_with)
58 {
59    if(begin_with == undefined)
60       HTML_AJAX.replace(document.getElementById("content"), encodeURI('rpc.php?action=show_photo_index'));
61    else
62       HTML_AJAX.replace(document.getElementById("content"), encodeURI('rpc.php?action=show_photo_index&begin_with=' + begin_with));
63 }
64
65 // if photo index is currently shown, refresh it
66 function refreshPhotoIndex()
67 {
68    if(document.getElementById("matrix") != undefined || startup == 1) {
69       showPhotoIndex();
70       startup = 0;
71    }
72 }
73
74 function click(object)
75 {
76    if(object.blur)
77       object.blur();
78
79 }
80
81 // set the radio button with the given value as being checked
82 // do nothing if there are no radio buttons
83 // if the given value does not exist, all the radio buttons
84 // are reset to unchecked
85 function setCheckedValue(condition, value) {
86
87    var count = condition.length;
88    if(count == undefined) {
89       condition.checked = (condition.value == value.toString());
90       return;
91    }
92    for(var i = 0; i < count; i++) {
93       condition[i].checked = false;
94       if(condition[i].value == value.toString()) {
95          condition[i].checked = true;
96       }
97    }
98 }
99
100 function startTagSearch(searchfor)
101 {
102    HTML_AJAX.grab(encodeURI('rpc.php?action=tag_search&for=' + searchfor));
103    refreshAvailableTags();
104    refreshSelectedTags();
105    showPhotoIndex();
106 }
107
108 function startDateSearch()
109 {
110    from_year = document.getElementById('fromyear').value;
111    from_month = document.getElementById('frommonth').value;
112    from_day = document.getElementById('fromday').value;
113    from = from_year +"-"+ from_month +"-"+ from_day;
114    to_year = document.getElementById('toyear').value;
115    to_month = document.getElementById('tomonth').value;
116    to_day = document.getElementById('today').value;
117    to = to_year +"-"+ to_month +"-"+ to_day;
118
119    HTML_AJAX.grab(encodeURI('rpc.php?action=date_search&from='+ from +'&to='+ to));
120    
121    clearSearch();
122    refreshAvailableTags();
123    refreshSelectedTags();
124    refreshPhotoIndex();
125    refreshPhotoIndex();
126 }
127
128 function setViewMode(mode)
129 {
130    var exprt = document.getElementById('output');
131    exprt.innerHTML = "Loading...";
132    exprt.innerHTML = HTML_AJAX.grab(encodeURI('rpc.php?action=get_export&mode=' + mode));
133 }
134
135 function clearSearch()
136 {
137    document.getElementsByName('searchfor')[0].value = '';
138 }
139
140 function init_phpfspot()
141 {
142    refreshAvailableTags();
143
144    if(photo = getPhotoToShow()) {
145       showImage(photo)
146       refreshSelectedTags();
147    }
148    else {
149       if(refreshSelectedTags()) {
150          showPhotoIndex();
151       }
152    }
153 }
154
155 function setBackGrdColor(item, color)
156 {
157    if(color == 'mouseover')
158       item.style.backgroundColor='#c6e9ff';
159    if(color == 'mouseout')
160       item.style.backgroundColor='#eeeeee';
161    if(color == 'mouseclick')
162       item.style.backgroundColor='#93A8CA';
163 }
164
165 function getPhotoToShow()
166 {
167    // update selected tags
168    var photo_to_show = HTML_AJAX.grab(encodeURI('rpc.php?action=get_photo_to_show'));
169
170    // if no image needs to be shown, return false from here
171    if(photo_to_show == "")
172       return false;
173    
174    return photo_to_show;
175 }
176
177 function showCalendar(date_box, click_obj)
178 {
179    var calendar = document.getElementById('calendar');
180    if(date_box == 'from') {
181       var xpos = document.getElementById('frompic').offsetLeft;
182       var ypos = document.getElementById('frompic').offsetTop;
183       calendar_mode = 'from';
184    }
185    if(date_box == 'to') {
186       var xpos = document.getElementById('topic').offsetLeft;
187       var ypos = document.getElementById('topic').offsetTop;
188       calendar_mode = 'to';
189    }
190    calendar.style.left = xpos + 60 + 'px';
191    calendar.style.top = ypos + 80 + 'px';
192
193    if(calendar.style.visibility == "" || calendar.style.visibility == 'hidden') {
194       calendar.style.visibility = 'visible';
195       calendar.innerHTML = "Loading...";
196       calendar.innerHTML = HTML_AJAX.grab(encodeURI('rpc.php?action=get_calendar_matrix'));
197       calendar_shown = 1;
198    }
199    else {
200       calendar.style.visibility = 'hidden';
201       calendar_shown = 0;
202    }
203 }
204
205 function setMonth(year, month, day)
206 {
207    var calendar = document.getElementById('calendar');
208    calendar.innerHTML = "Loading...";
209    calendar.innerHTML = HTML_AJAX.grab(encodeURI('rpc.php?action=get_calendar_matrix&year='+ year +'&month='+ month +'&day='+ day));
210 }
211
212 function setCalendarDate(year, month, day)
213 {
214    document.getElementById(calendar_mode+'year').value = year;
215    document.getElementById(calendar_mode+'month').value = month;
216    document.getElementById(calendar_mode+'day').value = day;
217 }
218
219 function resetAll()
220 {
221    HTML_AJAX.grab(encodeURI('rpc.php?action=reset'));
222    clearSearch();
223    refreshAvailableTags();
224    refreshSelectedTags();
225    refreshPhotoIndex();
226 }
227
228 var startup = 1;
229 var calendar_shown = 0;
230 var calendar_mode = '';