-rw-r--r-- | content/fireflix-panel.xul | 13 | ||||
-rw-r--r-- | content/fireflix.css | 10 | ||||
-rw-r--r-- | content/fireflix.js | 50 | ||||
-rw-r--r-- | content/util.js | 7 | ||||
-rw-r--r-- | locale/en-US/fireflix.dtd | 2 | ||||
-rw-r--r-- | locale/en-US/fireflix.properties | 2 |
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 @@ -49,4 +49,10 @@ <command id="cmd_search_open" label="&panel.search.cmd_search_open.label;" oncommand="fireflix.foundphotos.on_cmd_open(event)" /> + <command id="cmd_search_prev_page" + label="&panel.search.cmd_search_prev_page.label;" + oncommand="fireflix.foundphotos.on_cmd_prev(event)" disabled="true"/> + <command id="cmd_search_next_page" + label="&panel.search.cmd_search_next_page.label;" + oncommand="fireflix.foundphotos.on_cmd_next(event)" disabled="true"/> </commandset> @@ -131,4 +137,11 @@ </hbox> </groupbox> + <hbox> + <button command="cmd_search_prev_page"/> + <spacer flex="1"/> + <label id="search_page" hidden="true"/> + <spacer flex="1"/> + <button command="cmd_search_next_page"/> + </hbox> <tree id="searchresults" rows="2" flex="1" onselect="fireflix.foundphotos.on_select()" diff --git a/content/fireflix.css b/content/fireflix.css index 71080d1..9e7bf6b 100644 --- a/content/fireflix.css +++ b/content/fireflix.css @@ -88,2 +88,12 @@ div#searchresult_description { background: white; } + +label#search_page { + font-weight: bold; + background: white; color: #404040; + border-color: #c0c0c0 #404040 #404040 #c0c0c0; + border-style: solid; + border-width: 1px; + -moz-border-radius: 1em; + padding: 0.5ex 1ex; +} diff --git a/content/fireflix.js b/content/fireflix.js index e144aae..92c42f4 100644 --- a/content/fireflix.js +++ b/content/fireflix.js @@ -693,5 +693,6 @@ var fireflix = { 'search_for','search_tags','search_mine', 'searchresult_props','search_photo', - 'searchresult_title','searchresult_description' + 'searchresult_title','searchresult_description', + 'search_page','cmd_search_prev_page','cmd_search_next_page' ]); document.getElementById('searchresults').view = this; @@ -730,4 +731,8 @@ var fireflix = { this.tree.endUpdateBatch(); }, + paging: { + pars: null, + page: null, pages: null, perpage: null, total: null + }, search_photos: function() { var pars = { @@ -743,13 +748,24 @@ var fireflix = { pars.text=this.search_for.value; } + this.paging.pars = new Object(); + this.paging.page = null; this.paging.pages = null; + this.paging.perpage = null; this.paging.total = null; + for(var p in pars) this.paging.pars[p] = pars[p]; + this.perform_search(pars); + }, + perform_search: function(p) { var _this = this; - this.fireflix.flickr.api_call( pars, + this.fireflix.flickr.api_call( p, function(xr) { var x = xr.responseXML; - var xp = x.evaluate( - '/rsp/photos/photo', x, null, - XPathResult.ORDERED_NODE_ITERATOR_TYPE, null ); + var xp = xp_nodes('/rsp/photos/photo',x); _this.importXPR(xp); _this.tree.ensureRowIsVisible(0); + xp = xp_node('/rsp/photos',x); + _this.paging.page = parseInt(xp.getAttribute('page')); + _this.paging.pages = parseInt(xp.getAttribute('pages')); + _this.paging.perpage = parseInt(xp.getAttribute('perpage')); + _this.paging.total = parseInt(xp.getAttribute('total')); + _this.update_paging(); _this.on_select(); }, function(x,s,c,m) { @@ -758,4 +774,28 @@ var fireflix = { ); }, + on_cmd_prev: function(ev) { + var pars = new Object(); + for(var p in this.paging.pars) pars[p] = this.paging.pars[p]; + pars.page=this.paging.page-1; pars.per_page=this.paging.perpage; + this.perform_search(pars); + }, + on_cmd_next: function(ev) { + var pars = new Object(); + for(var p in this.paging.pars) pars[p] = this.paging.pars[p]; + pars.page=this.paging.page+1; pars.per_page=this.paging.perpage; + this.perform_search(pars); + }, + update_paging: function() { + if(! (this.paging.pars && this.paging.page && this.paging.pages) ) { + this.search_page.value=''; this.search_page.hidden = true; + this.cmd_search_prev_page.setAttribute('disabled','true'); + this.cmd_search_next_page.setAttribute('disabled','true'); + }else{ + this.search_page.value=this.fireflix.loc_strings.getFormattedString('search_page',[this.paging.page,this.paging.pages]); + this.search_page.hidden=false; + this.cmd_search_prev_page.setAttribute('disabled',(this.paging.page>1)?'false':'true'); + this.cmd_search_next_page.setAttribute('disabled',(this.paging.page<this.paging.pages)?'false':'true'); + } + }, render_description_frame: function(content) { if(!content) { diff --git a/content/util.js b/content/util.js index c4af09e..ccc61cf 100644 --- a/content/util.js +++ b/content/util.js @@ -59,4 +59,11 @@ function xp_node(xp,x) { return rv.singleNodeValue; } +/* + * extract xpath-specified ordered set of nodes + */ +function xp_nodes(xp,x) { + return x.evaluate( + xp, x, null, XPathResult.ORDERED_NODE_ITERATOR_TYPE, null); +} /* 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 @@ -36,4 +36,6 @@ <!ENTITY panel.search.col.title.label "Title"> <!ENTITY panel.search.cmd_search_open.label "Open"> +<!ENTITY panel.search.cmd_search_prev_page.label "«"> +<!ENTITY panel.search.cmd_search_next_page.label "»"> <!ENTITY panel.sets.name.label "Set"> 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 @@ -10,2 +10,4 @@ urltype_b=Large (fits in 1024x1024) urltype_o=Original image urltype_p=Flickr photo URL + +search_page=Page %S of %S |