issue54, sort order can now be modified
[phpfspot.git] / phpfspot.js
index f101e6080900209319d927a4e96ceca2f5a5ba0e..dff8da9e68c4aa536061b272c9df3f3bfdf4cef6 100644 (file)
@@ -45,13 +45,6 @@ function refreshSelectedTags()
    var selected_tags = document.getElementById("selected_tags");
    selected_tags.innerHTML = "Loading...";
    selected_tags.innerHTML = HTML_AJAX.grab(encodeURI('rpc.php?action=show_selected_tags'));
-
-   // if no tags are currently selected, return false from here
-   if(selected_tags.innerHTML == "")
-      return false;
-
-   return true;
-
 }
 
 function showPhotoIndex(begin_with)
@@ -97,16 +90,10 @@ function setCheckedValue(condition, value) {
    }
 }
 
-function startTagSearch(searchfor)
+function startSearch()
 {
-   HTML_AJAX.grab(encodeURI('rpc.php?action=tag_search&for=' + searchfor));
-   refreshAvailableTags();
-   refreshSelectedTags();
-   showPhotoIndex();
-}
+   var searchfor = document.getElementsByName('searchfor')[0].value
 
-function startDateSearch()
-{
    from_year = document.getElementById('fromyear').value;
    from_month = document.getElementById('frommonth').value;
    from_day = document.getElementById('fromday').value;
@@ -116,13 +103,42 @@ function startDateSearch()
    to_day = document.getElementById('today').value;
    to = to_year +"-"+ to_month +"-"+ to_day;
 
-   HTML_AJAX.grab(encodeURI('rpc.php?action=date_search&from='+ from +'&to='+ to));
+   var request = 'rpc.php?action=search';
+
+   if(searchfor != "") {
+      request = request + '&for=' + searchfor;
+   }
    
-   clearSearch();
+   if(document.getElementsByName('consider_date')[0].checked == true) {
+      request = request + '&from='+ from +'&to='+ to;
+   }
+
+   var sort_order = document.getElementsByName('sort_order')[0];
+   request = request + '&sort_order='+ sort_order.options[sort_order.selectedIndex].value;
+
+   HTML_AJAX.grab(encodeURI(request));
+
    refreshAvailableTags();
    refreshSelectedTags();
-   refreshPhotoIndex();
-   refreshPhotoIndex();
+   showPhotoIndex();
+   
+}
+
+function datesearch()
+{
+   var mode = true;
+
+   if(document.getElementsByName('consider_date')[0].checked == true) {
+      mode = false;
+   }
+      
+   document.getElementById('fromyear').disabled = mode;
+   document.getElementById('frommonth').disabled = mode;
+   document.getElementById('fromday').disabled = mode;
+   document.getElementById('toyear').disabled = mode;
+   document.getElementById('tomonth').disabled = mode;
+   document.getElementById('today').disabled = mode;
 }
 
 function setViewMode(mode)
@@ -137,17 +153,28 @@ function clearSearch()
    document.getElementsByName('searchfor')[0].value = '';
 }
 
+function AskServerWhatToDo()
+{
+   return HTML_AJAX.grab(encodeURI('rpc.php?action=what_to_do'));
+}
+
 function init_phpfspot()
 {
    refreshAvailableTags();
 
-   if(photo = getPhotoToShow()) {
-      showImage(photo)
+   whattodo = AskServerWhatToDo();
+
+   if(whattodo == 'showpi' || whattodo == 'showpi_date') {
+      showPhotoIndex();
+   }
+   if(whattodo == 'showpi_tags') {
       refreshSelectedTags();
+      showPhotoIndex();
    }
-   else {
-      if(refreshSelectedTags()) {
-         showPhotoIndex();
+   if(whattodo == 'show_photo') {
+      if(photo = getPhotoToShow()) {
+         showImage(photo)
+         refreshSelectedTags();
       }
    }
 }
@@ -220,8 +247,60 @@ function resetAll()
 {
    HTML_AJAX.grab(encodeURI('rpc.php?action=reset'));
    clearSearch();
+   refreshAvailableTags();
+   refreshSelectedTags();
+   refreshPhotoIndex();
+}
+
+function WSR_getElementsByClassName(oElm, strTagName, oClassNames){
+   var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
+   var arrReturnElements = new Array();
+   var arrRegExpClassNames = new Array();
+   if(typeof oClassNames == "object"){
+      for(var i=0; i<oClassNames.length; i++){
+         arrRegExpClassNames.push(new RegExp("(^|\s)" + oClassNames[i].replace(/-/g, "\-") + "(\s|$)"));
+      }
+   }
+   else{
+      arrRegExpClassNames.push(new RegExp("(^|\s)" + oClassNames.replace(/-/g, "\-") + "(\s|$)"));
+   }
+   var oElement;
+   var bMatchesAll;
+   for(var j=0; j<arrElements.length; j++){
+      oElement = arrElements[j];
+      bMatchesAll = true;
+      for(var k=0; k<arrRegExpClassNames.length; k++){
+         if(!arrRegExpClassNames[k].test(oElement.className)){
+            bMatchesAll = false;
+            break;
+         }
+      }
+      if(bMatchesAll){
+         arrReturnElements.push(oElement);
+      }
+   }
+   return (arrReturnElements)
+}
+
+
+function preloadPhotos(lbImg) {
+
+   var d=document;
+   if(d.images)
+      if(!d.photos)
+         d.photos=new Array();
+
+   var i, j=d.photos.length;
+
+   lbImg=WSR_getElementsByClassName(document,"img","thumb");
+   for(i=0;i<lbImg.length;i++){
+      d.photos[j]=new Image;
+      d.photos[j].src=lbImg[i].src;
+      j++;
+   }
 }
 
 var startup = 1;
 var calendar_shown = 0;
 var calendar_mode = '';
+