summaryrefslogtreecommitdiffabout
path: root/content
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 /content
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 (limited to 'content') (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
4 files changed, 75 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
@@ -45,12 +45,18 @@
45 45
46 <commandset id="cmdset_search"> 46 <commandset id="cmdset_search">
47 <command id="cmd_search" label="&panel.search.cmd_search.label;" 47 <command id="cmd_search" label="&panel.search.cmd_search.label;"
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">
54 <command id="cmd_refresh_sets" label="&panel.sets.cmd_refresh_sets;" 60 <command id="cmd_refresh_sets" label="&panel.sets.cmd_refresh_sets;"
55 oncommand="fireflix.on_refresh_sets()" /> 61 oncommand="fireflix.on_refresh_sets()" />
56 <command id="cmd_set_props" label="&panel.sets.cmd_properties;" 62 <command id="cmd_set_props" label="&panel.sets.cmd_properties;"
@@ -127,12 +133,19 @@
127 accesskey="t" /> 133 accesskey="t" />
128 <checkbox id="search_mine" label="&panel.search.mode.mine.label;" checked="true" accesskey="m"/> 134 <checkbox id="search_mine" label="&panel.search.mode.mine.label;" checked="true" accesskey="m"/>
129 <spacer flex="1"/> 135 <spacer flex="1"/>
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)"
136 onkeypress="if(event.keyCode==event.DOM_VK_RETURN) 149 onkeypress="if(event.keyCode==event.DOM_VK_RETURN)
137 fireflix.foundphotos.on_cmd_open(event)"> 150 fireflix.foundphotos.on_cmd_open(event)">
138 <treecols> 151 <treecols>
diff --git a/content/fireflix.css b/content/fireflix.css
index 71080d1..9e7bf6b 100644
--- a/content/fireflix.css
+++ b/content/fireflix.css
@@ -84,6 +84,16 @@ div#searchresult_description {
84 font-family: courier, monospace; 84 font-family: courier, monospace;
85 font-size: 9pt; 85 font-size: 9pt;
86 padding: 2px; 86 padding: 2px;
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
@@ -689,13 +689,14 @@ var fireflix = {
689 fireflix: null, 689 fireflix: null,
690 init: function(f) { 690 init: function(f) {
691 this.fireflix = f; 691 this.fireflix = f;
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 },
699 photos: new Array(), 700 photos: new Array(),
700 rowCount: 0, 701 rowCount: 0,
701 getCellText: function(r,c) { 702 getCellText: function(r,c) {
@@ -726,12 +727,16 @@ var fireflix = {
726 var n; while(n=xp.iterateNext()) { 727 var n; while(n=xp.iterateNext()) {
727 this.photos.push(new Photo(n)); 728 this.photos.push(new Photo(n));
728 } 729 }
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',
735 auth_token: 'default', 740 auth_token: 'default',
736 extras: 'license,date_upload,date_taken,owner_name,icon_server,original_format,last_update,geo' 741 extras: 'license,date_upload,date_taken,owner_name,icon_server,original_format,last_update,geo'
737 }; 742 };
@@ -739,27 +744,62 @@ var fireflix = {
739 pars.user_id='me'; 744 pars.user_id='me';
740 if(this.search_tags.checked) { 745 if(this.search_tags.checked) {
741 pars.tags=this.search_for.value.split(/ +/).join(','); 746 pars.tags=this.search_for.value.split(/ +/).join(',');
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 = '';
763 }else{ 803 }else{
764 this.searchresult_description.innerHTML = content?content:''; 804 this.searchresult_description.innerHTML = content?content:'';
765 /* of all linking elements flickr only allows a */ 805 /* of all linking elements flickr only allows a */
diff --git a/content/util.js b/content/util.js
index c4af09e..ccc61cf 100644
--- a/content/util.js
+++ b/content/util.js
@@ -55,12 +55,19 @@ function xp_str(xp,x) {
55 */ 55 */
56function xp_node(xp,x) { 56function xp_node(xp,x) {
57 var rv = x.evaluate( 57 var rv = x.evaluate(
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
64 */ 71 */
65function pull_elements(th,d,els) { 72function pull_elements(th,d,els) {
66 for(var e in els) { 73 for(var e in els) {