summaryrefslogtreecommitdiffabout
authorMichael Krelin <hacker@klever.net>2006-10-01 23:53:31 (UTC)
committer Michael Krelin <hacker@klever.net>2006-10-01 23:53:31 (UTC)
commitb6a122d536aef024b69d40cdf2ac0332d7c14607 (patch) (unidiff)
tree5b6f01eb73f858e6caaf22301e23d7b6b996ffea
parent455df70118b045c6053b33ae2f0318a70e4f96b8 (diff)
downloadfireflix-b6a122d536aef024b69d40cdf2ac0332d7c14607.zip
fireflix-b6a122d536aef024b69d40cdf2ac0332d7c14607.tar.gz
fireflix-b6a122d536aef024b69d40cdf2ac0332d7c14607.tar.bz2
paginating through search results
git-svn-id: http://svn.klever.net/kin/fireflix/trunk@179 fe716a7a-6dde-0310-88d9-d003556173a8
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--content/fireflix-panel.xul13
-rw-r--r--content/fireflix.css10
-rw-r--r--content/fireflix.js50
-rw-r--r--content/util.js7
-rw-r--r--locale/en-US/fireflix.dtd2
-rw-r--r--locale/en-US/fireflix.properties2
6 files changed, 79 insertions, 5 deletions
diff --git a/content/fireflix-panel.xul b/content/fireflix-panel.xul
index 398dd78..bf6df73 100644
--- a/content/fireflix-panel.xul
+++ b/content/fireflix-panel.xul
@@ -48,6 +48,12 @@
48 oncommand="fireflix.foundphotos.search_photos()"/> 48 oncommand="fireflix.foundphotos.search_photos()"/>
49 <command id="cmd_search_open" label="&panel.search.cmd_search_open.label;" 49 <command id="cmd_search_open" label="&panel.search.cmd_search_open.label;"
50 oncommand="fireflix.foundphotos.on_cmd_open(event)" /> 50 oncommand="fireflix.foundphotos.on_cmd_open(event)" />
51 <command id="cmd_search_prev_page"
52 label="&panel.search.cmd_search_prev_page.label;"
53 oncommand="fireflix.foundphotos.on_cmd_prev(event)" disabled="true"/>
54 <command id="cmd_search_next_page"
55 label="&panel.search.cmd_search_next_page.label;"
56 oncommand="fireflix.foundphotos.on_cmd_next(event)" disabled="true"/>
51 </commandset> 57 </commandset>
52 58
53 <commandset id="cmdset_sets"> 59 <commandset id="cmdset_sets">
@@ -130,6 +136,13 @@
130 <button command="cmd_search"/> 136 <button command="cmd_search"/>
131 </hbox> 137 </hbox>
132 </groupbox> 138 </groupbox>
139 <hbox>
140 <button command="cmd_search_prev_page"/>
141 <spacer flex="1"/>
142 <label id="search_page" hidden="true"/>
143 <spacer flex="1"/>
144 <button command="cmd_search_next_page"/>
145 </hbox>
133 <tree id="searchresults" rows="2" flex="1" 146 <tree id="searchresults" rows="2" flex="1"
134 onselect="fireflix.foundphotos.on_select()" 147 onselect="fireflix.foundphotos.on_select()"
135 ondblclick="fireflix.foundphotos.on_cmd_open(event)" 148 ondblclick="fireflix.foundphotos.on_cmd_open(event)"
diff --git a/content/fireflix.css b/content/fireflix.css
index 71080d1..9e7bf6b 100644
--- a/content/fireflix.css
+++ b/content/fireflix.css
@@ -87,3 +87,13 @@ div#searchresult_description {
87 border: dotted 1px gray; 87 border: dotted 1px gray;
88 background: white; 88 background: white;
89} 89}
90
91label#search_page {
92 font-weight: bold;
93 background: white; color: #404040;
94 border-color: #c0c0c0 #404040 #404040 #c0c0c0;
95 border-style: solid;
96 border-width: 1px;
97 -moz-border-radius: 1em;
98 padding: 0.5ex 1ex;
99}
diff --git a/content/fireflix.js b/content/fireflix.js
index e144aae..92c42f4 100644
--- a/content/fireflix.js
+++ b/content/fireflix.js
@@ -692,7 +692,8 @@ var fireflix = {
692 pull_elements(this,document,[ 692 pull_elements(this,document,[
693 'search_for','search_tags','search_mine', 693 'search_for','search_tags','search_mine',
694 'searchresult_props','search_photo', 694 'searchresult_props','search_photo',
695 'searchresult_title','searchresult_description' 695 'searchresult_title','searchresult_description',
696 'search_page','cmd_search_prev_page','cmd_search_next_page'
696 ]); 697 ]);
697 document.getElementById('searchresults').view = this; 698 document.getElementById('searchresults').view = this;
698 }, 699 },
@@ -729,6 +730,10 @@ var fireflix = {
729 this.rowCount = this.photos.length; 730 this.rowCount = this.photos.length;
730 this.tree.endUpdateBatch(); 731 this.tree.endUpdateBatch();
731 }, 732 },
733 paging: {
734 pars: null,
735 page: null, pages: null, perpage: null, total: null
736 },
732 search_photos: function() { 737 search_photos: function() {
733 var pars = { 738 var pars = {
734 method: 'flickr.photos.search', 739 method: 'flickr.photos.search',
@@ -742,21 +747,56 @@ var fireflix = {
742 }else{ 747 }else{
743 pars.text=this.search_for.value; 748 pars.text=this.search_for.value;
744 } 749 }
750 this.paging.pars = new Object();
751 this.paging.page = null; this.paging.pages = null;
752 this.paging.perpage = null; this.paging.total = null;
753 for(var p in pars) this.paging.pars[p] = pars[p];
754 this.perform_search(pars);
755 },
756 perform_search: function(p) {
745 var _this = this; 757 var _this = this;
746 this.fireflix.flickr.api_call( pars, 758 this.fireflix.flickr.api_call( p,
747 function(xr) { 759 function(xr) {
748 var x = xr.responseXML; 760 var x = xr.responseXML;
749 var xp = x.evaluate( 761 var xp = xp_nodes('/rsp/photos/photo',x);
750 '/rsp/photos/photo', x, null,
751 XPathResult.ORDERED_NODE_ITERATOR_TYPE, null );
752 _this.importXPR(xp); 762 _this.importXPR(xp);
753 _this.tree.ensureRowIsVisible(0); 763 _this.tree.ensureRowIsVisible(0);
764 xp = xp_node('/rsp/photos',x);
765 _this.paging.page = parseInt(xp.getAttribute('page'));
766 _this.paging.pages = parseInt(xp.getAttribute('pages'));
767 _this.paging.perpage = parseInt(xp.getAttribute('perpage'));
768 _this.paging.total = parseInt(xp.getAttribute('total'));
769 _this.update_paging();
754 _this.on_select(); 770 _this.on_select();
755 }, function(x,s,c,m) { 771 }, function(x,s,c,m) {
756 _this.fireflix.flickr_failure(x,s,c,m); 772 _this.fireflix.flickr_failure(x,s,c,m);
757 } 773 }
758 ); 774 );
759 }, 775 },
776 on_cmd_prev: function(ev) {
777 var pars = new Object();
778 for(var p in this.paging.pars) pars[p] = this.paging.pars[p];
779 pars.page=this.paging.page-1; pars.per_page=this.paging.perpage;
780 this.perform_search(pars);
781 },
782 on_cmd_next: function(ev) {
783 var pars = new Object();
784 for(var p in this.paging.pars) pars[p] = this.paging.pars[p];
785 pars.page=this.paging.page+1; pars.per_page=this.paging.perpage;
786 this.perform_search(pars);
787 },
788 update_paging: function() {
789 if(! (this.paging.pars && this.paging.page && this.paging.pages) ) {
790 this.search_page.value=''; this.search_page.hidden = true;
791 this.cmd_search_prev_page.setAttribute('disabled','true');
792 this.cmd_search_next_page.setAttribute('disabled','true');
793 }else{
794 this.search_page.value=this.fireflix.loc_strings.getFormattedString('search_page',[this.paging.page,this.paging.pages]);
795 this.search_page.hidden=false;
796 this.cmd_search_prev_page.setAttribute('disabled',(this.paging.page>1)?'false':'true');
797 this.cmd_search_next_page.setAttribute('disabled',(this.paging.page<this.paging.pages)?'false':'true');
798 }
799 },
760 render_description_frame: function(content) { 800 render_description_frame: function(content) {
761 if(!content) { 801 if(!content) {
762 this.searchresult_description.innerHTML = ''; 802 this.searchresult_description.innerHTML = '';
diff --git a/content/util.js b/content/util.js
index c4af09e..ccc61cf 100644
--- a/content/util.js
+++ b/content/util.js
@@ -58,6 +58,13 @@ function xp_node(xp,x) {
58 xp, x, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null ); 58 xp, x, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null );
59 return rv.singleNodeValue; 59 return rv.singleNodeValue;
60} 60}
61/*
62 * extract xpath-specified ordered set of nodes
63 */
64function xp_nodes(xp,x) {
65 return x.evaluate(
66 xp, x, null, XPathResult.ORDERED_NODE_ITERATOR_TYPE, null);
67}
61 68
62/* 69/*
63 * pull in elements into documents as a member variables 70 * pull in elements into documents as a member variables
diff --git a/locale/en-US/fireflix.dtd b/locale/en-US/fireflix.dtd
index f4ceb79..88ec6fb 100644
--- a/locale/en-US/fireflix.dtd
+++ b/locale/en-US/fireflix.dtd
@@ -35,6 +35,8 @@
35<!ENTITY panel.search.mode.mine.label "mine"> 35<!ENTITY panel.search.mode.mine.label "mine">
36<!ENTITY panel.search.col.title.label "Title"> 36<!ENTITY panel.search.col.title.label "Title">
37<!ENTITY panel.search.cmd_search_open.label "Open"> 37<!ENTITY panel.search.cmd_search_open.label "Open">
38<!ENTITY panel.search.cmd_search_prev_page.label "«">
39<!ENTITY panel.search.cmd_search_next_page.label "»">
38 40
39<!ENTITY panel.sets.name.label "Set"> 41<!ENTITY panel.sets.name.label "Set">
40<!ENTITY panel.sets.name.tip "Photoset name"> 42<!ENTITY panel.sets.name.tip "Photoset name">
diff --git a/locale/en-US/fireflix.properties b/locale/en-US/fireflix.properties
index 7caa12f..18300ff 100644
--- a/locale/en-US/fireflix.properties
+++ b/locale/en-US/fireflix.properties
@@ -9,3 +9,5 @@ urltype__=Medium (fits in 500x500)
9urltype_b=Large (fits in 1024x1024) 9urltype_b=Large (fits in 1024x1024)
10urltype_o=Original image 10urltype_o=Original image
11urltype_p=Flickr photo URL 11urltype_p=Flickr photo URL
12
13search_page=Page %S of %S